Jump to content

[HELP] Trailer problems


..:D&G:..

Recommended Posts

Hey guys, I made a tanker job and I made it create/attach a trailer on your tanker, and then destroy it when the player exits the vehicle, the trailer will be destroyed. The problem is that the trailer is not destroyed when the player gets out the vehicle, and sometimes there are trailer spawning next to the driver randomly and even when the player is not in a vehicle!

Server -

local tirpetrol = { [514]=true} 
function giveCisterna() 
    local vehicle = getPedOccupiedVehicle(client) 
    local x, y, z =  getElementPosition(vehicle) 
    local rotX, rotY, rotZ = getElementRotation(vehicle) 
    if vehicle and getVehicleController(vehicle) == client and tirpetrol[getElementModel(vehicle)] then 
        trailer = createVehicle ( 584, x+4, y+1, z, rotX, rotY, rotZ ) 
        attachTrailerToVehicle ( vehicle, trailer )  
    else 
    if isElement(trailer) then 
        return end 
    end 
end 
addEvent("spawnCisterna", true) 
addEventHandler("spawnCisterna", getRootElement(), giveCisterna) 
  
addEventHandler("onVehicleExit", getRootElement(), 
    function(thePlayer, seat) 
        local vehicle = getPedOccupiedVehicle(client) 
        if thePlayer == client and tirpetrol[getElementModel(vehicle)] then 
            destroyElement(trailer) 
        end 
    end 
) 

This is triggered from the client side bit

function giveCisterna() 
    local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
    if vehicle and tirpetrol[getElementModel(vehicle)] then 
        triggerServerEvent ( "spawnCisterna", resourceRoot ) 
    end 
end 

addEventHandler("onClientMarkerHit",tirpetrolMarker, giveCisterna) 

Link to comment

client

function giveCisterna() 
    local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
    if vehicle and tirpetrol[getElementModel(vehicle)] then 
        triggerServerEvent ( "spawnCisterna", resourceRoot ) 
    end 
end 

server

local tirpetrol = { [514]=true} 
  
function giveCisterna() 
    local vehicle = getPedOccupiedVehicle(client) 
    local x, y, z =  getElementPosition(vehicle) 
    local rotX, rotY, rotZ = getElementRotation(vehicle) 
    if vehicle and getVehicleController(vehicle) == client and tirpetrol[getElementModel(vehicle)] then 
        trailer = createVehicle ( 584, x+4, y+1, z, rotX, rotY, rotZ ) 
        attachTrailerToVehicle ( vehicle, trailer ) 
    else 
    if isElement(trailer) then 
        return end 
    end 
end 
addEvent("spawnCisterna", true) 
addEventHandler("spawnCisterna", getRootElement(), giveCisterna) 
  
addEventHandler("onVehicleExit", getRootElement(), 
    function() 
         if isElement(trailer) then 
            destroyElement(trailer) 
            outputChatBox("was created", source) 
            else  
        return 
        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...