Get the highest variable - 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: Get the highest variable - Voting System (
/showthread.php?tid=296191)
Get the highest variable - Voting System -
jamiesage123 - 10.11.2011
Hey,
I'm in need of some help,
I'm basically making a voting system. I have ten different variables which are +1'd every time someone picks it (Its also on a timer for 35 seconds). At the end of the timer i want it to output the highest voted variable.
Voting starts:
pawn Код:
//foreach(Player, i) { etc...
ShowPlayerDialog(i, DIALOG_VOTE, DIALOG_STYLE_LIST, "Vote", "Variable 1\nVariable 2\nVariable 3\nVariable 4\nVariable 5\nVariable 6\nVariable 7\nVariable 8\nVariable 9\nVariable 10", "Vote", "Cancel");
voting = 1;
SetTimer("VoteTimer", 35000, false);
pawn Код:
//public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
//...
case DIALOG_VOTE:
{
switch(listitem) {
case 0:
{
if(voting == 0)
return SendClientMessage(playerid, COLOR_GREY, "Voting time has already eneded!");
variableOne++;
}
case 1:
{
if(voting == 0)
return SendClientMessage(playerid, COLOR_GREY, "Voting time has already eneded!");
variableTwo++;
}
case 2:
{
if(voting == 0)
return SendClientMessage(playerid, COLOR_GREY, "Voting time has already eneded!");
variableThree++;
}
case 3:
{
if(voting == 0)
return SendClientMessage(playerid, COLOR_GREY, "Voting time has already eneded!");
variableFour++;
}
//(etc...)
pawn Код:
public VoteTimer()
{
voting = 0;
GameTextForAll("Voting time has ended.", 5000, 1);
/*
Here is where i want to output the highest vote (variable).
However, i do have to check if the results are even, then i can just do random();
*/
}
I searched for a solutions yesterday, but i couldn't find any.
I'm not totally sure if this is the best way to do it, but it was the first thing which i thought of doing :P
Any help will be much appreciated,
Thanks : )
Re: Get the highest variable - Voting System -
Calgon - 10.11.2011
I'd do something like this:
pawn Код:
new highestVariableValue, highVariable;
if(variableOne > highestVariableValue) {
highestVariableValue = variableOne;
highVariable = 1;
}
if(variableTwo > highestVariableValue) {
highestVariableValue = variableTwo;
highVariable = 2;
}
if(variableThree > highestVariableValue) {
highestVariableValue = variableThree;
highVariable = 3;
}
if(variableFour > highestVariableValue) {
highestVariableValue = variableFour;
highVariable = 4;
}
But I'm sure there's a better way.
Re: Get the highest variable - Voting System -
jamiesage123 - 10.11.2011
Ah thank you so much!
I've also done the checking thing (in-case anyone else has the same problem) by putting the variables into an array (new variable[10]) and then looping through all the variables with for(new i = 1; i < sizeof(variable); i++) and then using 'break;' if it finds two variables which equal each other.