Annas Posted August 26, 2015 Posted August 26, 2015 please help , i tried to change onPlayerQuit to a Command Handler .. i wish you understand me.. i have made a vehicle system , but i didnt complete it yet for this reason , when i quit , all currently vehicles spawned destroyed by this function function SaveVehicleDataOnQuit() for i, veh in ipairs (getElementsByType("vehicle")) do if getElementData(veh, "Owner") == source then destroyVehicle(veh) end end end addEventHandler("onPlayerQuit", root,SaveVehicleDataOnQuit) i try to change "addEventHandler("onPlayerQuit", root,SaveVehicleDataOnQuit)" to addcommandhandler, i do it like this: function SaveVehicleDataOnQuit() for i, veh in ipairs (getElementsByType("vehicle")) do if getElementData(veh, "Owner") == source then destroyVehicle(veh) end end end addCommandHandler("hide",SaveVehicleDataOnQuit) but not work with the command handler , please help me
Annas Posted August 26, 2015 Author Posted August 26, 2015 how are you setting the vehice's owner data? what u mean ?, wanna complete Server.lua , script ?
t3wz Posted August 26, 2015 Posted August 26, 2015 In your second code source isn't defined, if you want to destroy the vehicle of the player who typed the command you have to add a parameter to the function (thePlayer for example) which will be the player who typed the command (as described in the wiki) and replace source with the parameter "name" (thePlayer using my example...). function SaveVehicleDataOnQuit( thePlayer ) -- define thePlayer for i, veh in ipairs (getElementsByType("vehicle")) do if getElementData(veh, "Owner") == thePlayer then -- replace source with thePlayer destroyVehicle(veh) end end end addCommandHandler("hide",SaveVehicleDataOnQuit)
Recommended Posts