Vote - 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: Vote (
/showthread.php?tid=606939)
Vote -
Lajko1 - 11.05.2016
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
Re: Vote -
BiosMarcel - 11.05.2016
PHP код:
new compareWithNext = 0;
for(new i = 0;i < sizeof(EventVoteType); i++)
{
if(i != (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];
}
Re: Vote -
Lajko1 - 11.05.2016
Okay no errors, how can I use that code in Send Client Message like.. "(event number / name) has most of the votes"
repped.
Re: Vote -
BiosMarcel - 11.05.2016
PHP код:
stock getMostVotes()
{
new compareWithNext = 0;
for(new i = 0;i < sizeof(EventVoteType); i++)
{
if(i != (sizeof(EventVoteType) - 1))
{
if(EventVoteType[compareWithNext] < EventVoteType[i+1])
{
compareWithNext = i+1;
}
}
}
return compareWithNext;
}
format(string, sizeof(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 ^^