Jump to content

Help with Emergancy Lights.


Vigo.K

Recommended Posts

Hello, guys. I'm just download "Emergancy Lights".

And there is some bug, can't turn off that lights and in consule it's shows:

WARNING: vehicles\elights.lua:9: Bad argument @ 'killTimer'

WARNING: vehicles\elights.lua:10: Bad argument @ 'killTimer'

Script file:

function EmergencyLights ( source )      
    theVehicle = getPlayerOccupiedVehicle ( source )      
    if ( theVehicle ) then                                           
        if ( getVehicleOverrideLights ( theVehicle ) ~= 2 ) then  
            setVehicleOverrideLights ( theVehicle, 2 ) 
            setTimer ( setLight, 400, 1 )             
        else 
            setVehicleOverrideLights ( theVehicle, 0 )    
            killTimer ( setLight ) 
            killTimer ( setLight2 )         
        end 
    end 
end 
  
function setLight ( ) 
            setTimer ( setLight2, 400, 1 )         
            setVehicleHeadLightColor (theVehicle, 000, 000, 255)         
end 
  
function setLight2 (  ) 
            setVehicleHeadLightColor (theVehicle, 255, 000, 000)           
            setTimer ( setLight, 400, 1 )     
end 
addCommandHandler ( "elights", EmergencyLights ) 

Waiting your answers. :wink::wink:

Link to comment

setTimer returns timer variable, and this is what you need to kill..

before you copy-paste it without reading:

this will fail on server side (if 2 players activate it - one player timers won't stop)

will work fine on client

for server you need to create a table with timers like:

  
timers1 = { } 
  

then set/kill timer like that:

  
  timers1[playerElement] = setTimer (blabla) 
  --and kill 
  killTimer(timers1[playerElement]) 
  

where playerElement is .. your player element :)

  
function EmergencyLights ( source )      
    theVehicle = getPlayerOccupiedVehicle ( source )      
    if ( theVehicle ) then                                           
        if ( getVehicleOverrideLights ( theVehicle ) ~= 2 ) then  
            setVehicleOverrideLights ( theVehicle, 2 ) 
            setTimer ( setLight, 400, 1 )             
        else 
            setVehicleOverrideLights ( theVehicle, 0 )    
            killTimer ( timer1 ) 
            killTimer ( timer2 )         
        end 
    end 
end 
  
function setLight ( ) 
            setTimer ( setLight2, 400, 1 )         
            timer1 = setVehicleHeadLightColor (theVehicle, 000, 000, 255)         
end 
  
function setLight2 (  ) 
            setVehicleHeadLightColor (theVehicle, 255, 000, 000)           
            timer2 = setTimer ( setLight, 400, 1 )     
end 
addCommandHandler ( "elights", EmergencyLights ) 
  

Link to comment
blueTimers = {} -- vehicle table for your blue timers 
redTimers = {} -- for your red timers 
  
function EmergencyLights(source)      
  local theVehicle = getPedOccupiedVehicle(source) -- getPlayerOccupiedVehicle() is deprecated  
  -- thevehicle must be local, since we can have more than 1 player with vehicles 
  if theVehicle then                                           
    if getVehicleOverrideLights(theVehicle) ~= 2 then  
      setVehicleOverrideLights(theVehicle, 2) 
      blueTimers[theVehicle] = setTimer(setLight, 400, 1, theVehicle)    
      -- vehicle element must be passed to the timer/function, since theVehicle is now local 
    else 
      setVehicleOverrideLights(theVehicle, 0)    
      if isTimer(blueTimers[theVehicle]) then killTimer(blueTimers[theVehicle]) end 
      if isTimer(redTimers[theVehicle]) then killTimer(redTimers[theVehicle]) end 
    end 
  end 
end 
  
function setLight(car) 
  setVehicleHeadLightColor(car, 0, 0, 255)       
  redTimers[car] = setTimer(setLight2, 400, 1, car) 
end 
  
function setLight2(car) 
  setVehicleHeadLightColor(car, 255, 0, 0)         
  blueTimers[car] = setTimer(setLight, 400, 1, car)     
end 
  
addCommandHandler("elights", EmergencyLights) 

Edited by Guest
Link to comment

just read:

http://en.wikipedia.org/wiki/Copyright

http://en.wikipedia.org/wiki/License

also notice the info while editing wiki:

Please note that all contributions to Multi Theft Auto: Wiki are considered to be released under the GNU Free Documentation License 1.2 (see Multi Theft Auto: Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.

You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

short summary:

you ALWAYS have copyrights to your work, but you can allow ppl to freely use and edit the result of your work.

Link to comment

you cant add 1 line to it to switch to white when off?

blueTimers = {} -- vehicle table for your blue timers 
redTimers = {} -- for your red timers 
  
function EmergencyLights(source)     
  local theVehicle = getPedOccupiedVehicle(source) -- getPlayerOccupiedVehicle() is deprecated 
  -- thevehicle must be local, since we can have more than 1 player with vehicles 
  if theVehicle then                                           
    if getVehicleOverrideLights(theVehicle) ~= 2 then 
      setVehicleOverrideLights(theVehicle, 2) 
      blueTimers[theVehicle] = setTimer(setLight, 400, 1, theVehicle)    
      -- vehicle element must be passed to the timer/function, since theVehicle is now local 
    else 
      setVehicleOverrideLights(theVehicle, 0)   
      setVehicleHeadLightColor(theVehicle, 255, 255, 255) -- this   
      if isTimer(blueTimers[theVehicle]) then killTimer(blueTimers[theVehicle]) end 
      if isTimer(redTimers[theVehicle]) then killTimer(redTimers[theVehicle]) end 
    end 
  end 
end 
  
function setLight(car) 
  setVehicleHeadLightColor(car, 0, 0, 255)      
  redTimers[car] = setTimer(setLight2, 400, 1, car) 
end 
  
function setLight2(car) 
  setVehicleHeadLightColor(car, 255, 0, 0)        
  blueTimers[car] = setTimer(setLight, 400, 1, car)    
end 
  
addCommandHandler("elights", EmergencyLights) 

Link to comment
you cant add 1 line to it to switch to white when off?
blueTimers = {} -- vehicle table for your blue timers 
redTimers = {} -- for your red timers 
  
function EmergencyLights(source)     
  local theVehicle = getPedOccupiedVehicle(source) -- getPlayerOccupiedVehicle() is deprecated 
  -- thevehicle must be local, since we can have more than 1 player with vehicles 
  if theVehicle then                                           
    if getVehicleOverrideLights(theVehicle) ~= 2 then 
      setVehicleOverrideLights(theVehicle, 2) 
      blueTimers[theVehicle] = setTimer(setLight, 400, 1, theVehicle)    
      -- vehicle element must be passed to the timer/function, since theVehicle is now local 
    else 
      setVehicleOverrideLights(theVehicle, 0)   
      setVehicleHeadLightColor(theVehicle, 255, 255, 255) -- this   
      if isTimer(blueTimers[theVehicle]) then killTimer(blueTimers[theVehicle]) end 
      if isTimer(redTimers[theVehicle]) then killTimer(redTimers[theVehicle]) end 
    end 
  end 
end 
  
function setLight(car) 
  setVehicleHeadLightColor(car, 0, 0, 255)      
  redTimers[car] = setTimer(setLight2, 400, 1, car) 
end 
  
function setLight2(car) 
  setVehicleHeadLightColor(car, 255, 0, 0)        
  blueTimers[car] = setTimer(setLight, 400, 1, car)    
end 
  
addCommandHandler("elights", EmergencyLights) 

Thanks man! <3

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...