You can use getVehicleTowedByVehicle to get the trailer attached to a truck.
https://wiki.multitheftauto.com/wiki/GetVehicleTowedByVehicle
First create your marker (serverside)
local myMarker = createMarker(0, 0, 0, 'cylinder', 1, 255, 0, 0, 150)
setElementID(myMarker, 'myMarker')
Listen for hit event and check for petrol trailer for example (serverside)
addEventHandler('onMarkerHit', myMarker, function(hitElement)
if getElementType(hitElement) == 'vehicle' then
local driver = getVehicleOccupant(hitElement)
if driver then
local trailer = getVehicleTowedByVehicle(hitElement)
if trailer and getElementModel(trailer) == 584 then
outputChatBox('You have a petrol trailer', driver, 0, 255, 0)
else
outputChatBox('You do not have a petrol trailer.', driver, 255, 0, 0)
end
end
end
end)
Or listen for key press while inside the marker (clientside)
addEventHandler('onClientKey', root, function(key, p)
if key == 'e' and p then
local vehicle = getElementVehicle(localPlayer)
local myMarker = getElementByID('myMarker')
if vehicle and isElementWithinColShape(vehicle, getElementColShape(myMarker)) then
local trailer = getVehicleTowedByVehicle(vehicle)
if trailer and getElementModel(trailer) == 584 then
outputChatBox('You have a petrol trailer.', 0, 255, 0)
else
outputChatBox('You do not have a petrol trailer.', 255, 0, 0)
end
end
end
end)
Hope this helps!