benwilkins Posted December 21, 2011 Posted December 21, 2011 I have this function working fine: function detachVehicle(thePlayer) if isPedInVehicle(thePlayer) and getPedOccupiedVehicleSeat(thePlayer) == 0 then local veh = getPedOccupiedVehicle(thePlayer) if getVehicleTowedByVehicle(veh) then detachTrailerFromVehicle(veh) outputChatBox("The trailer was detached.", thePlayer, 0, 255, 0) else outputChatBox("There is no trailer...", thePlayer, 255, 0, 0) end end end addCommandHandler("detach", detachVehicle, false, false) The only problem is when the command detach is given, it will detach fine, but will reatch almost instantly. So I need a way to stop the trailing from attaching for 2/3 seconds.
Charlie_Jefferson Posted December 21, 2011 Posted December 21, 2011 Use the setTimer function to disable the command for 2 seconds.
benwilkins Posted December 21, 2011 Author Posted December 21, 2011 Its not the command, its nothing to do with the detach function, that works fine, I need a way to stop it from reataching, once the detach function has been completed, it will just assume your vehicle is there to attach again.
Carlossg Posted December 21, 2011 Posted December 21, 2011 (edited) I'm not sure ,but try whit this: function detachVehicle(thePlayer) if isPedInVehicle(thePlayer) and getPedOccupiedVehicleSeat(thePlayer) == 0 then local veh = getPedOccupiedVehicle(thePlayer) if getVehicleTowedByVehicle(veh) then setTimer ( detachTrailerFromVehicle(veh), 2000, 1 ) outputChatBox("The trailer was detached.", thePlayer, 0, 255, 0) else outputChatBox("There is no trailer...", thePlayer, 255, 0, 0) end end end addCommandHandler("detach", detachVehicle, false, false) Edited December 21, 2011 by Guest
Charlie_Jefferson Posted December 21, 2011 Posted December 21, 2011 (edited) Then set the element data to deattached and when the /attach thing is done, check if the element data(for the player) is the one with deattach. If it is, then cancelFunction, or somethin'. Edited December 21, 2011 by Guest
Castillo Posted December 21, 2011 Posted December 21, 2011 Try this: local skip = {} function detachVehicle(thePlayer) if isPedInVehicle(thePlayer) and getPedOccupiedVehicleSeat(thePlayer) == 0 then local veh = getPedOccupiedVehicle(thePlayer) if getVehicleTowedByVehicle(veh) then detachTrailerFromVehicle(veh) outputChatBox("The trailer was detached.", thePlayer, 0, 255, 0) skip[veh] = true setTimer(function (veh) skip[veh] = nil end, 3000, 1, veh) else outputChatBox("There is no trailer...", thePlayer, 255, 0, 0) end end end addCommandHandler("detach", detachVehicle, false, false) addEventHandler("onTrailerAttach", root, function (theTruck) if skip[theTruck] then cancelEvent() end end)
benwilkins Posted December 21, 2011 Author Posted December 21, 2011 Thanks Snake. It worked perfect the first time, but then hooked it up again, and now it wont detach at all, but still says It was detached in chatbox.
myonlake Posted December 22, 2011 Posted December 22, 2011 Just set the trailer's position like X+1 or such.
Buffalo Posted December 22, 2011 Posted December 22, 2011 It used to work for me by just simply binding a key to that function and it would stay detached until key is pressed.
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