Liberty Unleashed

Scripting => Script Help => Topic started by: CANYON on August 23, 2012, 07:51:18 am

Title: Whether possibly the timer to make a blinking of headlights at the car?
Post by: CANYON on August 23, 2012, 07:51:18 am
it is possible to make a blinking of headlights at the car by means of the timer?
Title: Re: Whether possibly the timer to make a blinking of headlights at the car?
Post by: Rocky on August 23, 2012, 08:03:18 am
Code: [Select]
function BlinkLights( veh )
{
        if(veh)
        {
            if(veh.LightState == LIGHTSTATE_ON) veh.LightState = LIGHTSTATE_ON;
            else veh.LightState = LIGHTSTATE_OFF;
        }
}

NewTimer("BlinkLights",1000,0);

You can also use a single timer to run all vehicle alarms, this is just an idea.
Title: Re: Whether possibly the timer to make a blinking of headlights at the car?
Post by: Shadow. on August 23, 2012, 09:53:50 am
Code: [Select]
function BlinkLights( veh )
{
        if(veh)
        {
            if(veh.LightState == LIGHTSTATE_ON) veh.LightState = LIGHTSTATE_ON;
            else veh.LightState = LIGHTSTATE_OFF;
        }
}

NewTimer("BlinkLights",1000,0);

You can also use a single timer to run all vehicle alarms, this is just an idea.

wrong

Code: [Select]
function BlinkLights( veh )
{
        if(veh)
        {
            if(veh.LightState == LIGHTSTATE_ON) veh.LightState = LIGHTSTATE_ON;
            else veh.LightState = LIGHTSTATE_OFF;
        }
}

NewTimer("BlinkLights",1000,0,veh);

correct
Title: Re: Whether possibly the timer to make a blinking of headlights at the car?
Post by: Thijn on August 23, 2012, 10:16:35 am
I would also call the timer something, or add it to an array. So you can actually stop it..
Title: Re: Whether possibly the timer to make a blinking of headlights at the car?
Post by: Rocky on August 23, 2012, 10:47:03 am
I forgot here is the complete idea:

Code: [Select]
AlarmState <- array(GetVehicleCount(), false );

function ToggleLights( )
{
        local i = 0;
        while(i < GetVehicleCount())
        {
           local veh = FindVehicle( i );
           if( veh && AlarmState[i] )
           {
               if(veh.LightState == LIGHTSTATE_ON) veh.LightState = LIGHTSTATE_OFF;
               else veh.LightState = LIGHTSTATE_OFF;
           }
           i++;
        }
}

function onScriptLoad()
{
     NewTimer("BlinkLights",2000,0,veh);
}

Toggle AlarmState[ ID ] to true or false to enable/disable vehicle alarm.

EDIT: Thanks Vortrex, fixed.  :)

Quote from: Vortrex
Just a thought on saving time when scripting. Also, if something is false, just use the "not" comparison operator (which is an exclamation point) in front of the variable you are checking.

Well, i know that just to become more explanatory to CANYON i used it.  :)
Title: Re: Whether possibly the timer to make a blinking of headlights at the car?
Post by: Vortrex on August 23, 2012, 01:54:22 pm
Wait, Rocky/Shadow, if the light state is on, why are you setting it "on" again? Shouldn't it be

Code: [Select]
if(veh.LightState == LIGHTSTATE_ON) veh.LightState = LIGHTSTATE_OFF;
else veh.LightState = LIGHTSTATE_ON;

EDIT: Another correction:
Rocky, if something is true, you don't have to use "== true" in the if check. Just use:
Code: [Select]
if(AlarmState[veh])
{
      // alarm is enabled
}
Just a thought on saving time when scripting. Also, if something is false, just use the "not" comparison operator (which is an exclamation point) in front of the variable you are checking.
Code: [Select]
if(!AlarmState[veh])
{
      // alarm is disabled
}