Alot of timers in one? - 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: Alot of timers in one? (
/showthread.php?tid=217325)
A lot of timers in one? -
SaW_[VrTx] - 27.01.2011
Hello all..
I have seen somewhere something like this
pawn Код:
StartTimer(timer[playerid]); // Starts timer from 0 miliseconds
If(timer[playerid] == 10000)
{
SendClientMessage(playerid, COLOR_GREEN, "10 seconds already passed");
return 1;
}
If(timer[playerid] == 20000)
{
SendClientMessage(playerid, COLOR_GREEN, "20 seconds already passed");
return 1;
}
How to make it?
Re: Alot of timers in one? -
PowerPC603 - 27.01.2011
Something like this?
pawn Код:
enum TimerData
{
Timer, // Holds the timer instance
TimerValue // Holds the value of the timer (how many seconds have passed)
}
new APlayerData[MAX_PLAYERS][TimerData];
public OnPlayerConnect(playerid)
{
// Start the timer for this player and let it run every second
APlayerData[playerid][Timer] = SetTimerEx("MyTimer", 1000, true, "i", playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
// Kill the timer when the player logs off and reset the timer-id
KillTimer(APlayerData[playerid][Timer]);
APlayerData[playerid][Timer] = 0;
// also reset the timer-value (how many seconds have passed)
APlayerData[playerid][TimerValue] = 0;
return 1;
}
forward MyTimer(playerid);
public MyTimer(playerid)
{
// This timer runs every second, so count the number of seconds that have passed since the player connected to the server
APlayerData[playerid][TimerValue]++;
// Send a message based on how many seconds have passed since the player connected to the server
switch (APlayerData[playerid][TimerValue])
{
case 10: SendClientMessage(playerid, COLOR_GREEN, "10 seconds already passed");
case 20: SendClientMessage(playerid, COLOR_GREEN, "20 seconds already passed");
case 30: SendClientMessage(playerid, COLOR_GREEN, "30 seconds already passed");
}
return 1;
}
Re: Alot of timers in one? -
SaW_[VrTx] - 27.01.2011
Something similar to that, but i already made it.
Thanks for help.