mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 16:23:21 +00:00
+213
-184
@@ -121,220 +121,249 @@ if not Config.Multichar then
|
|||||||
end
|
end
|
||||||
|
|
||||||
function loadESXPlayer(identifier, playerId, isNew)
|
function loadESXPlayer(identifier, playerId, isNew)
|
||||||
local userData = {accounts = {}, inventory = {}, job = {}, loadout = {}, playerName = GetPlayerName(playerId), weight = 0, metadata = {}}
|
local userData = {
|
||||||
local result = MySQL.prepare.await(loadPlayer, {identifier})
|
accounts = {},
|
||||||
local job, grade, jobObject, gradeObject = result.job, tostring(result.job_grade)
|
inventory = {},
|
||||||
local foundAccounts, foundItems = {}, {}
|
job = {},
|
||||||
|
loadout = {},
|
||||||
|
playerName = GetPlayerName(playerId),
|
||||||
|
weight = 0,
|
||||||
|
metadata = {}
|
||||||
|
}
|
||||||
|
local result = MySQL.prepare.await(loadPlayer, { identifier })
|
||||||
|
local job, grade, jobObject, gradeObject = result.job, tostring(result.job_grade)
|
||||||
|
local foundAccounts, foundItems = {}, {}
|
||||||
|
|
||||||
-- Accounts
|
-- Accounts
|
||||||
if result.accounts and result.accounts ~= '' then
|
if result.accounts and result.accounts ~= '' then
|
||||||
local accounts = json.decode(result.accounts)
|
local accounts = json.decode(result.accounts)
|
||||||
|
|
||||||
for account, money in pairs(accounts) do
|
for account, money in pairs(accounts) do
|
||||||
foundAccounts[account] = money
|
foundAccounts[account] = money
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for account, data in pairs(Config.Accounts) do
|
for account, data in pairs(Config.Accounts) do
|
||||||
if data.round == nil then
|
if data.round == nil then
|
||||||
data.round = true
|
data.round = true
|
||||||
end
|
end
|
||||||
local index = #userData.accounts + 1
|
local index = #userData.accounts + 1
|
||||||
userData.accounts[index] = {
|
userData.accounts[index] = {
|
||||||
name = account,
|
name = account,
|
||||||
money = foundAccounts[account] or Config.StartingAccountMoney[account] or 0,
|
money = foundAccounts[account] or Config.StartingAccountMoney[account] or 0,
|
||||||
label = data.label,
|
label = data.label,
|
||||||
round = data.round,
|
round = data.round,
|
||||||
index = index
|
index = index
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Job
|
-- Job
|
||||||
if ESX.DoesJobExist(job, grade) then
|
if ESX.DoesJobExist(job, grade) then
|
||||||
jobObject, gradeObject = ESX.Jobs[job], ESX.Jobs[job].grades[grade]
|
jobObject, gradeObject = ESX.Jobs[job], ESX.Jobs[job].grades[grade]
|
||||||
else
|
else
|
||||||
print(('[^3WARNING^7] Ignoring invalid job for ^5%s^7 [job: ^5%s^7, grade: ^5%s^7]'):format(identifier, job, grade))
|
print(('[^3WARNING^7] Ignoring invalid job for ^5%s^7 [job: ^5%s^7, grade: ^5%s^7]'):format(identifier, job, grade))
|
||||||
job, grade = 'unemployed', '0'
|
job, grade = 'unemployed', '0'
|
||||||
jobObject, gradeObject = ESX.Jobs[job], ESX.Jobs[job].grades[grade]
|
jobObject, gradeObject = ESX.Jobs[job], ESX.Jobs[job].grades[grade]
|
||||||
end
|
end
|
||||||
|
|
||||||
userData.job.id = jobObject.id
|
userData.job.id = jobObject.id
|
||||||
userData.job.name = jobObject.name
|
userData.job.name = jobObject.name
|
||||||
userData.job.label = jobObject.label
|
userData.job.label = jobObject.label
|
||||||
|
|
||||||
userData.job.grade = tonumber(grade)
|
userData.job.grade = tonumber(grade)
|
||||||
userData.job.grade_name = gradeObject.name
|
userData.job.grade_name = gradeObject.name
|
||||||
userData.job.grade_label = gradeObject.label
|
userData.job.grade_label = gradeObject.label
|
||||||
userData.job.grade_salary = gradeObject.salary
|
userData.job.grade_salary = gradeObject.salary
|
||||||
|
|
||||||
userData.job.skin_male = {}
|
userData.job.skin_male = {}
|
||||||
userData.job.skin_female = {}
|
userData.job.skin_female = {}
|
||||||
|
|
||||||
if gradeObject.skin_male then
|
if gradeObject.skin_male then
|
||||||
userData.job.skin_male = json.decode(gradeObject.skin_male)
|
userData.job.skin_male = json.decode(gradeObject.skin_male)
|
||||||
end
|
end
|
||||||
if gradeObject.skin_female then
|
if gradeObject.skin_female then
|
||||||
userData.job.skin_female = json.decode(gradeObject.skin_female)
|
userData.job.skin_female = json.decode(gradeObject.skin_female)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Inventory
|
-- Inventory
|
||||||
if not Config.OxInventory then
|
if not Config.OxInventory then
|
||||||
if result.inventory and result.inventory ~= '' then
|
if result.inventory and result.inventory ~= '' then
|
||||||
local inventory = json.decode(result.inventory)
|
local inventory = json.decode(result.inventory)
|
||||||
|
|
||||||
for name, count in pairs(inventory) do
|
for name, count in pairs(inventory) do
|
||||||
local item = ESX.Items[name]
|
local item = ESX.Items[name]
|
||||||
|
|
||||||
if item then
|
if item then
|
||||||
foundItems[name] = count
|
foundItems[name] = count
|
||||||
else
|
else
|
||||||
print(('[^3WARNING^7] Ignoring invalid item ^5"%s"^7 for ^5"%s^7"'):format(name, identifier))
|
print(('[^3WARNING^7] Ignoring invalid item ^5"%s"^7 for ^5"%s^7"'):format(name, identifier))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for name, item in pairs(ESX.Items) do
|
for name, item in pairs(ESX.Items) do
|
||||||
local count = foundItems[name] or 0
|
local count = foundItems[name] or 0
|
||||||
if count > 0 then
|
if count > 0 then
|
||||||
userData.weight = userData.weight + (item.weight * count)
|
userData.weight = userData.weight + (item.weight * count)
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(userData.inventory,
|
table.insert(userData.inventory,
|
||||||
{name = name, count = count, label = item.label, weight = item.weight, usable = Core.UsableItemsCallbacks[name] ~= nil, rare = item.rare,
|
{
|
||||||
canRemove = item.canRemove})
|
name = name,
|
||||||
end
|
count = count,
|
||||||
|
label = item.label,
|
||||||
|
weight = item.weight,
|
||||||
|
usable = Core.UsableItemsCallbacks[name] ~= nil,
|
||||||
|
rare = item.rare,
|
||||||
|
canRemove = item.canRemove
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
table.sort(userData.inventory, function(a, b)
|
table.sort(userData.inventory, function(a, b)
|
||||||
return a.label < b.label
|
return a.label < b.label
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
if result.inventory and result.inventory ~= '' then
|
if result.inventory and result.inventory ~= '' then
|
||||||
userData.inventory = json.decode(result.inventory)
|
userData.inventory = json.decode(result.inventory)
|
||||||
else
|
else
|
||||||
userData.inventory = {}
|
userData.inventory = {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Group
|
-- Group
|
||||||
if result.group then
|
if result.group then
|
||||||
if result.group == "superadmin" then
|
if result.group == "superadmin" then
|
||||||
userData.group = "admin"
|
userData.group = "admin"
|
||||||
print("[^3WARNING^7] ^5Superadmin^7 detected, setting group to ^5admin^7")
|
print("[^3WARNING^7] ^5Superadmin^7 detected, setting group to ^5admin^7")
|
||||||
else
|
else
|
||||||
userData.group = result.group
|
userData.group = result.group
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
userData.group = 'user'
|
userData.group = 'user'
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Loadout
|
-- Loadout
|
||||||
if not Config.OxInventory then
|
if not Config.OxInventory then
|
||||||
if result.loadout and result.loadout ~= '' then
|
if result.loadout and result.loadout ~= '' then
|
||||||
local loadout = json.decode(result.loadout)
|
local loadout = json.decode(result.loadout)
|
||||||
|
|
||||||
for name, weapon in pairs(loadout) do
|
for name, weapon in pairs(loadout) do
|
||||||
local label = ESX.GetWeaponLabel(name)
|
local label = ESX.GetWeaponLabel(name)
|
||||||
|
|
||||||
if label then
|
if label then
|
||||||
if not weapon.components then
|
if not weapon.components then
|
||||||
weapon.components = {}
|
weapon.components = {}
|
||||||
end
|
end
|
||||||
if not weapon.tintIndex then
|
if not weapon.tintIndex then
|
||||||
weapon.tintIndex = 0
|
weapon.tintIndex = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(userData.loadout,
|
table.insert(userData.loadout,
|
||||||
{name = name, ammo = weapon.ammo, label = label, components = weapon.components, tintIndex = weapon.tintIndex})
|
{
|
||||||
end
|
name = name,
|
||||||
end
|
ammo = weapon.ammo,
|
||||||
end
|
label = label,
|
||||||
end
|
components = weapon.components,
|
||||||
|
tintIndex = weapon.tintIndex
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Position
|
-- Position
|
||||||
userData.coords = json.decode(result.position) or Config.DefaultSpawns[math.random(#Config.DefaultSpawns)]
|
userData.coords = json.decode(result.position) or Config.DefaultSpawns[math.random(#Config.DefaultSpawns)]
|
||||||
|
|
||||||
-- Skin
|
-- Skin
|
||||||
if result.skin and result.skin ~= '' then
|
if result.skin and result.skin ~= '' then
|
||||||
userData.skin = json.decode(result.skin)
|
userData.skin = json.decode(result.skin)
|
||||||
else
|
else
|
||||||
if userData.sex == 'f' then
|
if userData.sex == 'f' then
|
||||||
userData.skin = {sex = 1}
|
userData.skin = { sex = 1 }
|
||||||
else
|
else
|
||||||
userData.skin = {sex = 0}
|
userData.skin = { sex = 0 }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Identity
|
-- Identity
|
||||||
if result.firstname and result.firstname ~= '' then
|
if result.firstname and result.firstname ~= '' then
|
||||||
userData.firstname = result.firstname
|
userData.firstname = result.firstname
|
||||||
userData.lastname = result.lastname
|
userData.lastname = result.lastname
|
||||||
userData.playerName = userData.firstname .. ' ' .. userData.lastname
|
userData.playerName = userData.firstname .. ' ' .. userData.lastname
|
||||||
if result.dateofbirth then
|
if result.dateofbirth then
|
||||||
userData.dateofbirth = result.dateofbirth
|
userData.dateofbirth = result.dateofbirth
|
||||||
end
|
end
|
||||||
if result.sex then
|
if result.sex then
|
||||||
userData.sex = result.sex
|
userData.sex = result.sex
|
||||||
end
|
end
|
||||||
if result.height then
|
if result.height then
|
||||||
userData.height = result.height
|
userData.height = result.height
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if result.metadata and result.metadata ~= '' then
|
if result.metadata and result.metadata ~= '' then
|
||||||
local metadata = json.decode(result.metadata)
|
local metadata = json.decode(result.metadata)
|
||||||
userData.metadata = metadata
|
userData.metadata = metadata
|
||||||
end
|
end
|
||||||
|
|
||||||
local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job,
|
local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job, userData.loadout, userData.playerName, userData.coords, userData.metadata)
|
||||||
userData.loadout, userData.playerName, userData.coords, userData.metadata)
|
ESX.Players[playerId] = xPlayer
|
||||||
ESX.Players[playerId] = xPlayer
|
Core.playersByIdentifier[identifier] = xPlayer
|
||||||
Core.playersByIdentifier[identifier] = xPlayer
|
|
||||||
|
|
||||||
if userData.firstname then
|
if userData.firstname then
|
||||||
xPlayer.set('firstName', userData.firstname)
|
xPlayer.set('firstName', userData.firstname)
|
||||||
xPlayer.set('lastName', userData.lastname)
|
xPlayer.set('lastName', userData.lastname)
|
||||||
if userData.dateofbirth then
|
if userData.dateofbirth then
|
||||||
xPlayer.set('dateofbirth', userData.dateofbirth)
|
xPlayer.set('dateofbirth', userData.dateofbirth)
|
||||||
end
|
end
|
||||||
if userData.sex then
|
if userData.sex then
|
||||||
xPlayer.set('sex', userData.sex)
|
xPlayer.set('sex', userData.sex)
|
||||||
end
|
end
|
||||||
if userData.height then
|
if userData.height then
|
||||||
xPlayer.set('height', userData.height)
|
xPlayer.set('height', userData.height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
TriggerEvent('esx:playerLoaded', playerId, xPlayer, isNew)
|
TriggerEvent('esx:playerLoaded', playerId, xPlayer, isNew)
|
||||||
|
|
||||||
xPlayer.triggerEvent('esx:playerLoaded',
|
xPlayer.triggerEvent('esx:playerLoaded',
|
||||||
{
|
{
|
||||||
accounts = xPlayer.getAccounts(),
|
accounts = xPlayer.getAccounts(),
|
||||||
coords = userData.coords,
|
coords = userData.coords,
|
||||||
identifier = xPlayer.getIdentifier(),
|
identifier = xPlayer.getIdentifier(),
|
||||||
inventory = xPlayer.getInventory(),
|
inventory = xPlayer.getInventory(),
|
||||||
job = xPlayer.getJob(),
|
job = xPlayer.getJob(),
|
||||||
loadout = xPlayer.getLoadout(),
|
loadout = xPlayer.getLoadout(),
|
||||||
maxWeight = xPlayer.getMaxWeight(),
|
maxWeight = xPlayer.getMaxWeight(),
|
||||||
money = xPlayer.getMoney(),
|
money = xPlayer.getMoney(),
|
||||||
sex = xPlayer.get("sex") or "m",
|
sex = xPlayer.get("sex") or "m",
|
||||||
firstName = xPlayer.get("firstName") or "John",
|
firstName = xPlayer.get("firstName") or "John",
|
||||||
lastName = xPlayer.get("lastName") or "Doe",
|
lastName = xPlayer.get("lastName") or "Doe",
|
||||||
dateofbirth = xPlayer.get("dateofbirth") or "01/01/2000",
|
dateofbirth = xPlayer.get("dateofbirth") or "01/01/2000",
|
||||||
height = xPlayer.get("height") or 120,
|
height = xPlayer.get("height") or 120,
|
||||||
dead = false,
|
dead = false,
|
||||||
metadata = xPlayer.getMeta()
|
metadata = xPlayer.getMeta()
|
||||||
}, isNew,
|
}, isNew,
|
||||||
userData.skin)
|
userData.skin)
|
||||||
|
|
||||||
if not Config.OxInventory then
|
if not Config.OxInventory then
|
||||||
xPlayer.triggerEvent('esx:createMissingPickups', Core.Pickups)
|
xPlayer.triggerEvent('esx:createMissingPickups', Core.Pickups)
|
||||||
else
|
else
|
||||||
exports.ox_inventory:setPlayerInventory(xPlayer, userData.inventory)
|
exports.ox_inventory:setPlayerInventory(xPlayer, userData.inventory)
|
||||||
end
|
|
||||||
xPlayer.triggerEvent('esx:registerSuggestions', Core.RegisteredCommands)
|
if isNew then
|
||||||
print(('[^2INFO^0] Player ^5"%s"^0 has connected to the server. ID: ^5%s^7'):format(xPlayer.getName(), playerId))
|
for account, money in pairs(Config.StartingAccountMoney) do
|
||||||
|
if account == 'money' or account == 'black_money' then
|
||||||
|
exports.ox_inventory:AddItem(playerId, account, money)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
xPlayer.triggerEvent('esx:registerSuggestions', Core.RegisteredCommands)
|
||||||
|
print(('[^2INFO^0] Player ^5"%s"^0 has connected to the server. ID: ^5%s^7'):format(xPlayer.getName(), playerId))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
AddEventHandler('chatMessage', function(playerId, author, message)
|
AddEventHandler('chatMessage', function(playerId, author, message)
|
||||||
local xPlayer = ESX.GetPlayerFromId(playerId)
|
local xPlayer = ESX.GetPlayerFromId(playerId)
|
||||||
if message:sub(1, 1) == '/' and playerId > 0 then
|
if message:sub(1, 1) == '/' and playerId > 0 then
|
||||||
|
|||||||
Reference in New Issue
Block a user