HunT Posted September 20 Share Posted September 20 Hi guys. After a loooooong time I decided to do a rework on one of my map but I need a particular script. I have so forgotten anything related to scripting after 10 years and I don't know if there is any event or function related to this yet. I need help creating a script when a certain vehicle stops touching an object after 5 seconds I have the ability to start a function. Such as destroying the vehicle after 5 seconds if it does not touch an object with its wheels. If anyone helps me I will add credits for the script when I release the map. Thanks for the support Link to comment
Shady1 Posted September 20 Share Posted September 20 37 minutes ago, HunT said: Hi guys. After a loooooong time I decided to do a rework on one of my map but I need a particular script. I have so forgotten anything related to scripting after 10 years and I don't know if there is any event or function related to this yet. I need help creating a script when a certain vehicle stops touching an object after 5 seconds I have the ability to start a function. Such as destroying the vehicle after 5 seconds if it does not touch an object with its wheels. If anyone helps me I will add credits for the script when I release the map. Thanks for the support local vehicleTouchData = {} function onVehicleTouch(hitElement, matchingDimension) if getElementType(hitElement) == "vehicle" then local vehicle = hitElement vehicleTouchData[vehicle] = true if isTimer(vehicleTouchData[vehicle.."timer"]) then killTimer(vehicleTouchData[vehicle.."timer"]) vehicleTouchData[vehicle.."timer"] = nil outputChatBox("Vehicle touched the object again, timer canceled.") end end end addEventHandler("onElementCollide", root, onVehicleTouch) function onVehicleLeave(leftElement, matchingDimension) if getElementType(leftElement) == "vehicle" then local vehicle = leftElement vehicleTouchData[vehicle] = false vehicleTouchData[vehicle.."timer"] = setTimer(function() if not vehicleTouchData[vehicle] then if isElement(vehicle) then destroyElement(vehicle) outputChatBox("Vehicle did not touch for 5 seconds, destroyed.") end end end, 5000, 1) end end addEventHandler("onElementLeaveCollide", root, onVehicleLeave) function onVehicleDestroy() vehicleTouchData[source] = nil if isTimer(vehicleTouchData[source.."timer"]) then killTimer(vehicleTouchData[source.."timer"]) end end addEventHandler("onElementDestroy", root, onVehicleDestroy) Link to comment
HunT Posted September 21 Author Share Posted September 21 18 hours ago, Shady1 said: local vehicleTouchData = {} function onVehicleTouch(hitElement, matchingDimension) if getElementType(hitElement) == "vehicle" then local vehicle = hitElement vehicleTouchData[vehicle] = true if isTimer(vehicleTouchData[vehicle.."timer"]) then killTimer(vehicleTouchData[vehicle.."timer"]) vehicleTouchData[vehicle.."timer"] = nil outputChatBox("Vehicle touched the object again, timer canceled.") end end end addEventHandler("onElementCollide", root, onVehicleTouch) function onVehicleLeave(leftElement, matchingDimension) if getElementType(leftElement) == "vehicle" then local vehicle = leftElement vehicleTouchData[vehicle] = false vehicleTouchData[vehicle.."timer"] = setTimer(function() if not vehicleTouchData[vehicle] then if isElement(vehicle) then destroyElement(vehicle) outputChatBox("Vehicle did not touch for 5 seconds, destroyed.") end end end, 5000, 1) end end addEventHandler("onElementLeaveCollide", root, onVehicleLeave) function onVehicleDestroy() vehicleTouchData[source] = nil if isTimer(vehicleTouchData[source.."timer"]) then killTimer(vehicleTouchData[source.."timer"]) end end addEventHandler("onElementDestroy", root, onVehicleDestroy) A thousand thanks. I will try this script Link to comment
Shady1 Posted September 21 Share Posted September 21 2 hours ago, HunT said: A thousand thanks. I will try this script I have not tested it, so please get back to me if there is anything missing or needs to be edited and I will help you Link to comment
Dzsozi (h03) Posted October 27 Share Posted October 27 there are no such events as onElementCollide onElementLeaveCollide https://wiki.multitheftauto.com/wiki/Client_Scripting_Events#Element_events https://wiki.multitheftauto.com/wiki/Server_Scripting_Events#Element_events I think the best thing you could do for this case is either a distance check, or creating collision shapes alongside the objects you need the check against. You maybe could achieve more precise results with a distance check logic, since you could get the position of a vehicle dummy or ped bone and many more, but you'd need to do it in a render event, or an event that is not as heavy as a render, but still constantly called, like onClientPedsProcessed. 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