xTravax Posted August 15, 2015 Posted August 15, 2015 addEventHandler("onPlayerWasted",root, function() destroyElement(getPedOccupiedVehicle(source)) end ) this doesn't work it says expected element at argument 1, got boolean can someone explain why this most easiest code in the universe doesn't work? i guess getPedOccupiedVehicle returns false when driver is dead, is there any workaround for this?
nasserdfdd Posted August 15, 2015 Posted August 15, 2015 (edited) try this i did not test i just made it addEventHandler( "onPlayerWasted", getRootElement( ), function() destroyElement(getPedOccupiedVehicle(source)) end ) or try function onWasted() destroyElement(getPedOccupiedVehicle(source)) end -- add the event handler addEventHandler("onClientPedWasted", getRootElement(), onWasted) Edited August 15, 2015 by Guest
Dimos7 Posted August 15, 2015 Posted August 15, 2015 (edited) addEventHandler("onClientPedWasted", getRootElement(), function() if isPedDead(source) == true then destroyElement(getPedOccupiedVehicle(source)) end end ) Edited August 15, 2015 by Guest
HUNGRY:3 Posted August 15, 2015 Posted August 15, 2015 try this i did not test i just made it addEventHandler( "onPlayerWasted", getRootElement( ), function() destroyElement(getPedOccupiedVehicle(source)) end ) getRootElement() is old and root is getRootElement() so your code won't work
DakiLLa Posted August 15, 2015 Posted August 15, 2015 What happens when player is not inside a vehicle and dies? Thats right, getPedOccupiedVehicle() will return false and thus destroyElement() will also fail to execute. addEventHandler("onPlayerWasted", root, function() local veh = getPedOccupiedVehicle(source) if veh then destroyElement(veh) end end ) Btw: getRootElement() is old and root is getRootElement() There is no difference between getRootElement() and root.
xTravax Posted August 15, 2015 Author Posted August 15, 2015 Oh god. @naser that is same code and it wouldn't work @dimos that's the same code with an error, using serverside function in client event (which also is unnecessary because the player is dead for sure) @dakilla i'm in a vehicle, i wouldn't make this topic if i weren't in a vehicle, why would i even want to destroy an un-existant vehicle anyway?
DakiLLa Posted August 15, 2015 Posted August 15, 2015 Oh, yea, sorry. I just found out that there is similar bug report on mantis: https://bugs.mtasa.com/view.php?id=8242 Well, idk, you could make a workaround with element datas, like.. Set player data that he has entered/left the specified vehicle. addEventHandler( "onPlayerVehicleEnter", root, function( veh, seat ) if seat == 0 then setElementData( source, "occupied_veh", veh, false ) end end ) addEventHandler( "onPlayerVehicleExit", root, function( veh, seat ) if seat == 0 and getElementData( source, "occupied_veh" ) == veh then setElementData( source, "occupied_veh", nil, false ) end end ) -- And here goes onPlayerWasted event: addEventHandler( "onPlayerWasted", root, function() local occupied_veh = getElementData( source, "occupied_veh" ) if occupied_veh and isElement( occupied_veh ) then destroyElement( occupied_veh ) end setElementData( source, "occupied_veh", nil, false ) end )
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