Alot of timers in one?
#1

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?
Reply
#2

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;
}
Reply
#3

Something similar to that, but i already made it.
Thanks for help.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)