Blockland Forums > Modification Help
Gartaniums Questions -> checking to see who has the highest value
Gartanium:
2. Solved :D
Lets say I have 10 players in a server and 7 have the value of 1, 2 have the value of 10, and 1 has the value of 100. How would I check to see who has the highest value with out making a huge overcomplicated script?
1. Answered
How would I unassign a variable after giving it a client for
--- Code: ---function GetRandomPlayer()
{
%Randomnumber = GetRandom(0, clientgroup.getcount() - 1);
$Randomperson = Clientgroup.Getobject(%Randomnumber);
}
--- End code ---
I tried doing
--- Code: ---$RandomPerson = 0;
--- End code ---
but my player started acting funny and the game crashed.
Nvm, it crashed because I didn't package something right :|
MegaScientifical:
--- Code: ---function getRandomClient() {
return ClientGroup.getObject(getRandom(ClientGroup.getCount()));
}
--- End code ---
I posted that somewhere else. Then you just do:
--- Code: ---%client = getRandomClient();
--- End code ---
Wherever you need it and it'll work. I can see you're trying to save it to a variable because you don't understand returns yet. But if you want to delete a variable, you'd do this:
--- Code: ---deleteVariables("$VARIABLENAME");
--- End code ---
Gartanium:
Thanks a lot. I don't know much about returns like you said lol.
Gartanium:
-bump-
phflack:
couldn't you do something with the client count, then loop through getting the value, if it's higher than a variable, it sets the variable to the value, then continues with the next client?
edit:
--- Code: ---function getHighestClient()
{
for(%i = ClientGroup.getCount(); %i > 0; %i--)
{
if(/*value out of %i you wish to get the highest of*/ > %a)
%a = /*value out of %i you wish to get the highest of*/;
}
}
--- End code ---
not sure if it would work or not, but hey, you can look over it and tell me where i'm wrong :D