2026-04-14 17:41:39 +02:00

80 lines
2.3 KiB
Lua

openedManagementMenu = false
function IsJobAllowed(jobName, actionType)
local allowedList = {}
if actionType == "create" then
allowedList = Config.AllowedJobs
elseif actionType == "impound" then
allowedList = Config.ImpoundJobs
end
for _, allowed in ipairs(allowedList) do
if jobName == allowed then
return true
end
end
Debug("Job is not allowed to", actionType, jobName)
return false
end
local function RequireNearbyGarageWithOwnership()
if not ClosestGarage or not Config.Garages[ClosestGarage] then
Notification(i18n.t("management.no_garage_nearby"), "error")
return false
end
if not IsGarageOwner then
Notification(i18n.t("management.no_garage_owner"), "error")
return false
end
return true
end
RegisterCommand("garagemenu", function()
if not RequireNearbyGarageWithOwnership() then return end
openedManagementMenu = true
OpenManagementMenu()
end)
AddEventHandler("advancedgarages:openGiveKeyMenu", function()
if not RequireNearbyGarageWithOwnership() then return end
local nearbyPlayers = {}
local pedCoords = GetEntityCoords(cache.ped)
for _, playerId in pairs(GetPlayers()) do
local playerPed = GetPlayerPed(playerId)
local dist = #(GetEntityCoords(playerPed) - pedCoords)
if dist < 5.5 and cache.ped ~= playerPed then
local playerName = lib.callback.await("advancedgarages:GetPlayerSqlName", false, GetPlayerServerId(playerId))
table.insert(nearbyPlayers, {
id = GetPlayerServerId(playerId),
name = playerName
})
end
end
if #nearbyPlayers > 0 then
openGiveKeyMenu(nearbyPlayers)
else
Notification(i18n.t("management.no_player"), "error")
end
end)
AddEventHandler("advancedgarages:openKeyHoldersMenu", function()
if not RequireNearbyGarageWithOwnership() then return end
openTakeKeyMenu()
end)
RegisterNetEvent("advancedgarages:sellGarage")
AddEventHandler("advancedgarages:sellGarage", function()
TriggerServerEvent("advancedgarages:sellGarage", ClosestGarage)
end)
function SellGarage(garageId)
TriggerServerEvent("advancedgarages:sellGarage", garageId)
Wait(100)
return true
end
exports("SellGarage", SellGarage)