Map voting (+rep)
#1

I'm making a dialog map voting system.

I have currently got the dialog to show up and players can vote on a map.
pawn Код:
if(listitem == 0) {
map1 ++;
             }
if(listitem == 1) {
map2 ++;             
                      }
How do i get the voting to finish after everyone has voted?

And

How do i check what map has the most votes at the end?
Reply
#2

Add this above OnGameModeExit or under OnGameModeInit:
pawn Код:
new MapNames[][4] =
{
    {55,66,77},
    {1,1,1}
};

new Map[][] =
{
    "Map1",
    "Map2"
};

new CurrentMap = 0;
new Votes[50];
new CanVote[MAX_PLAYERS];
new bool:ActiveVote;

stock GetHighestNumberEx(num[], size = sizeof(num))
{
    new highesty = 0;
    for (new i = 0; i < size; i++)
    {
        if (num[i] > highesty) highesty = num[i];
    }
    return highesty;
}

forward endvote();
public endvote()
{
    ActiveVote = false;
    new high = GetHighestNumberEx(Votes);
    printf("%d",high);
    for (new i = 0; i<sizeof(Votes);i++)
    {
        if (Votes[i] == high)
        {
        CurrentMap = i;
        new msg[50];
        format(msg,sizeof(msg),"The Map %s Has been Nominated.",Map[i]);
        SendClientMessageToAll(COLOR_RED,msg);
        break;
        }
    }
   
    return 1;
}
forward BeginVote();
public BeginVote()
{
    SendClientMessageToAll(COLOR_RED,"Voting Ends in 15 seconds. Cast your Votes");
    SetTimer("endvote",15000,0);
    ActiveVote = true;
    new info[150];
    for (new i = 0;i<sizeof(MapNames);i++)
    {
        if (i == 0) format(info,sizeof(info),"%s\n",Map[i]);
        if (i == sizeof(MapNames)-1) format(info,sizeof(info),"%s%s",info,Map[i]);
        if (i != sizeof(MapNames) && i != 0) format(info,sizeof(info),"%s\n",info,Map[i]);
    }
    for (new i = 0;i<MAX_PLAYERS; i++)
    {
        CanVote[i] = 1;
        ShowPlayerDialog(i,500,DIALOG_STYLE_LIST,"Vote for Map",info,"Vote","Vote");
    }
    return 1;
}


stock GetHighestNumber(...)
{
    new args = numargs();
    new highestyet = 0;
    for (new i = 0; i<args; i++)
    {
        if (getarg(i,0) > highestyet) highestyet = getarg(i,0);
    }
    return highestyet;
}
This under OnPlayerConnect:
pawn Код:
if (ActiveVote == true) CanVote[playerid] = 0;
This above OnPlayerSpawn:
pawn Код:
forward Spawn(playerid);
public Spawn(playerid)
{
    SetPlayerPos(playerid,MapNames[CurrentMap][1],MapNames[CurrentMap][2],MapNames[CurrentMap][3]);
    new msg[50];
    format(msg,sizeof(msg),"You have Spawned In Map: %s(%d,%d,%d)",Map[CurrentMap],MapNames[CurrentMap][0],MapNames[CurrentMap][1],MapNames[CurrentMap][2]);
    SendClientMessage(playerid,COLOR_RED,msg);
    return 1;
}
This under OnPlayerSpawn:
pawn Код:
SetTimerEx("Spawn",500,0,"%d",playerid);
Best Of Luck!
Reply
#3

This is not what i need.. this is someone's filterscript.

I have everything scripted as my own. I would just like to know how to determin what map has the most amount of votes.

I have it so it counts the amount of players online. It also counts the amount of votes each map has.

So how do i determin which has the most amount of votes? I do no wish to rescript all of what i've made
Reply
#4

THIS
pawn Код:
stock GetHighestNumber(...)
{
    new args = numargs();
    new highestyet = 0;
    for (new i = 0; i<args; i++)
    {
        if (getarg(i,0) > highestyet) highestyet = getarg(i,0);
    }
    return highestyet;
}
Reply
#5

how do i use it with these variables.

map1; //being the amount of votes people placed for this map
map2;
Reply
#6

Havn't made a system like this before but it seems pretty straight forward.

For detecting when everyone has voted assign a value against MAX_PLAYERS and when the combined value of the two map var's reach the same value as MAX_PLAYERS then you know everyone has voted.

There is proberly a better way to do this, i'm sure you will get more replies soon.
Reply
#7

Yeah, that would work but i still need to know how to determin which has more votes at the end
Reply
#8

Quote:
Originally Posted by Marco_Valentine
Посмотреть сообщение
Yeah, that would work but i still need to know how to determin which has more votes at the end
Here a newbie code;
if(map1 > map2) { // pick map1 }
else if(map2 > map1) { // pick map2 }
else if(map1 == map2) { // revote }

Try something alike that.
Reply
#9

I thought of that but i plan to add more than 2 maps so it got a little confusing
Reply
#10

would this work?

pawn Код:
public Count(playerid)
{
    if(map1 > map2 && map1 > map3) {
    //choose map1
    }
   
    else if(map2 > map1 && map2 > map3) {
    //choose map2
    }
   
    else if(map3 > map1 && map3 > map2) {
    //choose map3
    }
   
    return 1;
    }
I will just need to work on it every time i add a new map
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)