Map Votes loop (More than 2 maps)
#1

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

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
Reply
#3

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

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

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

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++;
		}
	}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)