[REQ] Open Trunk script

I was wondering if it would be possible for someone to make a script that uses chat command to open the trunk.

ie: /trunk opens trunk

1 Like

Client:

RegisterNetEvent("Trunk")
AddEventHandler("Trunk", function()
	local Veh = GetVehiclePedIsUsing(GetPlayerPed(-1))
	SetVehicleDoorOpen(Veh, 5, false, false)
end)

RegisterNetEvent("TrunkClose")
AddEventHandler("TrunkClose", function()
	local Veh = GetVehiclePedIsUsing(GetPlayerPed(-1))
	SetVehicleDoorShut(Veh, 5, false)
end)

Server:

AddEventHandler('chatMessage', function(player, playerName, message)
	local message = string.lower(message)
	local args = stringsplit(message, " ");
	if message == "/trunk" then
	elseif args[2] == 'open' then
		TriggerClientEvent('Trunk', player)
		CancelEvent()
	elseif args[2] == 'close' then
		TriggerClientEvent('TrunkClose', player)
		CancelEvent()
	end
end)

function stringsplit(self, delimiter)
	local a = self:Split(delimiter)
	local t = {}
	
	for i = 0, #a - 1 do
		table.insert(t, a[i])
	end
	
	return t
end

type /trunk open/close

2 Likes

It opens but doesn’t close.

1 Like

To be fair, he asked only to open the trunk, and I delivered.
Updated original post with a workaround.
IsVehicleDoorFullyOpen(vehicle, doorIndex) does not seem to work properly, it catches if the door is not open, but can’t close it if it is…

1 Like

Hey im getting a error when im trying to do /trunk can you help me?

how to open the trunk of someone else when I work as policeman what I mean for example I am cop and I want to open the inventory in another trunk without his permission