SA-MP Forums Archive
Looping - 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: Looping (/showthread.php?tid=434066)



Looping - Sanady - 30.04.2013

Hello everybody I am planning to make a vote map system but I got one problem about loop.How to use loop to get number of players who voted for one map.Anyone got idea?


Re: Looping - MattyG - 30.04.2013

Every time someone votes, you could just add one to a global variable, then find the highest voted map from the variables?


Re: Looping - Sanady - 30.04.2013

Quote:
Originally Posted by MattyG
View Post
Every time someone votes, you could just add one to a global variable, then find the highest voted map from the variables?
Aha ok that.But I need to get number of people who voted for each map I don`t know how to explain...Maybe you understand me what I want to do.


Re: Looping - MattyG - 30.04.2013

Just add an array at the top of your script, like this:

pawn Code:
new votes[NUMBER_OF_MAPS_HERE];
then under where someone votes:

pawn Code:
votes[MAP_NUMBER_HERE]++;
and then do something like this to find the highest voted map:

pawn Code:
new numvotes, winner;
for(i=0;i<NUMBER_OF_MAPS_HERE;i++)
{
    if(votes[i] > numvotes)
    {
        winner = i;
    }
}
and then the winner is votes[winner]


Re: Looping - Sanady - 30.04.2013

Quote:
Originally Posted by MattyG
View Post
Sure, just add an array at the top of your script, like this:

pawn Code:
new votes[NUMBER_OF_MAPS_HERE];
then under where someone votes:

pawn Code:
votes[MAP_NUMBER_HERE]++;
and then do something like this to find the highest voted map:

pawn Code:
new numvotes, winner;
for(i=0;i<NUMBER_OF_MAPS_HERE;i++)
{
    if(votes[i] > numvotes)
    {
        winner = i
    }
}
and then the winner is votes[winner]
Aha Thanks for I understand know what to do.