Jump to content

Blip Off when Lights Got Broken


DarkLink

Recommended Posts

Guys I made this code to turn off the blip attached to vehicle when that vehicle get both front lights broken, but it doesnt work.

can someone help me?

  
function luzesPartidasDesligarBlip (thePlayerOrVehicle, matchingDimension) 
    if ( (getVehicleLightState ( thePlayerOrVehicle, 0 ) == 1) and (getVehicleLightState ( thePlayerOrVehicle, 1 ) == 1) ) then 
    destroyElement (blip) 
    end 
end 
addEventHandler ( "onColShapeLeave", getRootElement(), luzesPartidasDesligarBlip ) 
  

Edit: the blip is defined in another function

Link to comment

event didn't trigger when you would need to.

  
function luzesPartidasDesligarBlip() 
    if getVehicleLightState(source,0)==1 and getVehicleLightState(source,1 )==1 then 
       destroyElement(blip) --make sure that blip defined 
    end 
end 
addEventHandler ( "onVehicleDamage", getRootElement(), luzesPartidasDesligarBlip ) 
  

Link to comment

karlis thanks for ur answer ! I already tryed that before, but there is the problem with that trigger..

blips is just turned off on the next onVehicleDamage . dont know if u understand, look this example:

1. u hit house (left light broken)

2. u hit house (right light broken) (blip should be turned off now, but keeps on)

3. on the next hit , the blip is turned off.

u see ? i want to turn off on the second point, just when the hit brokes the last light turned on.

i hope u understand, thanks!

EDIT: I think the solution is calling the same function inside that function, but dont know how to do it in LUA.. add another handler inside function? thanks.

Link to comment

tryed this in recursion , calling the function inside the function

  
function luzesPartidasDesligarBlip() 
   if (not isElement (blip)) then return 
        end 
   if ((getVehicleLightState(source,0)==1) and (getVehicleLightState(source,1 )==1)) then 
        if (isElement ( blip )) then 
            destroyElement(blip) --make sure that blip defined 
        end 
   end 
     
   return luzesPartidasDesligarBlip() 
  
 end 
  
addEventHandler ( "onVehicleDamage", getRootElement(), luzesPartidasDesligarBlip ) 
  

[EDIT: On console I notice that with this recursion mode, the function enters in a infinite loop. Soo we can conclude that, when "onVehicleDamage" brokes a light , that broken light dont get updated for the function, so.. infinite loop. ]

but still doesnt work, the blip goes off on the next hit. not on the hit that brokes the last front light turned on. it seems that when I call that function using onVehicleDamage , that damage that broken the last lamp, doesnt count.. :S

why ???? :(

can someone help me here? I would really appreciate!

Thanks in advance!

Link to comment
Try checking it with a timer after 50 ms (or longer)

but where do i put the setTimer ? when i call the function in recursion?

or..

thanks!

edit:

do u mean this?

function luzesPartidasDesligarBlip() 
   if ((setTimer(getVehicleLightState(source,0),100,1)==1) and (setTimer(getVehicleLightState(source,1 ),100,1)==1)) then 
      if (isElement ( blip )) then 
      destroyElement(blip) --make sure that blip defined 
      end 
    end 
end 
addEventHandler ( "onVehicleDamage", getRootElement(), luzesPartidasDesligarBlip ) 
  

Link to comment
function BrokenLightsDesligarBlip (thePlayerOrVehicle, matchingDimension) 
    if ( (getVehicleLightState ( thePlayerOrVehicle, 0 ) == 1) and (getVehicleLightState ( thePlayerOrVehicle, 1 ) == 1) ) then 
    destroyElement (blip) 
    end 
end 
addEventHandler ( "onColShapeLeave", getRootElement(),BrokenLightsBlip ) 

1- Function is Created? I dind't see the function is being created, but you can created.

2- Another think, you must to put the script in english, is for help you, the scripters can understand what you want.

Link to comment
function BrokenLightsDesligarBlip (thePlayerOrVehicle, matchingDimension) 
    if ( (getVehicleLightState ( thePlayerOrVehicle, 0 ) == 1) and (getVehicleLightState ( thePlayerOrVehicle, 1 ) == 1) ) then 
    destroyElement (blip) 
    end 
end 
addEventHandler ( "onColShapeLeave", getRootElement(),BrokenLightsBlip ) 

1- Function is Created? I dind't see the function is being created, but you can created.

2- Another think, you must to put the script in english, is for help you and they can understand what you want.

ahn? thats the same i post on the start of topic bro :S

u just change the name of the function .. and its not correct, two names different ? i dont understand.

but thanks bro!!

dont know where to use the setTimer :S

Link to comment
function BrokenLightsDesligarBlip (thePlayerOrVehicle, matchingDimension) 
    if ( (getVehicleLightState ( thePlayerOrVehicle, 0 ) == 1) and (getVehicleLightState ( thePlayerOrVehicle, 1 ) == 1) ) then 
    destroyElement (blip) 
    end 
end 
addEventHandler ( "onColShapeLeave", getRootElement(),BrokenLightsBlip ) 

1- Function is Created? I dind't see the function is being created, but you can created.

2- Another think, you must to put the script in english, is for help you, the scripters can understand what you want.

which one? its BrokenLightsTurnOffBlip, if u want in english. and the function its created, its that one u have in Lua code.

then the handler call it.

Link to comment

yes but when do I put the timer function? I already had read the documentation on wiki, but dont know where to put it.. because of the handler..

should it be :

function luzesPartidasDesligarBlip() 
    if getVehicleLightState(source,0)==1 and getVehicleLightState(source,1 )==1 then 
       destroyElement(blip) --make sure that blip defined 
    end 
end 
  
addEventHandler ( "onVehicleDamage", getRootElement(), setTimer(luzesPartidasDesligarBlip,100,1) ) 
  
  

Link to comment

AHAHAHAHHA I MADE IT!! THIS IS AWESOME xD

scripting is so amazing +.+

Look the solution:

function callTheFunction() 
    theVehicleBrokenLights = source 
    setTimer(vehicleBrokenLightsTurnOffBlip, 1000,1) 
end 
  
addEventHandler ( "onVehicleDamage", getRootElement(), callTheFunction ) 
  
  
function vehicleBrokenLightsTurnOffBlip() 
  
    if getVehicleLightState(theVehicleBrokenLights,0) == 1 and getVehicleLightState(theVehicleBrokenLights,1 ) == 1 then 
       destroyElement(blip) --make sure that blip defined 
    end 
end 
  

Thanks alot guys ;D

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...