Jump to content

Kas7

Recommended Posts

addEventHandler("onTrailerAttach", resourceRoot,
    function ( TruckerVeh1 )
      local driver1 = getVehicleOccupant ( TruckerVeh1 ) 
      if ( driver1 ) then
        if (isElement(TruckerVeh1) and isElement(TruckerTra1)) then
        triggerClientEvent(driver1 , "TrailerAttach", resourceRoot )
        outputChatBox("The load has been attached",driver1)
         end
    end
end
)

addEventHandler("onTrailerDetach", resourceRoot,
    function ( TruckerVeh1)
      local driver1 = getVehicleOccupant ( TruckerVeh1 ) 
      if ( driver1 ) then
        if (isElement(TruckerVeh1) and isElement(TruckerTra1)) then
        triggerClientEvent(driver1 , "TrailerDetach", resourceRoot )
        outputChatBox("The load has been Detach",driver1)
        end
    end
end
)


addEventHandler("onTrailerAttach", resourceRoot,
    function ( TruckerVeh2 )
      local driver2 = getVehicleOccupant ( TruckerVeh2 ) 
      if ( driver2 ) then
        if (isElement(TruckerVeh2) and isElement(TruckerTra2)) then
        triggerClientEvent(driver2 , "TrailerAttach", resourceRoot )
        outputChatBox("The load has been attached",driver2)
        end
    end
end
)


addEventHandler("onTrailerDetach", resourceRoot,
    function ( TruckerVeh2 )
      local driver2 = getVehicleOccupant ( TruckerVeh2 ) 
      if ( driver2 ) then
        if (isElement(TruckerVeh2) and isElement(TruckerTra2)) then
        triggerClientEvent(driver2 , "TrailerDetach", resourceRoot )
        outputChatBox("The load has been Detach",driver2)
        end
    end
end
)

Why when I connect the first trailer to the first truck it shows me in the chat "The load has been attached" twice even though I did a verification condition and so on onTrailerDetach


 

Link to comment

Well you have duplicated functions which do the same thing.
There is no reason to have 2 same functions attached to every event.
This is why you get the messages twice.
The code from line 26 to 49 is pretty much useless as it's a copy of the code above them.

Link to comment

Like SpecT said above, you have 2 functions in your code that do exactly the same as the other 2 functions in your code. I cleaned it up for you:

local function onTrailerAttach(vehicle)
	
	local driver = getVehicleOccupant(vehicle)

	if (driver) then
		triggerClientEvent(driver, "TrailerAttach", resourceRoot)
		outputChatBox("The load has been attached", driver)
	end
end

local function onTrailerDetach(vehicle)

	local driver = getVehicleOccupant(vehicle) 

	if (driver) then
		triggerClientEvent(driver, "TrailerDetach", resourceRoot)
		outputChatBox("The load has been detached", driver)
	end
end

addEventHandler("onTrailerAttach", root, onTrailerAttach)
addEventHandler("onTrailerDetach", root, onTrailerDetach)

 

Edited by Jesseunit
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...