Jump to content

Trailing detaching.


benwilkins

Recommended Posts

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

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
Link to comment

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

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...