Jump to content
  • 0

Q>Select random player in map


x13th

Question


  • Group:  Members
  • Topic Count:  55
  • Topics Per Day:  0.01
  • Content Count:  206
  • Reputation:   13
  • Joined:  11/20/11
  • Last Seen:  

Hello :3 Just have one question. How to select a random player in a map? without query? /hmm

Edited by x13th
Link to comment
Share on other sites

3 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

I was trying to do this years ago.

However it's not optimized and query_sql will really simplify and speed up everything, that's a sample of what I planned years ago (also, when my scripting abilities were not great.)

First, I was saving all the players IDs into an array each time they log in, and deleting them each time they log out.

OnPCLoginEvent:
set .PeopleOnline[getarraysize(.PeopleOnline)], getcharid(0);
//...

OnPCLogoutEvent:
set .@tmp$, strcharinfo(0);
for( .@i = 0; .@i < getarraysize(.PeopleOnline$); .@i++ )
   if( .@tmp$ == PeopleOnline$[.@i] ) {
    deletearray PeopleOnline$[.@i], 1;
    break; //Useless to keep the for loop
   }

Second, I looped all the online players to check whoever was in that map.

then, I save players into a temporary array

//Save my AID
set .@myAid, getcharid(3);

for( for( .@i = 0; .@i < getarraysize(.PeopleOnline$); .@i++ ) {
   attachrid(getcharid(3,.PeopleOnline$[.@i])); //Actually it shouldn't be necessary an online check for obvious reason.
   if( strcharinfo(3) == "Your_map" )
    set .@array$[getarraysize(.@array)], .PeopleOnline$[.@i];
}

//Attaching back my RID
attachrid(.@myAid); //There, maybe a check should be added.

So, you now have .@array$ array that has stored the names of who is in "Your_map" map.

So you can choose one randomly...

set .@randomPlayer$, .@array$[rand(getarraysize(.@array$))];
dispbottom "You randomly selected " + .@randomPlayer$;

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

are you doing this for event ?

( I can't think of other situation that need to do something like this )

if it is, then save them into an array when they register

then its very easy to retrieve them later on

example like this script

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  55
  • Topics Per Day:  0.01
  • Content Count:  206
  • Reputation:   13
  • Joined:  11/20/11
  • Last Seen:  

Thank you guys :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...