Help with command
#1

Ok so I have a command that will turn vehicles lights on and off constantly. I wanted the same command thatturns them on to also turn them off, but I must have made a mistake becuase when I do it again it just adds another timer (they flash faster)... Here is what I have:

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;
                }
            }
        }
    }
And under the playerentervehicle part in my script I have this:
pawn Код:
CarFlasher[newcar] = 0;
So what do I need to do/fix?
Reply
#2

I'm surprised its working at all

Quote:

if(CarFlasher[newcar] == 0)
{
CarFlasher[newcar] = SetTimer("Flashers", 1000, true);
CarFlasher[newcar] = 1;
}
if(CarFlasher[newcar] == 1)
{
KillTimer(CarFlasher[newcar]);
CarFlasher[newcar] = 0;
}

You may want to return 1 at the end of each "CarFlasher[newcar] = " bit...because from the looks of that you start the timer, set carflasher to '1', and then immediately after that set carflasher to '0' and kill the timer...
Reply
#3

So your saying I should add two "return 1;" 's to the script one after each "CarFlasher[newcar] = ..." part?

And thanks +1 Rep.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)