SA-MP Forums Archive
Timer example - 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: Timer example (/showthread.php?tid=77642)



Timer example - Sal_Kings - 13.05.2009

mind giving me a short stupid script if how timers work? I dont understand a thing about how to use them

Give me a example once you type /healme you wait 1 minute then you get healed.


Re: Timer example - Weirdosport - 13.05.2009

For the example you requested SetTimerEx is most suitable..

pawn Код:
#include <a_samp>

forward HealTimer(playerid);

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/healme", cmdtext, true, 10) == 0)
    {
        SetTimerEx("HealTimer", 60000, 0, "d", playerid);
        return 1;
    }
    return 0;
}

public HealTimer(playerid)
{
    SetPlayerHealth(playerid, 100.0);
}
I changed the scenario to show you how to use SetTimer, this time it's a gate close timer. When the player uses the command the gate opens, and 5 seconds later the timer closes it:

pawn Код:
#include <a_samp>
forward GateTimer();
new Gate;

public OnFilterScriptInit()
{
    Gate = CreateObject(976,-1571.597,665.725,6.349, 0.0, 0.0, 90.0);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/opengate", cmdtext, true, 10) == 0)
    {
        MoveObject(Gate, -1571.597,656.572,6.349, 2.0);
        SetTimer("GateTimer", 5000, 0);
        return 1;
    }
    return 0;
}

public GateTimer()
{
    MoveObject(Gate, -1571.597,665.725,6.349, 2.0);
}