Voting system - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Voting system (
/showthread.php?tid=514305)
Voting system -
kamiliuxliuxliux - 20.05.2014
Hello. I've a question about a voting system I'm creating now. For an example a dialog appears for every player and they have to vote for the map which player likes. The system recieved results such as:
Map1- 8
Map2- 2
Map3- 9
Map4- 5
Now a question. How to
get map which has the most votes?
Re : Voting system -
mirou123 - 20.05.2014
Let's say you have map[0] = 8, map[1] = 2....map[4] = 5.
I'm sure there are better ways but this should work
Код:
new index, largest;
// Loop through the whole array.
for(new i = 0; i < 4; i++)
{
if(map[i] > largest)
{
// Update the index
index = i;
// Update the largest value.
largest = map[i];
}
}
now map[index] is the array with the largest value.
But of course you have to change "4" to the number of maps and store values in an array.
Re: Voting system -
kamiliuxliuxliux - 20.05.2014
Thanks for advice. I'll check it in the morning.
Re : Voting system -
mirou123 - 20.05.2014
Let me know when you test it. Good luck.
Re: Voting system -
kamiliuxliuxliux - 21.05.2014
Yes! It works. Thank you a lot!