-- client/main.lua local isMenuOpen = false function ToggleMenu(status) isMenuOpen = status SetNuiFocus(status, status) SendNUIMessage({ type = "ui", status = status }) end RegisterCommand(Config.CommandName, function() local ped = PlayerPedId() local vehicle = GetVehiclePedIsIn(ped, false) if vehicle ~= 0 then ToggleMenu(true) PlaySoundFrontend(-1, "NAV_LEFT_RIGHT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1) else lib.notify({ title = Config.Notifications.no_vehicle.title, description = Config.Notifications.no_vehicle.description, type = Config.Notifications.no_vehicle.type }) end end) RegisterNUICallback("close", function(data, cb) ToggleMenu(false) PlaySoundFrontend(-1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1) cb('ok') end) RegisterNUICallback("triggerAction", function(data, cb) local playerPed = PlayerPedId() local vehicle = GetVehiclePedIsIn(playerPed, false) if not vehicle or vehicle == 0 then cb('ok') return end PlaySoundFrontend(-1, "OK", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1) if data.action == "engine" then local status = GetIsVehicleEngineRunning(vehicle) SetVehicleEngineOn(vehicle, not status, false, true) elseif data.action == "lights" then local _, lights, highbeams = GetVehicleLightsState(vehicle) SetVehicleLights(vehicle, (lights == 1 or highbeams == 1) and 1 or 3) elseif data.action:match("door_") then local doorId = tonumber(data.action:split("_")[2]) if GetVehicleDoorAngleRatio(vehicle, doorId) > 0.0 then SetVehicleDoorShut(vehicle, doorId, false) else SetVehicleDoorOpen(vehicle, doorId, false, false) end elseif data.action == "hood" then if GetVehicleDoorAngleRatio(vehicle, 4) > 0.0 then SetVehicleDoorShut(vehicle, 4, false) else SetVehicleDoorOpen(vehicle, 4, false, false) end elseif data.action == "trunk" then if GetVehicleDoorAngleRatio(vehicle, 5) > 0.0 then SetVehicleDoorShut(vehicle, 5, false) else SetVehicleDoorOpen(vehicle, 5, false, false) end elseif data.action == "doors_all" then local open = GetVehicleDoorAngleRatio(vehicle, 0) > 0.0 for i = 0, 5 do if open then SetVehicleDoorShut(vehicle, i, false) else SetVehicleDoorOpen(vehicle, i, false, false) end end elseif data.action:match("window_") then local windowId = tonumber(data.action:split("_")[2]) if IsVehicleWindowIntact(vehicle, windowId) then RollDownWindow(vehicle, windowId) else RollUpWindow(vehicle, windowId) end elseif data.action:match("seat_") then local seatIndex = tonumber(data.action:split("_")[2]) if IsVehicleSeatFree(vehicle, seatIndex) then SetPedIntoVehicle(playerPed, vehicle, seatIndex) else lib.notify({ title = Config.Notifications.seat_occupied.title, description = Config.Notifications.seat_occupied.description, type = Config.Notifications.seat_occupied.type }) end end cb('ok') end) function string:split(sep) local sep, fields = sep or ":", {} local pattern = string.format("([^%s]+)", sep) self:gsub(pattern, function(c) fields[#fields+1] = c end) return fields end function OpenVehicleMenu() local playerPed = PlayerPedId() local veh = GetVehiclePedIsIn(playerPed, false) if veh ~= 0 then local status = { engine = GetIsVehicleEngineRunning(veh), lights = (function() local _, lights, highbeams = GetVehicleLightsState(veh) return (lights == 1 or highbeams == 1) end)(), doors = { [0] = GetVehicleDoorAngleRatio(veh, 0) > 0.1, [1] = GetVehicleDoorAngleRatio(veh, 1) > 0.1, [2] = GetVehicleDoorAngleRatio(veh, 2) > 0.1, [3] = GetVehicleDoorAngleRatio(veh, 3) > 0.1, [4] = GetVehicleDoorAngleRatio(veh, 4) > 0.1, [5] = GetVehicleDoorAngleRatio(veh, 5) > 0.1, }, windows = { [0] = not IsVehicleWindowIntact(veh, 0), [1] = not IsVehicleWindowIntact(veh, 1), [2] = not IsVehicleWindowIntact(veh, 2), [3] = not IsVehicleWindowIntact(veh, 3), } } SetNuiFocus(true, true) SendNUIMessage({ type = "ui", status = true, vehicleStatus = status }) end end RegisterCommand('vmenu', function() OpenVehicleMenu() end)