23.08.2012, 20:47
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:
Without foreach include:
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;
}
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;
}