PDA

View Full Version : Score Timer


TheSnaKe
04/12/2013, 01:08 AM
Hey guys,i want a script that give +1 score every 1 hour.
I watched the tutorials about the score timer like +1 score every 1 hour but i didn't understood, can someone do
it for me or explain it to me please?

eblood1
04/12/2013, 01:41 AM
Here you go, have a look at this I've just created:

new pTimeOnline[MAX_PLAYERS];

public OnGameModeInit()
{
SetTimer("Timer_Second", 1000, true);
}

forward Timer_Second();
public Timer_Second()
{
for(new i = 0; i != MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(pTimeOnline[i] == 3600)
{
pTimeOnline[i] = 0;
SetPlayerScore(i, GetPlayerScore(i) + 1);
} else
pTimeOnline[i]++;
}
}
}

public OnPlayerConnect(playerid)
{
pTimeOnline[playerid] = 0;
return 1;
}

Loot
04/12/2013, 03:30 AM
Why not just:

#define AddScore(%0) SetPlayerScore(%0, GetPlayerScore(%0) + 1)

public OnGameModeInit()
{
SetTimer("Timer", 3_600_000, true); // 1 hour
}

forward Timer();
public Timer()
{
for(new i = 0; i != MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
AddScore(i);
}
}

eblood1
04/12/2013, 04:06 AM
Because if someone joined a few seconds before the interval was about to tick 60 minutes, they would also get +1 score.

TheSnaKe
04/12/2013, 10:41 AM
Okay guys thanks, +Rep

Loot
04/12/2013, 04:37 PM
Because if someone joined a few seconds before the interval was about to tick 60 minutes, they would also get +1 score.
Yes, but that's not what he asked for.
He wanted a simple timer (1 hour) that adds the players 1 score, not by checking if they were online for 1 hour.