Update main.lua

This commit is contained in:
Arctos2win
2024-01-22 23:26:04 +01:00
committed by GitHub
parent 39306c2ad6
commit 55ec231f29
+120 -146
View File
@@ -122,132 +122,121 @@ if not Config.Multichar then
end)
end
function loadESXPlayer(identifier, playerId, isNew)
local userData = {
accounts = {},
inventory = {},
loadout = {},
playerName = GetPlayerName(playerId),
weight = 0,
metadata = {},
firstName = 'John',
lastName = 'Doe',
dateofbirth = '01/01/2000',
height = 120,
skin = { sex = 'm' },
sex = 'm',
group = 'user',
identifier = identifier,
function loadESXPlayer(identifier, playerId, isNew)
local userData = {
accounts = {},
inventory = {},
loadout = {},
weight = 0,
identifier = identifier,
firstName = 'John',
lastName = 'Doe',
dateofbirth = '01/01/2000',
height = 120,
dead = false
}
}
local result = MySQL.prepare.await(loadPlayer, { identifier })
local result = MySQL.prepare.await(loadPlayer, {identifier})
-- Accounts
local accounts = result.accounts
accounts = accounts and accounts ~= '' and json.decode(accounts) or {}
-- Accounts
local accounts = result.accounts
accounts = (accounts and accounts ~= '') and json.decode(accounts) or {}
for account, data in pairs(Config.Accounts) do
data.round = data.round or data.round == nil
local index = #userData.accounts + 1
local index = #userData.accounts + 1
userData.accounts[index] = {
name = account,
money = accounts[account] or Config.StartingAccountMoney[account] or 0,
label = data.label,
round = data.round,
index = index
name = account,
money = accounts[account] or Config.StartingAccountMoney[account] or
0,
label = data.label,
round = data.round,
index = index
}
end
end
-- Job
local job, grade = result.job, tostring(result.job_grade)
if not ESX.DoesJobExist(job, grade) then
print(('[^3WARNING^7] Ignoring invalid job for ^5%s^7 [job: ^5%s^7, grade: ^5%s^7]'):format(identifier, job, grade))
if not ESX.DoesJobExist(job, grade) then
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'
end
end
jobObject, gradeObject = ESX.Jobs[job], ESX.Jobs[job].grades[grade]
userData.job = {
id = jobObject.id,
name = jobObject.name,
label = jobObject.label,
id = jobObject.id,
name = jobObject.name,
label = jobObject.label,
grade = tonumber(grade),
grade_name = gradeObject.name,
grade_label = gradeObject.label,
grade_salary = gradeObject.salary,
grade = tonumber(grade),
grade_name = gradeObject.name,
grade_label = gradeObject.label,
grade_salary = gradeObject.salary,
skin_male = gradeObject.skin_male and json.decode(gradeObject.skin_male) or {},
skin_female = gradeObject.skin_female and json.decode(gradeObject.skin_female) or {}
skin_male = gradeObject.skin_male and json.decode(gradeObject.skin_male) or
{},
skin_female = gradeObject.skin_female and
json.decode(gradeObject.skin_female) or {}
}
-- Inventory
if result.inventory and result.inventory ~= '' then
if not Config.OxInventory then
local inventory = json.decode(result.inventory)
-- Inventory
if not Config.OxInventory then
local inventory = (result.inventory and result.inventory ~= '') and json.decode(result.inventory) or {}
for name, count in pairs(inventory) do
local item = ESX.Items[name]
for name, item in pairs(ESX.Items) do
local count = inventory[name] or 0
userData.weight += (count * item.weight)
if count > 0 then
userData.weight += (item.weight * count)
end
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
})
end
table.sort(userData.inventory, function(a, b)
return a.label < b.label
end)
else
userData.inventory = json.decode(result.inventory)
end
end
-- Group
if result.group then
if result.group == 'superadmin' then
userData.group = 'admin'
print("[^3WARNING^7] ^5Superadmin^7 detected, setting group to ^5admin^7")
else
userData.group = result.group
userData.inventory[#userData.inventory + 1] = {
name = name,
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)
return a.label < b.label
end)
elseif result.inventory and result.inventory ~= '' then
userData.inventory = json.decode(result.inventory)
end
-- Group
if result.group then
if result.group == "superadmin" then
userData.group = "admin"
print("[^3WARNING^7] ^5Superadmin^7 detected, setting group to ^5admin^7")
else
userData.group = result.group
end
else
userData.group = 'user'
end
-- Loadout
if not Config.OxInventory then
if result.loadout and result.loadout ~= '' then
if not Config.OxInventory then
if result.loadout and result.loadout ~= '' then
local loadout = json.decode(result.loadout)
for name, weapon in pairs(loadout) do
local label = ESX.GetWeaponLabel(name)
if label then
weapon.components = weapon.components or {}
weapon.tintIndex = weapon.tintIndex or 0
table.insert(userData.loadout,
{
name = name,
userData.loadout[#userData.loadout + 1] = {
name = name,
ammo = weapon.ammo,
label = label,
components = weapon.components,
tintIndex = weapon.tintIndex
})
label = label,
components = weapon.components or {},
tintIndex = weapon.tintIndex or 0
}
end
end
end
@@ -257,77 +246,62 @@ function loadESXPlayer(identifier, playerId, isNew)
userData.coords = json.decode(result.position) or Config.DefaultSpawns[math.random(#Config.DefaultSpawns)]
-- Skin
if result.skin and result.skin ~= '' then
userData.skin = json.decode(result.skin)
end
userData.skin = (result.skin and result.skin ~= '') and json.decode(result.skin) or { sex = userData.sex == 'f' and 1 or 0}
-- Metadata
if result.metadata and result.metadata ~= '' then
local metadata = json.decode(result.metadata)
userData.metadata = metadata
end
userData.metadata = (result.metadata and result.metadata ~= '') and json.decode(result.metadata) or {}
-- xPlayer creation
local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job, userData.loadout, userData.playerName, userData.coords, userData.metadata)
-- xPlayer Creation
local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job, userData.loadout, GetPlayerName(playerId), userData.coords, userData.metadata)
ESX.Players[playerId] = xPlayer
Core.playersByIdentifier[identifier] = xPlayer
Core.playersByIdentifier[identifier] = xPlayer
-- Identity
if result.firstname and result.firstname ~= '' then
userData.firstName = result.firstname
userData.lastName = result.lastname
-- Identity
if result.firstname and result.firstname ~= '' then
userData.firstName = result.firstname
userData.lastName = result.lastname
xPlayer.set('firstName', result.firstname)
xPlayer.set('lastName', result.lastname)
xPlayer.set('firstName', result.firstname)
xPlayer.set('lastName', result.lastname)
xPlayer.setName(('%s %s'):format(result.firstname, result.lastname))
userData.playerName = userData.firstName .. ' ' .. userData.lastName
xPlayer.name = userData.playerName
if result.dateofbirth then
userData.dateofbirth = result.dateofbirth
if result.dateofbirth then
userData.dateofbirth = result.dateofbirth
xPlayer.set('dateofbirth', result.dateofbirth)
end
if result.sex then
userData.sex = result.sex
end
if result.sex then
userData.sex = result.sex
xPlayer.set('sex', result.sex)
end
if result.height then
userData.height = result.height
end
if result.height then
userData.height = result.height
xPlayer.set('height', result.height)
end
end
-- Save player health and armor in metadata
local ped = GetPlayerPed(xPlayer.source)
if ped then
xPlayer.setMeta('health', xPlayer.getMeta('health') or GetEntityHealth(ped))
xPlayer.setMeta('armor', xPlayer.getMeta('armor') or GetPedArmour(ped))
end
end
TriggerEvent('esx:playerLoaded', playerId, xPlayer, isNew)
userData.maxWeight = xPlayer.getMaxWeight()
money = xPlayer.getMoney()
xPlayer.triggerEvent('esx:playerLoaded',userData, isNew, userData.skin)
userData.money = xPlayer.getMoney()
userData.maxWeight = xPlayer.getMaxWeight()
xPlayer.triggerEvent('esx:playerLoaded', userData, isNew, userData.skin)
if not Config.OxInventory then
xPlayer.triggerEvent('esx:createMissingPickups', Core.Pickups)
else
exports.ox_inventory:setPlayerInventory(xPlayer, userData.inventory)
if isNew then
xPlayer.triggerEvent('esx:createMissingPickups', Core.Pickups)
else
exports.ox_inventory:setPlayerInventory(xPlayer, userData.inventory)
if isNew then
local shared = json.decode(GetConvar('inventory:accounts', '["money"]'))
for i=1, #shared do
local account = Config.StartingAccountMoney[shared[i]]
if account then
exports.ox_inventory:AddItem(playerId, shared[i], account)
end
end
end
end
for i = 1, #shared do
local name = shared[i]
local account = Config.StartingAccountMoney[name]
if account then
exports.ox_inventory:AddItem(playerId, name, account)
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))
print(('[^2INFO^0] Player ^5"%s"^0 has connected to the server. ID: ^5%s^7'):format(xPlayer.getName(), playerId))
end
AddEventHandler('chatMessage', function(playerId, _, message)