SA-MP Forums Archive
Help with timers - 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: Help with timers (/showthread.php?tid=394295)



Help with timers - jakejohnsonusa - 21.11.2012

Ok so I have a timer that will make a cars headlights flash... but I seem to be having troubles with it. I can't seem to get the timer to stop (it starts, but wont stop with the command). What do I need to fix or do?
Here is my code:
pawn Код:
if(!strcmp(cmd, "/hazard", true))//hazard lights
    {
        if(IsPlayerConnected(playerid))
        {
            if(IsPlayerInAnyVehicle(playerid))
            {
                new newcar = GetPlayerVehicleID(playerid);
                if(CarFlasher[newcar] == 0)
                {
                    CarFlasher[newcar] = SetTimer("Flashers", 1000, true);
                    CarFlasher[newcar] = 1;
                }
                if(CarFlasher[newcar] == 1)
                {
                    KillTimer(CarFlasher[newcar]);
                    CarFlasher[newcar] = 0;
                }
            }
        }
        return true;
    }
And the timer command:
pawn Код:
public Flashers ()
{
    new playerid;
    new newcar = GetPlayerVehicleID(playerid);
    ToggleVehicleLights(newcar)
    return 1;
}



Re: Help with timers - ScRaT - 21.11.2012

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



Re: Help with timers - jakejohnsonusa - 21.11.2012

I added return 1; 's to the end and still didn't kill the timer (stop flashing). There MUST be somthing wrong with the actual timer function but I can't find it. I know this because I also tried adding the kill timer part on playerecitvehicle in my GM and it didn't kill the timer (it remained flashing when the player entered the car again).

Please help: jakejohnsonusa


Re: Help with timers - Azazelo - 21.11.2012

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



Re: Help with timers - jakejohnsonusa - 21.11.2012

Now it's not working at all.

NOTE:
pawn Код:
CarFlasher[newcar] = 0;
This is what I have under the on player enter vehicle part in my GM...


Re: Help with timers - ScRaT - 21.11.2012

You can't just kill the timer! You must turn off the lights too.
Killing the timer doesn't turn off the lights.


Re: Help with timers - Dr.Einstein - 21.11.2012

Код:
  
if(!strcmp(cmd, "/hazard", true))//hazard lights
    {
        if(IsPlayerConnected(playerid))
        {
            if(IsPlayerInAnyVehicle(playerid))
            {
                new newcar = GetPlayerVehicleID(playerid);
                if(CarFlasher[newcar] == 0)
                {
                    CarFlasher[newcar] = SetTimerEx("Flashers", 1000, true, "d", newcar);
                    CarFlasher[newcar] = 1;
                }
                if(CarFlasher[newcar] == 1)
                {
                    KillTimer(CarFlasher[newcar]);
                    CarFlasher[newcar] = 0;
                }
            }
        }
        return true;
    }
And this is the function:
Код:
forward Flashers(vehid);
public Flashers (vehid)
{
     ToggleVehicleLights(vehid);
    //your other code
    return 1;
}
Anyways, if you search there is already a filterscript about vehicle lights. Take a look at it and see how it was built, but don't just copy and paste, otherwise you will never learn.


Re: Help with timers - jakejohnsonusa - 21.11.2012

Yes, I have seen others... but none that flash... so I built my own (this). So I did what you asked and added SetTimerEx instead of SetTimer, but again I have the same problem... It doesn't turn off when I do /hazard it just adds a new timer (gets faster).

Still need help...

Thanks: jakejohnsonusa


Re: Help with timers - jakejohnsonusa - 21.11.2012

I just tried to make a command that would kill the timer and it STILL doesn't turn off. What should I do? To fix my original code?


Re: Help with timers - Azazelo - 21.11.2012

pawn Код:
if(!strcmp(cmd, "/hazard", true))//hazard lights
    {
        if(IsPlayerConnected(playerid))
        {
            if(IsPlayerInAnyVehicle(playerid))
            {
                new newcar = GetPlayerVehicleID(playerid);
                if(CarFlasher[newcar] == 0) // is flesher off
                {
                    CarFlasher[newcar] = SetTimer("Flashers", 1000, true); // CarFlasher[newcar] =  timerid
                    CarFlasher[newcar] = 1; // flesher on
                    return 1;
                }
                if(CarFlasher[newcar] == 1) // is flesher on
                {
                    KillTimer(CarFlasher[newcar]);//CarFlasher[newcar] = 1 NOT TIMER ID
                    CarFlasher[newcar] = 0; // flesher off
                    return 1;
                }
            }
        }
        return true;
    }
i hope this will help you to debug you code.