Help with timers
#1

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

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

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
Reply
#4

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

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...
Reply
#6

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

Код:
  
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.
Reply
#8

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
Reply
#9

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

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)