x13th Posted December 10, 2012 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
Ryokem Posted December 10, 2012 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
AnnieRuru Posted December 10, 2012 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
Question
x13th
Hello :3 Just have one question. How to select a random player in a map? without query?
Edited by x13th3 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.