Reinhard Posted January 31, 2017 Share Posted January 31, 2017 i tried to use onVehicleExplode to check if vehicle is dead.. but it still doesn't trigger the function fail, how ??? vehicle = createVehicle ( 429, 1, 2, 3, 0, 0, 0) function fail (player) if player and getElementType ( player ) == 'player' then setElementData(player, "mission", false) setTimer(setVehicleLocked, 350, 1, vehicle, false) outputChatBox("test") addEventHandler ( "onVehicleExplode", vehicle, fail ) end end Link to comment
koragg Posted January 31, 2017 Share Posted January 31, 2017 (edited) vehicle = createVehicle ( 429, 1, 2, 3, 0, 0, 0) function fail (player) if player and getElementType ( player ) == 'player' then setElementData(player, "mission", false) setTimer(setVehicleLocked, 350, 1, vehicle, false) outputChatBox("test") end end addEventHandler ( "onVehicleExplode", root, fail ) addEventHandler sits after the whole function. And you need to replace 'vehicle' with 'root' in the addEventHandler line. Edited January 31, 2017 by koragg https://wiki.multitheftauto.com/wiki/AddEventHandler Link to comment
Reinhard Posted January 31, 2017 Author Share Posted January 31, 2017 (edited) 13 minutes ago, koragg said: vehicle = createVehicle ( 429, 1, 2, 3, 0, 0, 0) function fail (player) if player and getElementType ( player ) == 'player' then setElementData(player, "mission", false) setTimer(setVehicleLocked, 350, 1, vehicle, false) outputChatBox("test") end end addEventHandler ( "onVehicleExplode", root, fail ) addEventHandler sits after the whole function. And you need to replace 'vehicle' with 'root' in the addEventHandler line. doesn't work and anyway.. i want it to work at that "vehicle" not all the vehicles in san andreas.... anyways i saw this ex in wiki. not all addEventHandlers are roots... function onThisResourceStart () -- Create the vagos vehicle. A van. vagosVehicle = createVehicle ( 522, 0, 0, 5 ) -- Add its explode handler. When this car explodes, onVagosVehicleExplode is called addEventHandler ( "onVehicleExplode", vagosVehicle, onVagosVehicleExplode ) end my script works with... onVehicleEnter and onVehicleExit but idk why it doesnt work with onVehicleExplode! Edited January 31, 2017 by Reinhard Link to comment
koragg Posted January 31, 2017 Share Posted January 31, 2017 1 minute ago, Reinhard said: doesn't work and anyway.. i want it to work at that "vehicle" not all the vehicles in san andreas.... anyways i saw this ex in wiki. not all addEventHandlers are roots... function onThisResourceStart () -- Create the vagos vehicle. A van. vagosVehicle = createVehicle ( 522, 0, 0, 5 ) -- Add its explode handler. When this car explodes, onVagosVehicleExplode is called addEventHandler ( "onVehicleExplode", vagosVehicle, onVagosVehicleExplode )end If you want it to work only that vehicle then yes, what you did is correct. But the 'addEventhandler' must be after the function in your case. In this^ example it is inside a function, but the addEventHandler is not bound to the same function it is inside of - it's for another function. Link to comment
Reinhard Posted January 31, 2017 Author Share Posted January 31, 2017 Just now, koragg said: If you want it to work only that vehicle then yes, what you did is correct. But the 'addEventhandler' must be after the function in your case. In this^ example it is inside a function, but the addEventHandler is not bound to the same function it is inside of - it's for another function. but my script works with onVehicleEnter and onVehicleExit, it just doesn't work with onVehicleExplode... Link to comment
Reinhard Posted January 31, 2017 Author Share Posted January 31, 2017 (edited) any help? or atleast trigger the function fail if vehicle has 1 or 0 health? Edited January 31, 2017 by Reinhard Link to comment
LoPollo Posted January 31, 2017 Share Posted January 31, 2017 (edited) What @koragg said is correct, you needed only to replace root with vehicle vehicle = createVehicle ( 429, 1, 2, 3, 0, 0, 0) function fail (player) if player and getElementType ( player ) == 'player' then setElementData(player, "mission", false) setTimer(setVehicleLocked, 350, 1, vehicle, false) outputChatBox("test") end end addEventHandler ( "onVehicleExplode", vehicle, fail ) I can't see any problem with his script, did you try to edit it as he told you? Have fun with scripting Edited January 31, 2017 by LoPollo Link to comment
Reinhard Posted January 31, 2017 Author Share Posted January 31, 2017 (edited) here's the part of my code, for some reason, it says element at argument 2 got nil at the addEventHandler("onVehicleExplode", vehicle, fail)? why? function createVehicles ( ) loc = math.random ( #vehicles ) vehicle = createVehicle ( 429, vehicles[loc][1], vehicles[loc][2], vehicles[loc][3], 0, 0, 0) outputChatBox("test", root, 100, 0, 0, true) blips[vehicles] = createBlipAttachedTo(vehicle, 41) setBlipVisibleDistance(blips[vehicles], 150) addEventHandler ( "onVehicleEnter", vehicle, start ) addEventHandler ( "onVehicleExit", vehicle, removedata2 ) end function fail (player) if player and getElementType ( player ) == 'player' then setElementData(player, "mission", false) setTimer(setVehicleLocked, 350, 1, vehicle, false) outputChatBox("test") end end addEventHandler ( "onVehicleExplode", vehicle, fail ) Edited January 31, 2017 by Reinhard Link to comment
iPrestege Posted January 31, 2017 Share Posted January 31, 2017 move the event handler from line 18 to 8 or after 8 because the vehicle is nil until it's created. Link to comment
Reinhard Posted January 31, 2017 Author Share Posted January 31, 2017 (edited) no more debug errors but still doesn't work wtf? but the onVehicleExit and onVehicleEnter works.... function createVehicles ( ) loc = math.random ( #vehicles ) vehicle = createVehicle ( 429, vehicles[loc][1], vehicles[loc][2], vehicles[loc][3], 0, 0, 0) outputChatBox("test", root, 100, 0, 0, true) blips[vehicles] = createBlipAttachedTo(vehicle, 41) setBlipVisibleDistance(blips[vehicles], 150) addEventHandler ( "onVehicleEnter", vehicle, start ) addEventHandler ( "onVehicleExit", vehicle, removedata2 ) addEventHandler ( "onVehicleExplode", vehicle, fail ) end function fail (player) if player and getElementType ( player ) == 'player' then setElementData(player, "mission", false) setTimer(setVehicleLocked, 350, 1, vehicle, false) outputChatBox("test") end end Edited January 31, 2017 by Reinhard Link to comment
pa3ck Posted January 31, 2017 Share Posted January 31, 2017 function fail (player) -- Are you sure this actually returns the player? I don't see it on the wiki... if player and getElementType ( player ) == 'player' then setElementData(player, "mission", false) setTimer(setVehicleLocked, 350, 1, vehicle, false) outputChatBox("test") end end addEventHandler ( "onVehicleExplode", vehicle, fail ) Try to get the "player" by using this: local player = getPedOccupiedVehicle(source) Link to comment
LoPollo Posted January 31, 2017 Share Posted January 31, 2017 onVehicleExplode doesn't pass any argument, and at line 13 you return the function if "player" argument does not exist (and it always does not, so the function will always end here) Link to comment
Reinhard Posted January 31, 2017 Author Share Posted January 31, 2017 (edited) Works now! thanks for the help y'all! Edited January 31, 2017 by Reinhard 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