joriss11 Posted January 11, 2018 Posted January 11, 2018 Hey, i am having an issue regarding a certain script. I am trying to create a script, in which the player will automaticly exit the vehicle once it catches fire / has a certain amount of health left. this is what I currently have : [lua] setTimer( function (player) local yass = getPedOccupiedVehicle(player) for _, vehicle in ipairs ( getElementsByType ( "vehicle" ) ) do if getElementHealth(vehicle) < 301 then setVehicleDamageProof( vehicle, true) setVehicleEngineState( vehicle, false) setTimer(removeThePed, 100, 1) else if getElementHealth(vehicle) > 302 then setVehicleDamageProof( vehicle, false) setVehicleEngineState( vehicle, true) end end end end, 100, 0 ) function removeThePed ( ) removePedFromVehicle ( yass ) -- Removes the ped from any vehicle. end [/lua] From what I know I tried my best to get things working correctly. The damage proof and engine state works fine, but the player wont exit the vehicle. if anyone could assist me, that would be great, joriss11
Dimos7 Posted January 11, 2018 Posted January 11, 2018 (edited) removePedFromVehicle Edited January 11, 2018 by Dimos7
URBAN Posted January 12, 2018 Posted January 12, 2018 This is better use this. Quote function checkDamage(loss) if getElementHealth(source) > 301 then setVehicleDamageProof(source,false) setVehicleEngineState(source,true) else setVehicleDamageProof(source,true) setVehicleEngineState(source,false) end for i,player in ipairs(getVehicleOccupants(source)) do removePedFromVehicle(player) end end addEventHandler("onVehicleDamage",getRootElement(),checkDamage) Regards, URBAN
joriss11 Posted January 12, 2018 Author Posted January 12, 2018 Tried your code @URBAN, however this doesn't work either. Using your code the script wont even load, which is a problem haha.
URBAN Posted January 12, 2018 Posted January 12, 2018 4 hours ago, joriss11 said: Tried your code @URBAN, however this doesn't work either. Using your code the script wont even load, which is a problem haha. Which side did u try? I tried that it works well. put it on server side.
joriss11 Posted January 12, 2018 Author Posted January 12, 2018 Ahh, I tried client side, that might be the issue
URBAN Posted January 12, 2018 Posted January 12, 2018 @joriss11 function checkDamage(loss) if getElementHealth(source) > 301 then setVehicleDamageProof(source,false) setVehicleEngineState(source,true) else setVehicleDamageProof(source,true) setVehicleEngineState(source,false) for i,player in pairs(getVehicleOccupants(source)) do removePedFromVehicle(player) end end end addEventHandler("onVehicleDamage",getRootElement(),checkDamage) Use this version i just changed position of loop
joriss11 Posted January 12, 2018 Author Posted January 12, 2018 @URBAN This worked, however this TP's the player outside of the vehicle, instead of letting him get out using the regular animation. Which is what I was trying to achieve. Is that possible to do so?
URBAN Posted January 12, 2018 Posted January 12, 2018 (edited) @joriss11 Yes its possible use setControlState(player,"enter_exit",true) instead of removePedFromVehicle(player) Edited January 12, 2018 by URBAN forgot ',' 1
joriss11 Posted January 12, 2018 Author Posted January 12, 2018 (edited) Thanks it worked now, the only issue I am having now, is that its only a one-use script. as It has to be restarted, once a car was destroyed. after that it wont work haha Edit: nvm, works now. Thanks anyways Edited January 12, 2018 by joriss11 1
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