x13th Posted December 10, 2012 Group: Members Topic Count: 55 Topics Per Day: 0.01 Content Count: 206 Reputation: 14 Joined: 11/20/11 Last Seen: April 9, 2024 Share Posted December 10, 2012 (edited) Hello :3 Just have one question. How to select a random player in a map? without query? Edited December 10, 2012 by x13th Quote Link to comment Share on other sites More sharing options...
Ryokem Posted December 10, 2012 Group: Members Topic Count: 0 Topics Per Day: 0 Content Count: 205 Reputation: 19 Joined: 10/12/12 Last Seen: November 7, 2013 Share Posted December 10, 2012 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$; 1 Quote Link to comment Share on other sites More sharing options...
AnnieRuru Posted December 10, 2012 Group: Members Topic Count: 18 Topics Per Day: 0.00 Content Count: 2044 Reputation: 682 Joined: 10/09/12 Last Seen: December 20, 2020 Share Posted December 10, 2012 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 1 Quote Link to comment Share on other sites More sharing options...
x13th Posted December 10, 2012 Group: Members Topic Count: 55 Topics Per Day: 0.01 Content Count: 206 Reputation: 14 Joined: 11/20/11 Last Seen: April 9, 2024 Author Share Posted December 10, 2012 Thank you guys Quote Link to comment Share on other sites More sharing options...
Question
x13th
Hello :3 Just have one question. How to select a random player in a map? without query?
Edited by x13thLink to comment
Share on other sites
3 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.