The online racing simulator
#1 - xxx
[Solved] Problem with random.
Hello,

I have code there with some problem,

CatchEvent OnLapperStart()
GlobalVar $player; $player = 0;
EndCatchEvent

CatchEvent OnConnect( $userName )
CountPlayer();
EndCatchEvent

Sub CountPlayer()
$ListP = getListOfPlayers();
WHILE($ListP[$player] != "" )
$player1 = $ListP[$player];
$player=$player+1;
$rr = round(ToNum(RandomNum(1,2)),0)."";
SetPlayerVar($ListP[ToNum($rr)],"CurrentJob", 4);
privmsg("^1".$player);
ENDWHILE
EndSub

Arrange players with numbers and choose any number randomly on (CurrentJob) .
and how can I Set RandomNum with online players ?

Example: if there 8 players random will be between (1,8)
if there 15 random will be between (1,15)

thanks
I'm not familiar with Lapper, but wouldn't this be enough:
$ListP = getListOfPlayers();
$playerCount = count($ListP);
WHILE($ListP[$player] != "" )
$player1 = $ListP[$player];
$player=$player+1;
$rr = round(ToNum(RandomNum(1,$playerCount)),0)."";
SetPlayerVar($ListP[ToNum($rr)],"CurrentJob", 4);
privmsg("^1".$player);
ENDWHILE

If this doesn't work, then I'd assume you would need second loop.
** Best answer **
well, as i can see you count the players aswell in the WHILE loop.

$ListP = getListOfPlayers();
$randomnumber = round(ToNum(RandomNum(1,$player)),0)
$Player = $ListP[ToNum($randomnumber)];

To make it easier, Lapper does have a Lappervar to count the players.

$Var = GetLapperVar("LapperVar");
numconns //Number of players are connected to the server (include Host)
numplayers //Number of players are connected to the server

#4 - xxx
Thanks all for reply.
This thread is closed

FGED GREDG RDFGDR GSFDG