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

74 lines
2.3 KiB
Lua

local shellPlayers = {}
local function FindPlayerIndexInShell(garageId, playerId)
local shellList = shellPlayers[garageId]
if not shellList then return false end
for idx, playerSource in pairs(shellList) do
if playerSource == playerId then
return idx
end
end
return false
end
function LeavelShellGarage(garageId)
local playerSource = source
local playerIndex = FindPlayerIndexInShell(garageId, playerSource)
if not playerIndex then return end
shellPlayers[garageId][playerIndex] = nil
TriggerClientEvent("advancedgarages:SetShellData", -1, shellPlayers)
end
RegisterNetEvent("advancedgarages:enterShellgarage")
AddEventHandler("advancedgarages:enterShellgarage", function(garageId, defaultCoords, customGarageId)
local playerSource = source
if not shellPlayers[garageId] then
shellPlayers[garageId] = {}
end
table.insert(shellPlayers[garageId], playerSource)
TriggerClientEvent("advancedgarages:SetShellData", -1, shellPlayers)
local shellData = {
defaultCoords = defaultCoords,
garage = garageId,
customGarageId = customGarageId
}
local identifier = GetPlayerIdentifier(playerSource)
MySQL.Sync.execute(
string.format("UPDATE %s SET shell_garage = ? WHERE %s = ?", userTable, identifierColumn),
{ json.encode(shellData), identifier }
)
local qsInventoryState = GetResourceState("qs-inventory")
if qsInventoryState and qsInventoryState:find("started") then
exports["qs-inventory"]:UpdateQuestProgress(playerSource, "enter_garage_interior", 100)
end
end)
RegisterNetEvent("advancedgarages:leaveShellgarage", LeavelShellGarage)
AddEventHandler("playerDropped", function(reason)
local playerSource = source
if not next(shellPlayers) then return end
for garageId, playerList in pairs(shellPlayers) do
for idx, playerSourceInShell in pairs(playerList) do
if playerSourceInShell == playerSource then
shellPlayers[garageId][idx] = nil
end
end
end
TriggerClientEvent("advancedgarages:SetShellData", -1, shellPlayers)
end)
lib.callback.register("advancedgarages:playerIsRealeState", function(sourcePlayer)
local jobName = GetJobName(sourcePlayer)
return IsJobAllowed(jobName, "create")
end)