Jump to content

Trailing detaching.


benwilkins

Recommended Posts

Posted

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.

Posted

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.

Posted (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 by Guest
Posted (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 by Guest
Posted

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) 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...