|
RobMacAF Apprentice
Joined: 09 Jun 2002 Posts: 186 Location: USA
|
Posted: Fri Jul 11, 2003 10:00 am
Random |
I am making a game for my mud and I want it to pick the players in a random order. The number of players can be from 1-10 and is stored in a variable DPlayers.
Lets say we have 5 people playing. I want their names picked randomly and stored into variables named player1 player2 player3 player4 player5
None of the names should repeat |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Fri Jul 11, 2003 12:09 pm |
Create a temporary variable which is a copy of the list of players you have. Then randomly select the players from the temporary variable and delete them as you select each one. Example:
#VAR temp @DPlayers
#LOOP 1,5 {#VAR pnum %random(1, %numitems(@temp));#VAR player%i {%item(@temp, @pnum)};#DELNITEM temp @pnum}
You can also create a new stringlist that will contain the randomly picked players in order. This would be easier than the multiple variables method. Example:
#VAR temp @DPlayers
#LOOP 1,5 {#VAR pnum %random(1, %numitems(@temp));#ADDITEM players {%item(@temp, @pnum)};#DELNITEM temp @pnum} |
|
|
|
RobMacAF Apprentice
Joined: 09 Jun 2002 Posts: 186 Location: USA
|
Posted: Fri Jul 11, 2003 4:08 pm |
I tried the list way and it doesn't do anything that I see. I look in the player variable and there is only the number 10 there
|
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Fri Jul 11, 2003 10:33 pm |
Works fine for me. Just pasted it into my zMUD and it selected five random players correctly. *shrug*
|
|
|
|
|
|