mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
feat(Client): GetAccount method
- Minor code refactoring - Return nil on the server if the account isn't fount (self.getAccount)
This commit is contained in:
@@ -20,7 +20,7 @@ end
|
||||
|
||||
function OnTime(d, h, m)
|
||||
|
||||
for i=1, #Jobs, 1 do
|
||||
for i = 1, #Jobs, 1 do
|
||||
if Jobs[i].h == h and Jobs[i].m == m then
|
||||
Jobs[i].cb(d, h, m)
|
||||
end
|
||||
|
||||
@@ -77,8 +77,7 @@ function ESX.ShowNotification(message, type, length)
|
||||
|
||||
print("[^1ERROR^7] ^5ESX Notify^7 is Missing!")
|
||||
end
|
||||
|
||||
|
||||
|
||||
function ESX.TextUI(message, type)
|
||||
if GetResourceState("esx_textui") ~= "missing" then
|
||||
return exports["esx_textui"]:TextUI(message, type)
|
||||
@@ -155,9 +154,9 @@ if GetResourceState("esx_context") ~= "missing" then
|
||||
end
|
||||
|
||||
function ESX.RefreshContext(...)
|
||||
exports["esx_context"]:Refresh(...)
|
||||
exports["esx_context"]:Refresh(...)
|
||||
end
|
||||
else
|
||||
else
|
||||
function ESX.OpenContext()
|
||||
print("[^1ERROR^7] Tried to ^5open^7 context menu, but ^5esx_context^7 is missing!")
|
||||
end
|
||||
@@ -358,7 +357,7 @@ end
|
||||
|
||||
function ESX.Game.SpawnObject(object, coords, cb, networked)
|
||||
networked = networked == nil and true or networked
|
||||
if networked then
|
||||
if networked then
|
||||
ESX.TriggerServerCallback('esx:Onesync:SpawnObject', function(NetworkID)
|
||||
if cb then
|
||||
local obj = NetworkGetEntityFromNetworkId(NetworkID)
|
||||
@@ -374,7 +373,7 @@ function ESX.Game.SpawnObject(object, coords, cb, networked)
|
||||
cb(obj)
|
||||
end
|
||||
end, object, coords, 0.0)
|
||||
else
|
||||
else
|
||||
local model = type(object) == 'number' and object or joaat(object)
|
||||
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
|
||||
CreateThread(function()
|
||||
@@ -408,13 +407,13 @@ function ESX.Game.SpawnVehicle(vehicle, coords, heading, cb, networked)
|
||||
networked = networked == nil and true or networked
|
||||
|
||||
local playerCoords = GetEntityCoords(ESX.PlayerData.ped)
|
||||
if not vector or not playerCoords then
|
||||
if not vector or not playerCoords then
|
||||
return
|
||||
end
|
||||
local dist = #(playerCoords - vector)
|
||||
if dist > 424 then -- Onesync infinity Range (https://docs.fivem.net/docs/scripting-reference/onesync/)
|
||||
local executingResource = GetInvokingResource() or "Unknown"
|
||||
return print(("[^1ERROR^7] Resource ^5%s^7 Tried to spawn vehicle on the client but the position is too far away (Out of onesync range)."):format(executing_resource))
|
||||
return print(("[^1ERROR^7] Resource ^5%s^7 Tried to spawn vehicle on the client but the position is too far away (Out of onesync range)."):format(executingResource))
|
||||
end
|
||||
|
||||
CreateThread(function()
|
||||
@@ -610,10 +609,10 @@ function ESX.Game.GetVehicleProperties(vehicle)
|
||||
|
||||
local hasCustomXenonColor, customXenonColorR, customXenonColorG, customXenonColorB = GetVehicleXenonLightsCustomColor(vehicle)
|
||||
local customXenonColor = nil
|
||||
if hasCustomXenonColor then
|
||||
if hasCustomXenonColor then
|
||||
customXenonColor = {customXenonColorR, customXenonColorG, customXenonColorB}
|
||||
end
|
||||
|
||||
|
||||
local hasCustomSecondaryColor = GetIsVehicleSecondaryColourCustom(vehicle)
|
||||
local customSecondaryColor = nil
|
||||
if hasCustomSecondaryColor then
|
||||
@@ -675,7 +674,7 @@ function ESX.Game.GetVehicleProperties(vehicle)
|
||||
|
||||
pearlescentColor = pearlescentColor,
|
||||
wheelColor = wheelColor,
|
||||
|
||||
|
||||
dashboardColor = dashboardColor,
|
||||
interiorColor = interiorColor,
|
||||
|
||||
@@ -1027,6 +1026,17 @@ function ESX.Game.Utils.DrawText3D(coords, text, size, font)
|
||||
ClearDrawOrigin()
|
||||
end
|
||||
|
||||
---@param account string Account name (money/bank/black_money)
|
||||
---@return table|nil
|
||||
function ESX.GetAccount(account)
|
||||
for i = 1, #ESX.PlayerData.accounts, 1 do
|
||||
if ESX.PlayerData.accounts[i].name == account then
|
||||
return ESX.PlayerData.accounts[i]
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function ESX.ShowInventory()
|
||||
if not Config.EnableDefaultInventory then
|
||||
return
|
||||
@@ -1038,7 +1048,7 @@ function ESX.ShowInventory()
|
||||
}
|
||||
local currentWeight = 0
|
||||
|
||||
for i=1, #(ESX.PlayerData.accounts) do
|
||||
for i = 1, #(ESX.PlayerData.accounts) do
|
||||
if ESX.PlayerData.accounts[i].money > 0 then
|
||||
local formattedMoney = TranslateCap('locale_currency', ESX.Math.GroupDigits(ESX.PlayerData.accounts[i].money))
|
||||
local canDrop = ESX.PlayerData.accounts[i].name ~= 'bank'
|
||||
@@ -1105,7 +1115,7 @@ function ESX.ShowInventory()
|
||||
icon = "fas fa-weight",
|
||||
title = "Current Weight: "..currentWeight
|
||||
}
|
||||
|
||||
|
||||
ESX.CloseContext()
|
||||
|
||||
ESX.OpenContext("right", elements, function(menu,element)
|
||||
|
||||
@@ -338,7 +338,7 @@ if not Config.OxInventory then
|
||||
RegisterNetEvent('esx:removeWeapon')
|
||||
AddEventHandler('esx:removeWeapon', function(weapon)
|
||||
local playerPed = ESX.PlayerData.ped
|
||||
RemoveWeaponFromPed(ESX.PlayerData.ped, joaat(weapon))
|
||||
RemoveWeaponFromPed(playerPed, joaat(weapon))
|
||||
SetPedAmmo(ESX.PlayerData.ped, joaat(weapon), 0)
|
||||
end)
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ function ESX.DumpTable(table, nb)
|
||||
end
|
||||
|
||||
s = '{\n'
|
||||
for k,v in pairs(table) do
|
||||
for k, v in pairs(table) do
|
||||
if type(k) ~= 'number' then k = '"'..k..'"' end
|
||||
for i = 1, nb, 1 do
|
||||
s = s .. " "
|
||||
|
||||
@@ -13,12 +13,12 @@ end
|
||||
|
||||
function ESX.Table.Set(t)
|
||||
local set = {}
|
||||
for k,v in ipairs(t) do set[v] = true end
|
||||
for k, v in ipairs(t) do set[v] = true end
|
||||
return set
|
||||
end
|
||||
|
||||
function ESX.Table.IndexOf(t, value)
|
||||
for i=1, #t, 1 do
|
||||
for i = 1, #t, 1 do
|
||||
if t[i] == value then
|
||||
return i
|
||||
end
|
||||
@@ -38,7 +38,7 @@ function ESX.Table.LastIndexOf(t, value)
|
||||
end
|
||||
|
||||
function ESX.Table.Find(t, cb)
|
||||
for i=1, #t, 1 do
|
||||
for i = 1, #t, 1 do
|
||||
if cb(t[i]) then
|
||||
return t[i]
|
||||
end
|
||||
@@ -48,7 +48,7 @@ function ESX.Table.Find(t, cb)
|
||||
end
|
||||
|
||||
function ESX.Table.FindIndex(t, cb)
|
||||
for i=1, #t, 1 do
|
||||
for i = 1, #t, 1 do
|
||||
if cb(t[i]) then
|
||||
return i
|
||||
end
|
||||
@@ -60,7 +60,7 @@ end
|
||||
function ESX.Table.Filter(t, cb)
|
||||
local newTable = {}
|
||||
|
||||
for i=1, #t, 1 do
|
||||
for i = 1, #t, 1 do
|
||||
if cb(t[i]) then
|
||||
table.insert(newTable, t[i])
|
||||
end
|
||||
@@ -72,7 +72,7 @@ end
|
||||
function ESX.Table.Map(t, cb)
|
||||
local newTable = {}
|
||||
|
||||
for i=1, #t, 1 do
|
||||
for i = 1, #t, 1 do
|
||||
newTable[i] = cb(t[i], i)
|
||||
end
|
||||
|
||||
@@ -95,7 +95,7 @@ function ESX.Table.Clone(t)
|
||||
local meta = getmetatable(t)
|
||||
local target = {}
|
||||
|
||||
for k,v in pairs(t) do
|
||||
for k, v in pairs(t) do
|
||||
if type(v) == 'table' then
|
||||
target[k] = ESX.Table.Clone(v)
|
||||
else
|
||||
@@ -111,7 +111,7 @@ end
|
||||
function ESX.Table.Concat(t1, t2)
|
||||
local t3 = ESX.Table.Clone(t1)
|
||||
|
||||
for i=1, #t2, 1 do
|
||||
for i = 1, #t2, 1 do
|
||||
table.insert(t3, t2[i])
|
||||
end
|
||||
|
||||
@@ -122,7 +122,7 @@ function ESX.Table.Join(t, sep)
|
||||
local sep = sep or ','
|
||||
local str = ''
|
||||
|
||||
for i=1, #t, 1 do
|
||||
for i = 1, #t, 1 do
|
||||
if i > 1 then
|
||||
str = str .. sep
|
||||
end
|
||||
|
||||
@@ -129,7 +129,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
local minimalAccounts = {}
|
||||
|
||||
for i=1, #self.accounts do
|
||||
for i = 1, #self.accounts do
|
||||
minimalAccounts[self.accounts[i].name] = self.accounts[i].money
|
||||
end
|
||||
|
||||
@@ -137,11 +137,12 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
function self.getAccount(account)
|
||||
for i=1, #self.accounts do
|
||||
for i = 1, #self.accounts do
|
||||
if self.accounts[i].name == account then
|
||||
return self.accounts[i]
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function self.getInventory(minimal)
|
||||
@@ -170,7 +171,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
local minimalLoadout = {}
|
||||
|
||||
for k,v in ipairs(self.loadout) do
|
||||
for k, v in ipairs(self.loadout) do
|
||||
minimalLoadout[v.name] = {ammo = v.ammo}
|
||||
if v.tintIndex > 0 then minimalLoadout[v.name].tintIndex = v.tintIndex end
|
||||
|
||||
@@ -270,7 +271,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
function self.getInventoryItem(name, metadata)
|
||||
for k,v in ipairs(self.inventory) do
|
||||
for k, v in ipairs(self.inventory) do
|
||||
if v.name == name then
|
||||
return v
|
||||
end
|
||||
@@ -477,7 +478,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
function self.removeWeapon(weaponName)
|
||||
local weaponLabel
|
||||
|
||||
for k,v in ipairs(self.loadout) do
|
||||
for k, v in ipairs(self.loadout) do
|
||||
if v.name == weaponName then
|
||||
weaponLabel = v.label
|
||||
|
||||
@@ -504,7 +505,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
if component then
|
||||
if self.hasWeaponComponent(weaponName, weaponComponent) then
|
||||
for k,v in ipairs(self.loadout[loadoutNum].components) do
|
||||
for k, v in ipairs(self.loadout[loadoutNum].components) do
|
||||
if v == weaponComponent then
|
||||
table.remove(self.loadout[loadoutNum].components, k)
|
||||
break
|
||||
@@ -531,7 +532,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
local loadoutNum, weapon = self.getWeapon(weaponName)
|
||||
|
||||
if weapon then
|
||||
for k,v in ipairs(weapon.components) do
|
||||
for k, v in ipairs(weapon.components) do
|
||||
if v == weaponComponent then
|
||||
return true
|
||||
end
|
||||
@@ -544,7 +545,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
function self.hasWeapon(weaponName)
|
||||
for k,v in ipairs(self.loadout) do
|
||||
for k, v in ipairs(self.loadout) do
|
||||
if v.name == weaponName then
|
||||
return true
|
||||
end
|
||||
@@ -554,7 +555,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
function self.hasItem(item, metadata)
|
||||
for k,v in ipairs(self.inventory) do
|
||||
for k, v in ipairs(self.inventory) do
|
||||
if (v.name == item) and (v.count >= 1) then
|
||||
return v, v.count
|
||||
end
|
||||
@@ -564,7 +565,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
function self.getWeapon(weaponName)
|
||||
for k,v in ipairs(self.loadout) do
|
||||
for k, v in ipairs(self.loadout) do
|
||||
if v.name == weaponName then
|
||||
return k, v
|
||||
end
|
||||
|
||||
@@ -84,7 +84,7 @@ ESX.RegisterCommand({'cardel', 'dv'}, 'admin', function(xPlayer, args, showError
|
||||
DeleteEntity(PedVehicle)
|
||||
end
|
||||
local Vehicles = ESX.OneSync.GetVehiclesInArea(GetEntityCoords(GetPlayerPed(xPlayer.source)), tonumber(args.radius) or 5.0)
|
||||
for i=1, #Vehicles do
|
||||
for i = 1, #Vehicles do
|
||||
local Vehicle = NetworkGetEntityFromNetworkId(Vehicles[i])
|
||||
if DoesEntityExist(Vehicle) then
|
||||
DeleteEntity(Vehicle)
|
||||
@@ -188,7 +188,7 @@ end, true, {help = TranslateCap('command_clearall')})
|
||||
|
||||
if not Config.OxInventory then
|
||||
ESX.RegisterCommand('clearinventory', 'admin', function(xPlayer, args, showError)
|
||||
for k,v in ipairs(args.playerId.inventory) do
|
||||
for k, v in ipairs(args.playerId.inventory) do
|
||||
if v.count > 0 then
|
||||
args.playerId.setInventoryItem(v.name, 0)
|
||||
end
|
||||
@@ -293,7 +293,7 @@ end, false)
|
||||
ESX.RegisterCommand('players', "admin", function(xPlayer, args, showError)
|
||||
local xPlayers = ESX.GetExtendedPlayers() -- Returns all xPlayers
|
||||
print("^5"..#xPlayers.." ^2online player(s)^0")
|
||||
for i=1, #(xPlayers) do
|
||||
for i = 1, #(xPlayers) do
|
||||
local xPlayer = xPlayers[i]
|
||||
print("^1[ ^2ID : ^5"..xPlayer.source.." ^0| ^2Name : ^5"..xPlayer.getName().." ^0 | ^2Group : ^5"..xPlayer.getGroup().." ^0 | ^2Identifier : ^5".. xPlayer.identifier .."^1]^0\n")
|
||||
end
|
||||
|
||||
@@ -338,7 +338,7 @@ else
|
||||
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
|
||||
for i=1, #(xPlayers) do
|
||||
for i = 1, #(xPlayers) do
|
||||
if xPlayers[i] then
|
||||
checkIdentity(xPlayers[i])
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local Timeouts, OpenedMenus, MenuType = {}, {}, 'dialog'
|
||||
|
||||
local function openMenu(namespace, name, data)
|
||||
for i=1, #Timeouts, 1 do
|
||||
for i = 1, #Timeouts, 1 do
|
||||
ESX.ClearTimeout(Timeouts[i])
|
||||
end
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ CreateThread(function()
|
||||
name = name,
|
||||
})
|
||||
|
||||
for k,v in pairs(OpenedMenus) do
|
||||
for k, v in pairs(OpenedMenus) do
|
||||
if v then
|
||||
OpenedMenuCount = OpenedMenuCount + 1
|
||||
end
|
||||
|
||||
@@ -185,7 +185,7 @@ if ESX.GetConfig().Multichar then
|
||||
function SelectCharacterMenu(Characters, slots)
|
||||
local Character = next(Characters)
|
||||
local elements = {{title = TranslateCap('select_char') , icon = "fa-solid fa-users", description = TranslateCap('select_char_description') , unselectable = true}}
|
||||
for k,v in pairs(Characters) do
|
||||
for k, v in pairs(Characters) do
|
||||
if not v.model and v.skin then
|
||||
if v.skin.model then v.model = v.skin.model elseif v.skin.sex == 1 then v.model = mp_f_freemode_01 else v.model = mp_m_freemode_01 end
|
||||
end
|
||||
|
||||
@@ -16,11 +16,11 @@ function OpenMenu(submitCb, cancelCb, restrict)
|
||||
|
||||
-- Restrict menu
|
||||
if restrict == nil then
|
||||
for i=1, #components, 1 do
|
||||
for i = 1, #components, 1 do
|
||||
_components[i] = components[i]
|
||||
end
|
||||
else
|
||||
for i=1, #components, 1 do
|
||||
for i = 1, #components, 1 do
|
||||
local found = false
|
||||
|
||||
for j=1, #restrict, 1 do
|
||||
@@ -35,7 +35,7 @@ function OpenMenu(submitCb, cancelCb, restrict)
|
||||
end
|
||||
end
|
||||
-- Insert elements
|
||||
for i=1, #_components, 1 do
|
||||
for i = 1, #_components, 1 do
|
||||
local value = _components[i].value
|
||||
local componentId = _components[i].componentId
|
||||
|
||||
@@ -54,7 +54,7 @@ function OpenMenu(submitCb, cancelCb, restrict)
|
||||
type = 'slider'
|
||||
}
|
||||
|
||||
for k,v in pairs(maxVals) do
|
||||
for k, v in pairs(maxVals) do
|
||||
if k == _components[i].name then
|
||||
data.max = v
|
||||
break
|
||||
@@ -104,7 +104,7 @@ function OpenMenu(submitCb, cancelCb, restrict)
|
||||
|
||||
local newData = {}
|
||||
|
||||
for i=1, #elements, 1 do
|
||||
for i = 1, #elements, 1 do
|
||||
newData = {}
|
||||
newData.max = maxVals[elements[i].name]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user