Liberty Unleashed
Scripting => Script Help => Topic started 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?
-
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.
-
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
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
-
I would also call the timer something, or add it to an array. So you can actually stop it..
-
I forgot here is the complete idea:
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. :)
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. :)
-
Wait, Rocky/Shadow, if the light state is on, why are you setting it "on" again? Shouldn't it be
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:
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.
if(!AlarmState[veh])
{
// alarm is disabled
}