179 lines
5.4 KiB
Lua
179 lines
5.4 KiB
Lua
if Config.Framework ~= 'esx' then
|
|
return
|
|
end
|
|
|
|
ESX = exports['es_extended']:getSharedObject()
|
|
|
|
userTable = 'users'
|
|
identifierColumn = 'identifier'
|
|
garageTable = 'owned_vehicles'
|
|
garageIdentifierColumn = 'owner'
|
|
garagePropsColumn = 'vehicle'
|
|
storedColumn = 'stored'
|
|
|
|
Query = {
|
|
SELECT_PLAYER_VEHICLES = [[
|
|
SELECT id, owner, tag, plate, vehicle, type, garage, impound_data, favorite, stored, jobVehicle, jobGarage FROM owned_vehicles WHERE garage = ? AND owner = ?
|
|
]]
|
|
}
|
|
|
|
RegisterNetEvent('esx:playerLoaded')
|
|
AddEventHandler('esx:playerLoaded', function(id)
|
|
UpdatePlayerCache(id)
|
|
CreateQuests(id)
|
|
end)
|
|
|
|
CreateThread(function()
|
|
for k, v in pairs(ESX.Players) do
|
|
if v and v.source then
|
|
Debug('Loaded player:', v.source)
|
|
CreateQuests(v.source)
|
|
end
|
|
end
|
|
end)
|
|
|
|
function InitInsideShellGarage(source)
|
|
local xPlayer = GetPlayerFromId(source)
|
|
if not xPlayer then return end
|
|
local str = [[
|
|
SELECT shell_garage FROM users WHERE identifier = ?
|
|
]]
|
|
local result = MySQL.Sync.fetchAll(str, { xPlayer.identifier })
|
|
if not result[1] or not result[1].shell_garage then return end
|
|
local data = json.decode(result[1].shell_garage)
|
|
if not data then return end
|
|
TriggerClientEvent('advancedgarages:enterShellGarage', source, data.garage, data.defaultCoords, data.customGarageId)
|
|
end
|
|
|
|
RegisterNetEvent('esx:playerLoaded')
|
|
AddEventHandler('esx:playerLoaded', function(id, xPlayer)
|
|
TriggerClientEvent('advancedgarages:SetShellData', id, shellPlayers)
|
|
InitInsideShellGarage(id)
|
|
end)
|
|
|
|
function RegisterServerCallback(name, cb)
|
|
ESX.RegisterServerCallback(name, cb)
|
|
end
|
|
|
|
function RegisterUsableItem(name, cb)
|
|
ESX.RegisterUsableItem(name, cb)
|
|
end
|
|
|
|
function GetPlayerFromId(source)
|
|
return ESX.GetPlayerFromId(source)
|
|
end
|
|
|
|
function GetPlayerFromIdentifier(identifier)
|
|
return ESX.GetPlayerFromIdentifier(identifier)
|
|
end
|
|
|
|
function GetPlayerIdentifier(source)
|
|
if source == 0 then return "console" end
|
|
local player = GetPlayerFromId(source)
|
|
return player and player.identifier
|
|
end
|
|
|
|
function GetJobName(source)
|
|
local player = GetPlayerFromId(source)
|
|
if not player then return "unemployed" end
|
|
return player.getJob().name
|
|
end
|
|
|
|
function GetJobGrade(source)
|
|
local player = GetPlayerFromId(source)
|
|
if not player then return 0 end
|
|
return player.getJob().grade or 0
|
|
end
|
|
|
|
function GetJobsData()
|
|
local jobs = ESX.GetJobs()
|
|
local data = {}
|
|
for k, v in pairs(jobs) do
|
|
data[#data + 1] = {
|
|
name = v.name,
|
|
label = v.label,
|
|
grades = table.map(v.grades, function(grade)
|
|
return {
|
|
id = grade.id,
|
|
name = grade.name,
|
|
label = grade.label,
|
|
grade = grade.grade
|
|
}
|
|
end)
|
|
}
|
|
end
|
|
return data
|
|
end
|
|
|
|
function GetPlayerSource(player)
|
|
return player?.source
|
|
end
|
|
|
|
function GetAccountMoney(source, account)
|
|
local player = GetPlayerFromId(source)
|
|
if not player then return 0 end
|
|
return player.getAccount(account).money
|
|
end
|
|
|
|
function RemoveAccountMoney(source, account, amount)
|
|
if amount <= 0 then
|
|
return true
|
|
end
|
|
local player = GetPlayerFromId(source)
|
|
player.removeAccountMoney(account, amount)
|
|
return true
|
|
end
|
|
|
|
function AddAccountMoney(source, account, amount)
|
|
local player = GetPlayerFromId(source)
|
|
player.addAccountMoney(account, amount)
|
|
end
|
|
|
|
function RemoveItem(source, item, count)
|
|
local player = GetPlayerFromId(source)
|
|
player.removeInventoryItem(item, count)
|
|
end
|
|
|
|
function PlayerIsAdmin(source)
|
|
if source == 0 then return true end
|
|
local player = GetPlayerFromId(source)
|
|
if not player then return false end
|
|
|
|
-- On essaie les deux méthodes de récupération de groupe selon la version ESX
|
|
local group = (type(player.getGroup) == 'function') and player.getGroup() or player.group
|
|
|
|
print("[GARAGES] Debug Final: Groupe detecte = " .. tostring(group))
|
|
return group == "admin" or group == "superadmin" or group == "owner"
|
|
end
|
|
|
|
RegisterServerEvent('advancedgarages:server:setVehicle')
|
|
AddEventHandler('advancedgarages:server:setVehicle', function(vehicleProps, model, playerID, vehicleType, addcommand)
|
|
local src = source
|
|
local Player = GetPlayerFromId(src)
|
|
local plate = vehicleProps.plate
|
|
local garage
|
|
if Player ~= nil then
|
|
if addcommand then
|
|
garage = 'OUT'
|
|
else
|
|
garage = GetImpoundOfType(vehicleType, vehicleProps.coords)
|
|
if not garage then
|
|
Notification(src, i18n.t('missing_type', { type = vehicleType }), 'error')
|
|
return
|
|
end
|
|
end
|
|
|
|
MySQL.Async.execute('INSERT INTO ' .. garageTable .. ' (' .. garageIdentifierColumn .. ', plate, ' .. garagePropsColumn .. ', garage, type) VALUES (?, ?, ?, ?, ?)', {
|
|
GetPlayerIdentifier(playerID),
|
|
plate,
|
|
json.encode(vehicleProps),
|
|
garage,
|
|
vehicleType
|
|
}, function(rowsAffected)
|
|
if rowsAffected > 0 then
|
|
Notification(playerID, i18n.t('give_vehicle.give_info', { model = model, plate = plate, player = GetPlayerName(playerID) }), 'success')
|
|
end
|
|
end)
|
|
end
|
|
end)
|