Author Topic: Gartaniums Questions -> checking to see who has the highest value  (Read 1044 times)

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: [Select]
function GetRandomPlayer()
{
  
    %Randomnumber = GetRandom(0, clientgroup.getcount() - 1);
      $Randomperson = Clientgroup.Getobject(%Randomnumber);
  
  
}

I tried doing

Code: [Select]
$RandomPerson = 0;

but my player started acting funny and the game crashed.
Nvm, it crashed because I didn't package something right :|
« Last Edit: November 22, 2010, 01:03:57 PM by Gartanium »

Code: [Select]
function getRandomClient() {
return ClientGroup.getObject(getRandom(ClientGroup.getCount()));
}

I posted that somewhere else. Then you just do:

Code: [Select]
%client = getRandomClient();
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: [Select]
deleteVariables("$VARIABLENAME");

Thanks a lot. I don't know much about returns like you said lol.


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: [Select]
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*/;
}
}
not sure if it would work or not, but hey, you can look over it and tell me where i'm wrong :D
« Last Edit: November 22, 2010, 12:54:18 AM by phflack »

hmm I'll try that, ty phflack.

Edit: Allright this is what I came up with. I don't have time to test it but yeah.
Code: [Select]
function highestvote()
{
   for(%i = 0; %i < clientgroup.getCount(); %i++)
   {
      %newclient = clientgroup.getobject(%i);
      if(%newclient.votecount > %oldclient.votecount)
      {
         %oldclient = %newclient;
         %newclient.votecount = 0;
      }
   }
   for(%i = 0; %i < clientgroup.getCount(); %i++)
   {
      %newclient = clientgroup.getobject(%i);
      if(%newclient.votecount == %oldclient.votecount)
      {
         %j++
         if(%j == 2)
         {

         return 0;

         }
      }
   }
   return %oldclient;
}
« Last Edit: November 22, 2010, 11:18:14 AM by Gartanium »

i don't think you need %newclient.votecount = 0;, as it will reset by itself on the next loop
also, what would the 2nd for loop do? the other one already finds the highest, if equal or not

I put the 2nd loop in to see if two votecounts equal each other, and I put the votecount to 0 so on the 2nd loop, it wouldn't check for lower variables equaling each other. I only wanted it checking to see if the two highest equal each other.

ah, for ties? you could use an = check after the > check, and if true, then put the name somewhere