ScoreTimer Only works for PlayerID 0
#8

The EASIEST way to do it is with foreach. You need to download the 'foreach' include first and add #include <foreach> in your script.

Then...

With foreach include:
pawn Код:
#include <foreach>
public OnFilterScriptInit() //Or OnGameModeInit()
{
    SetTimer("ScoreTimer", 1000, true);
    return 1;
}

forward ScoreTimer();
public ScoreTimer()
{
    foreach(Player, i) //If you're using foreach include. (RECOMMENDED)
    {
        if(PlayerInfo[i][LoggedIn] == 1) //Check if player is logged in. Remember use 'i' not 'playerid'
        {
            seconds[i]++;
            if(seconds[i] >= 60)
            {
                SetPlayerScore(i, GetPlayerScore(i) + 1);
                seconds[i] = 0;
            }
        }
    }
    return 1;
}
Without foreach include:
pawn Код:
public OnFilterScriptInit() //Or OnGameModeInit()
{
    SetTimer("ScoreTimer", 1000, true);
    return 1;
}

forward ScoreTimer();
public ScoreTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][LoggedIn] == 1)
            {
                seconds[i]++;
                if(seconds[i] >= 60)
                {
                    SetPlayerScore(i, GetPlayerScore(i) + 1);
                    seconds[i] = 0;
                }
            }
        }
    }
    return 1;
}
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)