#1

I'm wondering how to make a vote system, so players can Vote for things.. the main thing I need help here is how the thing with most votes will be picked.

Right now I have dialog where players are voting so I have variable to count votes at 3 different things:
Код:
new EventVoteType[3];
How can I detect which thing has the most votes and it will be choosen for whatever will I decide to do :P
Reply
#2

PHP код:
new compareWithNext 0;
for(new 
0;sizeof(EventVoteType); i++)
{
    if(
!= (sizeof(EventVoteType) - 1))
    {
        if(
EventVoteType[compareWithNext] < EventVoteType[i+1])
        {
            
compareWithNext i+1;
        }
    }
}
return 
EventVoteType[compareWithNext
I guess that should do it

And here is an alternative(thats ugly code tho ^^)

PHP код:
if(EventVoteType[0] < EventVoteType[1])
{
    if(
EventVoteType[1] < EventVoteType[2])
    {
        return 
EventVoteType[2];
    }
    return 
EventVoteType[1];
}
else
{
    if(
EventVoteType[0] < EventVoteType[2])
    {
        return 
EventVoteType[2];
    }
    return 
EventVoteType[0];

Reply
#3

Okay no errors, how can I use that code in Send Client Message like.. "(event number / name) has most of the votes"

repped.
Reply
#4

PHP код:
stock getMostVotes()
{
    new 
compareWithNext 0;
    for(new 
0;sizeof(EventVoteType); i++)
    {
        if(
!= (sizeof(EventVoteType) - 1))
        {
            if(
EventVoteType[compareWithNext] < EventVoteType[i+1])
            {
                
compareWithNext i+1;
            }
        }
    }
    return 
compareWithNext;
}
format(stringsizeof(string), "Event number %i has the most votes"compareWithNext 1);
SendClientMessage(playerid,-1,string); 
i added the "+ 1" cuz i thinik the users should think that event 0 is the one with the most votes even tho there was no 0 ^^
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)