SA-MP Forums Archive
Quick help on command that has 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)
+--- Thread: Quick help on command that has timer (/showthread.php?tid=393845)



Quick help on command that has timer - jakejohnsonusa - 20.11.2012

Ok so I decided to create a command in my GM that acts as hazard lights. What it does it constantly turn the lights on and off when someone does /hazard. But I am trying to get it where /hazard turns it on AND off. How do I do this? Please tell me what to add so that /hazard will both set the timer to on if its off and kill the timer if it's is on.

Thanks,
jakejohnsonusa

Here is what I have so far:
pawn Код:
if(!strcmp(cmd, "/hazard", true))
    {
        if(IsPlayerConnected(playerid))
        {
            if(IsPlayerInAnyVehicle(playerid))
            {
                flashers1 = SetTimer("Flashers", 1000, true);
            }
        }
    }
And for the flashers timer:
pawn Код:
public Flashers ()
{
    new playerid;
    new newcar = GetPlayerVehicleID(playerid);
    ToggleVehicleLights(newcar)
    return 1;
}
**I do have the defined things and it compiles and works, all I need is to make it where /hazard will also turn it off once it's on***


Re: Quick help on command that has timer - Azazelo - 20.11.2012

pawn Код:
new CarFlasher[MAX_VEH];
if(!strcmp(cmd, "/hazard", true))
    {
        if(IsPlayerConnected(playerid))
        {
            if(IsPlayerInAnyVehicle(playerid))
            {
                new newcar = GetPlayerVehicleID(playerid);
                if(CarFlasher[newcar] == -1)
                {
                CarFlasher[newcar] = SetTimer("Flashers", 1000, true);
                }
                if(CarFlasher[newcar] != -1)
               {
                KillTimer(CarFlasher[newcar]);
                CarFlasher[newcar] == -1;
               }
            }
        }
    }