mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 09:18:53 +00:00
@@ -389,6 +389,7 @@ CREATE TABLE `users` (
|
||||
`job` varchar(20) DEFAULT 'unemployed',
|
||||
`job_grade` int(11) DEFAULT 0,
|
||||
`loadout` longtext DEFAULT NULL,
|
||||
`meta` LONGTEXT NULL DEFAULT NULL,
|
||||
`position` longtext NULL DEFAULT NULL,
|
||||
`firstname` varchar(16) DEFAULT NULL,
|
||||
`lastname` varchar(16) DEFAULT NULL,
|
||||
|
||||
@@ -646,3 +646,8 @@ for i = 1, #DoNotUse do
|
||||
print("[^1ERROR^7] YOU ARE USING A RESOURCE THAT WILL BREAK ^1ESX^7, PLEASE REMOVE ^5" .. DoNotUse[i] .. "^7")
|
||||
end
|
||||
end
|
||||
|
||||
RegisterNetEvent('esx:updatePlayerData', function(key, val)
|
||||
if GetInvokingResource() ~= 'es_extended' then return end
|
||||
ESX.SetPlayerData(key, val)
|
||||
end)
|
||||
@@ -15,6 +15,7 @@ CREATE TABLE `users` (
|
||||
`job` VARCHAR(20) NULL DEFAULT 'unemployed',
|
||||
`job_grade` INT NULL DEFAULT 0,
|
||||
`loadout` LONGTEXT NULL DEFAULT NULL,
|
||||
`meta` LONGTEXT NULL DEFAULT NULL,
|
||||
`position` longtext NULL DEFAULT NULL,
|
||||
|
||||
PRIMARY KEY (`identifier`)
|
||||
|
||||
@@ -4,7 +4,7 @@ local DoesEntityExist = DoesEntityExist
|
||||
local GetEntityCoords = GetEntityCoords
|
||||
local GetEntityHeading = GetEntityHeading
|
||||
|
||||
function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, weight, job, loadout, name, coords)
|
||||
function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, weight, job, loadout, name, coords, meta)
|
||||
local targetOverrides = Config.PlayerFunctionOverride and Core.PlayerFunctionOverrides[Config.PlayerFunctionOverride] or {}
|
||||
|
||||
local self = {}
|
||||
@@ -22,6 +22,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
self.variables = {}
|
||||
self.weight = weight
|
||||
self.maxWeight = Config.MaxWeight
|
||||
self.meta = meta
|
||||
if Config.Multichar then self.license = 'license'.. identifier:sub(identifier:find(':'), identifier:len()) else self.license = 'license:'..identifier end
|
||||
|
||||
ExecuteCommand(('add_principal identifier.%s group.%s'):format(self.license, self.group))
|
||||
@@ -32,6 +33,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
stateBag:set("job", self.job, true)
|
||||
stateBag:set("group", self.group, true)
|
||||
stateBag:set("name", self.name, true)
|
||||
stateBag:set("meta", self.meta, true)
|
||||
|
||||
function self.triggerEvent(eventName, ...)
|
||||
TriggerClientEvent(eventName, self.source, ...)
|
||||
@@ -573,6 +575,109 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
self.triggerEvent('esx:showHelpNotification', msg, thisFrame, beep, duration)
|
||||
end
|
||||
|
||||
function self.getMeta(index, subIndex)
|
||||
if index then
|
||||
|
||||
if type(index) ~= "string" then
|
||||
return print("[^1ERROR^7] xPlayer.getMeta ^5index^7 should be ^5string^7!")
|
||||
end
|
||||
|
||||
if self.meta[index] then
|
||||
|
||||
if subIndex and type(self.meta[index]) == "table" then
|
||||
local _type = type(subIndex)
|
||||
|
||||
if _type == "string" then
|
||||
if self.meta[index][subIndex] then
|
||||
return self.meta[index][subIndex]
|
||||
end
|
||||
|
||||
return print(("[^1ERROR^7] xPlayer.getMeta ^5%s^7 not esxist on ^5%s^7!"):format(subIndex, index))
|
||||
end
|
||||
|
||||
if _type == "table" then
|
||||
local returnValues = {}
|
||||
for i = 1, #subIndex do
|
||||
if self.meta[index][subIndex[i]] then
|
||||
returnValues[subIndex[i]] = self.meta[index][subIndex[i]]
|
||||
else
|
||||
print(("[^1ERROR^7] xPlayer.getMeta ^5%s^7 not esxist on ^5%s^7!"):format(subIndex[i], index))
|
||||
end
|
||||
end
|
||||
|
||||
return returnValues
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return self.meta[index]
|
||||
else
|
||||
return print(("[^1ERROR^7] xPlayer.getMeta ^5%s^7 not exist!"):format(index))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return self.meta
|
||||
end
|
||||
|
||||
function self.setMeta(index, value, subValue)
|
||||
if not index then
|
||||
return print("[^1ERROR^7] xPlayer.setMeta ^5index^7 is Missing!")
|
||||
end
|
||||
|
||||
if type(index) ~= "string" then
|
||||
return print("[^1ERROR^7] xPlayer.setMeta ^5index^7 should be ^5string^7!")
|
||||
end
|
||||
|
||||
if not value then
|
||||
return print(("[^1ERROR^7] xPlayer.setMeta ^5%s^7 is Missing!"):format(value))
|
||||
end
|
||||
|
||||
local _type = type(value)
|
||||
|
||||
if not subValue then
|
||||
|
||||
if _type ~= "number" and _type ~= "string" and _type ~= "table" then
|
||||
return print(("[^1ERROR^7] xPlayer.setMeta ^5%s^7 should be ^5number^7 or ^5string^7 or ^5table^7!"):format(value))
|
||||
end
|
||||
|
||||
self.meta[index] = value
|
||||
else
|
||||
|
||||
if _type ~= "string" then
|
||||
return print(("[^1ERROR^7] xPlayer.setMeta ^5value^7 should be ^5string^7 as a subIndex!"):format(value))
|
||||
end
|
||||
|
||||
self.meta[index][value] = subValue
|
||||
end
|
||||
|
||||
|
||||
self.triggerEvent('esx:updatePlayerData', 'meta', self.meta)
|
||||
Player(self.source).state:set('meta', self.meta, true)
|
||||
end
|
||||
|
||||
function self.clearMeta(index)
|
||||
if not index then
|
||||
return print(("[^1ERROR^7] xPlayer.clearMeta ^5%s^7 is Missing!"):format(index))
|
||||
end
|
||||
|
||||
if type(index) == 'table' then
|
||||
for _, val in pairs(index) do
|
||||
self.clearMeta(val)
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
if not self.meta[index] then
|
||||
return print(("[^1ERROR^7] xPlayer.clearMeta ^5%s^7 not exist!"):format(index))
|
||||
end
|
||||
|
||||
self.meta[index] = nil
|
||||
self.triggerEvent('esx:updatePlayerData', 'meta', self.meta)
|
||||
Player(self.source).state:set('meta', self.meta, true)
|
||||
end
|
||||
|
||||
for fnName,fn in pairs(targetOverrides) do
|
||||
self[fnName] = fn(self)
|
||||
end
|
||||
|
||||
@@ -159,16 +159,17 @@ function Core.SavePlayer(xPlayer, cb)
|
||||
local parameters <const> = {
|
||||
json.encode(xPlayer.getAccounts(true)),
|
||||
xPlayer.job.name,
|
||||
xPlayer.job.grade,
|
||||
xPlayer.job.grade,
|
||||
xPlayer.group,
|
||||
json.encode(xPlayer.getCoords()),
|
||||
json.encode(xPlayer.getInventory(true)),
|
||||
json.encode(xPlayer.getLoadout(true)),
|
||||
json.encode(xPlayer.getMeta()),
|
||||
xPlayer.identifier
|
||||
}
|
||||
|
||||
MySQL.prepare(
|
||||
'UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ? WHERE `identifier` = ?',
|
||||
'UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ?, `meta` = ? WHERE `identifier` = ?',
|
||||
parameters,
|
||||
function(affectedRows)
|
||||
if affectedRows == 1 then
|
||||
@@ -200,12 +201,13 @@ function Core.SavePlayers(cb)
|
||||
json.encode(xPlayer.getCoords()),
|
||||
json.encode(xPlayer.getInventory(true)),
|
||||
json.encode(xPlayer.getLoadout(true)),
|
||||
json.encode(xPlayer.getMeta()),
|
||||
xPlayer.identifier
|
||||
}
|
||||
end
|
||||
|
||||
MySQL.prepare(
|
||||
"UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ? WHERE `identifier` = ?",
|
||||
"UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ?, `meta` = ? WHERE `identifier` = ?",
|
||||
parameters,
|
||||
function(results)
|
||||
if not results then
|
||||
|
||||
@@ -2,7 +2,7 @@ SetMapName('San Andreas')
|
||||
SetGameType('ESX Legacy')
|
||||
|
||||
local newPlayer = 'INSERT INTO `users` SET `accounts` = ?, `identifier` = ?, `group` = ?'
|
||||
local loadPlayer = 'SELECT `accounts`, `job`, `job_grade`, `group`, `position`, `inventory`, `skin`, `loadout`'
|
||||
local loadPlayer = 'SELECT `accounts`, `job`, `job_grade`, `group`, `position`, `inventory`, `skin`, `loadout`, `meta`'
|
||||
|
||||
if Config.Multichar then
|
||||
newPlayer = newPlayer .. ', `firstname` = ?, `lastname` = ?, `dateofbirth` = ?, `sex` = ?, `height` = ?'
|
||||
@@ -111,8 +111,7 @@ if not Config.Multichar then
|
||||
end
|
||||
|
||||
function loadESXPlayer(identifier, playerId, isNew)
|
||||
local userData = {accounts = {}, inventory = {}, job = {}, loadout = {}, playerName = GetPlayerName(playerId), weight = 0}
|
||||
|
||||
local userData = {accounts = {}, inventory = {}, job = {}, loadout = {}, playerName = GetPlayerName(playerId), weight = 0, meta = {}}
|
||||
local result = MySQL.prepare.await(loadPlayer, {identifier})
|
||||
local job, grade, jobObject, gradeObject = result.job, tostring(result.job_grade)
|
||||
local foundAccounts, foundItems = {}, {}
|
||||
@@ -271,8 +270,13 @@ function loadESXPlayer(identifier, playerId, isNew)
|
||||
end
|
||||
end
|
||||
|
||||
if result.meta and result.meta ~= '' then
|
||||
local meta = json.decode(result.meta)
|
||||
userData.meta = meta
|
||||
end
|
||||
|
||||
local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job,
|
||||
userData.loadout, userData.playerName, userData.coords)
|
||||
userData.loadout, userData.playerName, userData.coords, userData.meta)
|
||||
ESX.Players[playerId] = xPlayer
|
||||
Core.playersByIdentifier[identifier] = xPlayer
|
||||
|
||||
@@ -307,7 +311,8 @@ function loadESXPlayer(identifier, playerId, isNew)
|
||||
lastName = xPlayer.get("lastName") or "Doe",
|
||||
dateofbirth = xPlayer.get("dateofbirth") or "01/01/2000",
|
||||
height = xPlayer.get("height") or 120,
|
||||
dead = false
|
||||
dead = false,
|
||||
meta = xPlayer.getMeta()
|
||||
}, isNew,
|
||||
userData.skin)
|
||||
|
||||
@@ -579,7 +584,7 @@ ESX.RegisterServerCallback('esx:getPlayerData', function(source, cb)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
cb({identifier = xPlayer.identifier, accounts = xPlayer.getAccounts(), inventory = xPlayer.getInventory(), job = xPlayer.getJob(),
|
||||
loadout = xPlayer.getLoadout(), money = xPlayer.getMoney(), position = xPlayer.getCoords(true)})
|
||||
loadout = xPlayer.getLoadout(), money = xPlayer.getMoney(), position = xPlayer.getCoords(true), meta = xPlayer.getMeta()})
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx:isUserAdmin', function(source, cb)
|
||||
@@ -594,7 +599,7 @@ ESX.RegisterServerCallback('esx:getOtherPlayerData', function(source, cb, target
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
cb({identifier = xPlayer.identifier, accounts = xPlayer.getAccounts(), inventory = xPlayer.getInventory(), job = xPlayer.getJob(),
|
||||
loadout = xPlayer.getLoadout(), money = xPlayer.getMoney(), position = xPlayer.getCoords(true)})
|
||||
loadout = xPlayer.getLoadout(), money = xPlayer.getMoney(), position = xPlayer.getCoords(true), meta = xPlayer.getMeta()})
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx:getPlayerNames', function(source, cb, players)
|
||||
|
||||
Reference in New Issue
Block a user