Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
RobMacAF
Apprentice


Joined: 09 Jun 2002
Posts: 186
Location: USA

PostPosted: 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
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: 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}
Reply with quote
RobMacAF
Apprentice


Joined: 09 Jun 2002
Posts: 186
Location: USA

PostPosted: 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
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: 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*
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net