Author Topic: Whether possibly the timer to make a blinking of headlights at the car?  (Read 1619 times)

CANYON

  • Newbie
  • *
  • Posts: 29
  • Karma: +1/-0
    • View Profile
it is possible to make a blinking of headlights at the car by means of the timer?

Rocky

  • Full Member
  • ***
  • Posts: 105
  • Karma: +5/-3
    • View Profile
Re: Whether possibly the timer to make a blinking of headlights at the car?
« Reply #1 on: August 23, 2012, 09: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.
Look for lu server testers, Requirements are:
English good enough to communicate.
Good knowledge about gaming.

PM me those who are interested.

Shadow.

  • Tester
  • Full Member
  • ****
  • Posts: 144
  • Karma: +16/-35
    • View Profile
Re: Whether possibly the timer to make a blinking of headlights at the car?
« Reply #2 on: August 23, 2012, 10: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

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: Whether possibly the timer to make a blinking of headlights at the car?
« Reply #3 on: August 23, 2012, 11:16:35 am »
I would also call the timer something, or add it to an array. So you can actually stop it..

Rocky

  • Full Member
  • ***
  • Posts: 105
  • Karma: +5/-3
    • View Profile
Re: Whether possibly the timer to make a blinking of headlights at the car?
« Reply #4 on: August 23, 2012, 11: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.  :)
« Last Edit: August 23, 2012, 03:15:53 pm by Rocky »
Look for lu server testers, Requirements are:
English good enough to communicate.
Good knowledge about gaming.

PM me those who are interested.

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: Whether possibly the timer to make a blinking of headlights at the car?
« Reply #5 on: August 23, 2012, 02: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
}
« Last Edit: August 23, 2012, 03:05:28 pm by Vortrex »

 

© Liberty Unleashed Team.