benwilkins Posted December 21, 2011 Share 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. Link to comment
Charlie_Jefferson Posted December 21, 2011 Share Posted December 21, 2011 Use the setTimer function to disable the command for 2 seconds. Link to comment
benwilkins Posted December 21, 2011 Author Share 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. Link to comment
Carlossg Posted December 21, 2011 Share 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 Link to comment
Charlie_Jefferson Posted December 21, 2011 Share 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 Link to comment
Castillo Posted December 21, 2011 Share 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) Link to comment
benwilkins Posted December 21, 2011 Author Share 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. Link to comment
myonlake Posted December 22, 2011 Share Posted December 22, 2011 Just set the trailer's position like X+1 or such. Link to comment
Buffalo Posted December 22, 2011 Share 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. 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