SA-MP Forums Archive
Help with script - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help with script (/showthread.php?tid=329672)



Help with script - boyan96 - 29.03.2012

How i can make every hour to give to all players 100 score


Re: Help with script - Zhao - 29.03.2012

Use a timer that calls every hour, then use a for loop or foreach to increase their score by 100.

https://sampwiki.blast.hk/wiki/SetTimer
https://sampwiki.blast.hk/wiki/SetPlayerScore
https://sampwiki.blast.hk/wiki/For


Re: Help with script - park4bmx - 29.03.2012

pawn Код:
new ScoreTimer[MAX_PLAYERS];

ScoreTimer[playerid] = SetTimerEx("AddScore", 3600000, true, "i", playerid);//add the timer to OnPlayerConnect

forward AddScore(playerid);
public AddScore(playerid)
{
SetPlayerScore(playerid,GetPlayerScore(playerid)+100);
//adds +100 ever 1hr
}

/*when the player leave the server kill the timer !
Go on "OnPlayerDisconnect" adn add this */

KillTimer(ScoreTimer[playerid]);
edit
Post bellow is right it the timer need to grt killed after the player leaves no dies !
God knows what I was thinking


Re: Help with script - Twisted_Insane - 29.03.2012

@park4bmx

The correct code should look like this:

pawn Код:
new ScoreTimer[MAX_PLAYERS];
ScoreTimer[playerid] = SetTimerEx("AddScore", 3600000, true, "i", playerid);
forward AddScore(playerid);
public AddScore(playerid)
{
     SetPlayerScore(playerid,GetPlayerScore(playerid)+100)
}

//now add this under OnPlayerDISCONNECT, NOT OnPlayerDeath
KillTimer(ScoreTimer[playerid])
Why should you kill the timer when the player died? He'd still play, so you'll have to kill it when he leaves the server / disconnects!