Jump to content

Help, Marker


Recommended Posts

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!

  • Thanks 1
Link to comment
On 28/05/2022 at 13:01, Tails said:

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!

Thanks a lot for the help :)
I'm still new to programming so people like you help a lot.
  • Like 1
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...