DarkLink Posted June 13, 2011 Share Posted June 13, 2011 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
karlis Posted June 13, 2011 Share Posted June 13, 2011 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
DarkLink Posted June 13, 2011 Author Share Posted June 13, 2011 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
DarkLink Posted June 13, 2011 Author Share Posted June 13, 2011 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.. why ???? can someone help me here? I would really appreciate! Thanks in advance! Link to comment
SDK Posted June 13, 2011 Share Posted June 13, 2011 Try checking it with a timer after 50 ms (or longer) Link to comment
DarkLink Posted June 13, 2011 Author Share Posted June 13, 2011 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
Klesh Posted June 13, 2011 Share Posted June 13, 2011 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
DarkLink Posted June 13, 2011 Author Share Posted June 13, 2011 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 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 Link to comment
DarkLink Posted June 13, 2011 Author Share Posted June 13, 2011 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
Klesh Posted June 13, 2011 Share Posted June 13, 2011 The answer you want can be here. Link to comment
DarkLink Posted June 13, 2011 Author Share Posted June 13, 2011 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
DarkLink Posted June 13, 2011 Author Share Posted June 13, 2011 AHAHAHAHHA I MADE IT!! THIS IS AWESOME 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now