Looping
#1

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?
Reply
#2

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

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.
Reply
#4

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]
Reply
#5

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)