SA-MP Forums Archive
Creating a timer - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Creating a timer (/showthread.php?tid=270579)



Creating a timer - slymatt - 20.07.2011

is there any way of creating a timer without using forwards and new publics?

Thanks


Re: Creating a timer - 0_o - 20.07.2011

No There Is No Other Way. Don't Be Lazy Creating Publics And Forwards


Re: Creating a timer - slymatt - 20.07.2011

im not being lazy im tryin to figure a way of making a timer in a public becase i need the time to start on player spawn because its a death timer when the player dies they will be put in hospital for the set amount of time you get me?


Re: Creating a timer - Daren_Jacobson - 20.07.2011

Yes there is but it is essentially re-inventing the wheel.

It involves many variables OnPlayerUpdate (Or another fast ticking function) and GetTickCount.


AW: Re: Creating a timer - Nero_3D - 20.07.2011

it matters if you are on windows or another OC

in windows you just could use tickcount or GetTickcount

pawn Код:
new TimeAlive[MAX_PLAYERS];
pawn Код:
//OnPlayerSpawn
    TimeAlive[playerid] = tickcount();
pawn Код:
//OnPlayerDeath
    TimeAlive[playerid] = tickcount() - TimeAlive[playerid];
TimeAlive[playerid] stores, after the second call, the time in milliseconds between spawn and death


If you use any other OS in which tickcount() doesnt work you could use a reapeating 1 second timer

pawn Код:
//OnPlayerSpawn
    TimeAlive[playerid] = 0; // resets the tracker
pawn Код:
//Timer which gets called each second
    for(new i; i < MAX_PLAYERS; ++i) {
        TimeAlive[i]++;
    }
TimeAlive[playerid] stores in this case the time in seconds