SA-MP Forums Archive
Map Votes loop (More than 2 maps) - 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: Map Votes loop (More than 2 maps) (/showthread.php?tid=367970)



Map Votes loop (More than 2 maps) - Mellnik - 11.08.2012

Hello there

I made a derby script this is the loop which checks which map has the most votes:

Код:
	new highestvar = -1;

	for(new i = 0; i < sizeof(DerbyMapVotes); i++)
	{
 		if(DerbyMapVotes[i] > highestvar)
		{
  			highestvar = DerbyMapVotes[i];
		}
	}
But it dont works when:

there are 4 maps: Map1Votes: 3
Map2Votes: 3
Map3Votes: 0
Map4Votes: 0
It will always choose Map1... How to extend this loop that it works how it should?

Thank you very much!!


Re: Map Votes loop (More than 2 maps) - Roko_foko - 11.08.2012

I think this will help. If not, reply.
pawn Код:
new highestvar = DerbyMapVotes[0],Hvar=0;

    for(new i = 1; i < sizeof(DerbyMapVotes); i++)
    {
        if(DerbyMapVotes[i] > highestvar)
        {
            highestvar = DerbyMapVotes[i];
            Hvar=0;
        }
        else if(DerbyMapVotes[i] == highestvar)Hvar++;
    }
//if Hvar is 1 or more, that means there is tie/draw in voting



Re: Map Votes loop (More than 2 maps) - leonardo1434 - 11.08.2012

Try to follow this logic.

pawn Код:
// storing the names of the maps in the array fuckyeh.
new fuckyeh[] =
{
   "map1",
   "map2",
   "map3"
};
new map1,map2,map3; // creating new variables to be increased in which map the player votes.

if(map1 > map2 && map3) return SendRconCommand(fuckyeh[0]); // checking if the first map has his value bigger than the others.
else if(map2 > map1 && map3) return SendRconCommand(fuckyeh[1]); // checking if the second map has his value bigger than the others.
else if(map3 > map1 && map2) return SendRconCommand(fuckyeh[2]);// checking if the third map has his value bigger than the others.



Re: Map Votes loop (More than 2 maps) - Roko_foko - 11.08.2012

Quote:
Originally Posted by leonardo1434
Посмотреть сообщение
Try to follow this logic.

pawn Код:
// storing the names of the maps in the array fuckyeh.
new fuckyeh[] =
{
   "map1",
   "map2",
   "map3"
};
new map1,map2,map3; // creating new variables to be increased in which map the player votes.

if(map1 > map2 && map3) return SendRconCommand(fuckyeh[0]); // checking if the first map has his value bigger than the others.
else if(map2 > map1 && map3) return SendRconCommand(fuckyeh[1]); // checking if the second map has his value bigger than the others.
else if(map3 > map1 && map2) return SendRconCommand(fuckyeh[2]);// checking if the third map has his value bigger than the others.
What if there are no 3, but 20 maps?
And, what if there are two maps that have equal votes and also have more votes then the other?


Re: Map Votes loop (More than 2 maps) - leonardo1434 - 11.08.2012

Just do the same thing , create more variable's and compare them among themselves, about the draw, just get the these variables and re-make the votation with them or even, add a random among themselves.


AW: Re: Map Votes loop (More than 2 maps) - Mellnik - 11.08.2012

Quote:
Originally Posted by Roko_foko
Посмотреть сообщение
I think this will help. If not, reply.
pawn Код:
new highestvar = DerbyMapVotes[0],Hvar=0;

    for(new i = 1; i < sizeof(DerbyMapVotes); i++)
    {
        if(DerbyMapVotes[i] > highestvar)
        {
            highestvar = DerbyMapVotes[i];
            Hvar=0;
        }
        else if(DerbyMapVotes[i] == highestvar)Hvar++;
    }
//if Hvar is 1 or more, that means there is tie/draw in voting
Thanks I improved it a bit:
Код:
	new highestmapvotes = -1;
	new draw = 0;
	for(new i = 0; i < sizeof(DerbyMapVotes); i++)
	{
 		if(DerbyMapVotes[i] > highestmapvotes && draw == 0)
		{
  			highestmapvotes = DerbyMapVotes[i];
		}
		else if(DerbyMapVotes[i] > highestmapvotes && draw != 0)
		{
		    draw = 0;
		}
		else if(DerbyMapVotes[i] == highestmapvotes)
		{
		    draw++;
		}
	}