Xwad Posted August 7, 2016 Share Posted August 7, 2016 why is this code not working? thanks. server side vehicle = createVehicle(564, -2839.9,202,16.9) function vehicle_demage(source) if source == vehicle then outPutChatBox("vehicle demaged") end end addEventHandler("onVehicleDamage", root, vehicle_demage) Link to comment
roaddog Posted August 7, 2016 Share Posted August 7, 2016 (edited) First and only parameter onVehicleDamage is the hp loss not vehicle elemnt so function vehicle_damage(loss) if source == vehicle then outputChatBox("vehicle damaged (-"..loss.." HP)") end end addEventHandler("onVehicleDamage", root, vehicle_damage) Posted from mobile Edited August 7, 2016 by Guest Link to comment
Captain Cody Posted August 7, 2016 Share Posted August 7, 2016 vehicle = createVehicle(564, -2839.9,202,16.9) function vehicle_demage() if source == vehicle then outputChatBox("vehicle demaged") end end addEventHandler("onVehicleDamage", root, vehicle_demage) -- Two things, -- One; don't define source up top, it's predefined, all that will do is mess it up. On vehicle damage perimeters are - Source == The source vehicle, Loss == Loss (Which you have to define in the function) -- Two you did outputChatBox wrong, it's not outPutChatBox. You need to make sure your caps are in the right locations. -- Edit -- // Other guy posted while I was writing this // Link to comment
Walid Posted August 7, 2016 Share Posted August 7, 2016 works, thanks! You don't need to use if source == vehicle then just attach the handler to the vehicle like this local vehicle = createVehicle(564, -2839.9,202,16.9) function vehicle_demage() outputChatBox("vehicle demaged") end addEventHandler("onVehicleDamage", vehicle, vehicle_demage) Link to comment
Xwad Posted August 7, 2016 Author Share Posted August 7, 2016 one more question: i tried that with onVehicleExplode, but its not working. The plane is not respawning. It says its a bad argumentum local dodo1 = createVehicle ( 593, -3413.4, -65.5, 18, 0, 0, -90 ) function respawn_dodo() setTimer(respawnVehicle, 5000, 1, source) end addEventHandler("onVehicleExplode", dodo1, respawn_dodo) Link to comment
Captain Cody Posted August 7, 2016 Share Posted August 7, 2016 local dodo1 = createVehicle ( 593, -3413.4, -65.5, 18, 0, 0, -90 ) function respawn_dodo() setTimer(respawnVehicleA, 5000, 1, source) end function respawnVehicleA(vehicle) respawnVehicle(vehicle) end addEventHandler("onVehicleExplode", dodo1, respawn_dodo) Link to comment
_DrXenon Posted August 7, 2016 Share Posted August 7, 2016 His function should work too... I have seen an almost identical one in the MTA wiki.. MTA goes weird sometimes. Link to comment
Captain Cody Posted August 8, 2016 Share Posted August 8, 2016 Try this then.. local dodo1 = createVehicle ( 593, -3413.4, -65.5, 18, 0, 0, -90 ) function respawn_dodo() setTimer(respawnVehicle, 5000, 1, dodo1 ) end addEventHandler("onVehicleExplode", dodo1, respawn_dodo) Link to comment
EstrategiaGTA Posted August 10, 2016 Share Posted August 10, 2016 local dodo1 = createVehicle ( 593, -3413.4, -65.5, 18, 0, 0, -90 ) function respawn_dodo() if source == dodo1 then setTimer(respawnVehicle, 5000, 1, source) end end addEventHandler("onVehicleExplode", root, respawn_dodo) Link to comment
Xwad Posted August 10, 2016 Author Share Posted August 10, 2016 Hmm interesting. I tested it on my local server, and it works. its only not working on he hoster server. But the way thanks! Link to comment
EstrategiaGTA Posted August 10, 2016 Share Posted August 10, 2016 You're welcome ! Probably it's a problem from your server (its scripts), because else it's so weird that it works in one server and doesn't work in the other. Make sure you set this as server side in the meta.xml. 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