Whats wrong with this code?
#1

hi,

i use a timer to check how many players are still in game.
If a player dies he is out of the game and he cant spawn anymore.
But this code does not work.
The first time the timer checks it ends the round even if there are still more than 1 players in game.
wheres the error?

pawn Код:
new pLiving;
new pAliveTimerKill;
new chainsawed[MAX_PLAYERS];

//Before round starts
chainsawed[playerid] = 0;//player is not dead yet...

//OnPlayerConnect
chainsawed[playerid] = 1;//so the player cant spawn while a round is in progress

//OnPlayerDeath
chainsawed[playerid] = 1;


//As soon as the round starts
pAliveTimerKill = SetTimer("pAliveChecker",4000,true);


forward pAliveChecker();//this is a timer checking how many players are still alive...
public pAliveChecker()
{

    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if((chainsawed[i] == 0))//if player is still in game
        {
        pLiving++;
        }
        if(pLiving > 1)//if there are more than 1 players alive
        {
        pLiving = -1;//reset the variable
        }
        if(pLiving == 1 || pLiving == 0)//if only 1 player is alive or if server is empty
        {
            ChainsawEnder();//this is a stock that ends the round and changes the map...

            KillTimer(pAliveTimerKill);
           
            break;
        }
    }
    return 1;
}

regards...
Reply
#2

Quote:
Originally Posted by BlackWolf120
Посмотреть сообщение
hi,

i use a timer to check how many players are still in game.
If a player dies he is out of the game and he cant spawn anymore.
But this code does not work.
The first time the timer checks it ends the round even if there are still more than 1 players in game.
wheres the error?

pawn Код:
new pLiving;
new pAliveTimerKill;
new chainsawed[MAX_PLAYERS];

//Before round starts
chainsawed[playerid] = 0;//player is not dead yet...

//OnPlayerConnect
chainsawed[playerid] = 1;//so the player cant spawn while a round is in progress

//OnPlayerDeath
chainsawed[playerid] = 1;


//As soon as the round starts
pAliveTimerKill = SetTimer("pAliveChecker",4000,true);


forward pAliveChecker();//this is a timer checking how many players are still alive...
public pAliveChecker()
{

    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if((chainsawed[i] == 0))//if player is still in game
        {
        pLiving++;
        }
        if(pLiving > 1)//if there are more than 1 players alive
        {
        pLiving = -1;//reset the variable
        }
        if(pLiving == 1 || pLiving == 0)//if only 1 player is alive or if server is empty
        {
            ChainsawEnder();//this is a stock that ends the round and changes the map...

            KillTimer(pAliveTimerKill);
           
            break;
        }
    }
    return 1;
}

regards...
Maybe its if "chainsawed[i] == 1)"?
Reply
#3

Код:
forward pAliveChecker();//this is a timer checking how many players are still alive...
public pAliveChecker()
{

    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if((chainsawed[i] == 0))//if player is still in game
        {
            pLiving++;
        }
        if(pLiving > 1)//if there are more than 1 players alive 
        {
		pLiving = -1;//reset the variable
        }
        if(pLiving == 1 || pLiving == 0)//if only 1 player is alive or if server is empty
        {
            ChainsawEnder();//this is a stock that ends the round and changes the map...

            KillTimer(pAliveTimerKill);
            pLiving = 0;
            chainsawed[i] = 0;
            break; 
        }
    }
    return 1;
}
try this no garentee it will work but possible, pm if you want more help, ill be glad to help
Reply
#4

try this
pawn Код:
public pAliveChecker()
{

    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if((chainsawed[i] == 0))pLiving++;
    }
    if(pLiving > 1)pLiving = -1;//reset the variable
    else if(pLiving == 1 || pLiving == 0)//if only 1 player is alive or if server is empty
    {
        ChainsawEnder();//this is a stock that ends the round and changes the map...
        KillTimer(pAliveTimerKill);
        pLiving = 0;
        for(new i=0; i < MAX_PLAYERS; i++)chainsawed[i] = 0;
        }
    }
    return 1;
}
Reply
#5

thx alot for all ur answers but it is still not working
As soon as there is only 1 player alive (chainsawed=0) the round is not ended.
Any other ideas?
The error must be somewhere in the pLiving count or the loop...
Would be very happy about some help
Reply
#6

pawn Код:
forward pAliveChecker();//this is a timer checking how many players are still alive...
public pAliveChecker()
{
    new playersalive;
    for(new playerid; playerid < MAX_PLAYERS; playerid++)
    {
        if(IsPlayerConnected(playerid)) // is player online?
        {
            if(chainsawed[playerid] == 0) //if player is still in-game
            {
                playersalive++;
            }
        }
    }

    if(playersalive <= 1) // if 1 or below
    {
        ChainsawEnder();//this is a stock that ends the round and changes the map...
        KillTimer(pAliveTimerKill);
    }
    return 1;
}
Reply
#7

thx sooo much
this works now!
Could u tell me where the main error was pls?
In the IsPlayerConnected Part?

thx alot!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)