[Help] How to open the trunk of a truck with the action key(E)

Hi,

I am looking for a script on how to open the trunk while standing for it when I press E. I know its possible to add something but I don’t know how.

CurrentActionMsg = ‘Press E to open trunk’ is what I want to display in the top left corner. Can someone help me?

Thanks!

1 Like

You’ll want to create an infinite loop checking if the E key is pressed.

Citizen.CreateThread(function()
    while true do
        if IsControlJustPressed(1, 86) then --INPUT_HORN
            local doorAngle = GetVehicleDoorAngleRatio(vehicle, 5) --check if trunk is open
            if doorAngle == 0 then
                SetVehicleDoorOpen(vehicle, 5, false, false)
            else
                SetVehicleDoorShut(vehicle, 5, false)
            end
        end
    end
end)

As for displaying the help message, I wouldn’t recommend having anything permanently displayed in case it interferes with other scripts and their functionality.

2 Likes

Hi, thanks for your reply!

As for displaying that message. I want it to be displayed when you are standing in front of the back of the car.

Would you recommend this?

1 Like

That sounds like a much better idea. In which case, you would need another infinite loop checking the position of the player’s ped compared to the back of the vehicle and then display the message if they are within a reasonable distance.
Instead of giving you the code, this time I’m going to give you some natives to help.

  1. GetDistanceBetweenCoords
  2. GetEntityCoords

You can look more into these natives here. Good luck :smile:

3 Likes

You can check out my resource, this is cmd based but can easily be converted for keybinds