Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion [core]/es_extended/client/functions.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---@return boolean
---@diagnostic disable-next-line: duplicate-set-field
function ESX.IsPlayerLoaded()
return ESX.PlayerLoaded
end
Expand Down Expand Up @@ -559,7 +560,8 @@ function ESX.Game.SpawnVehicle(vehicleModel, coords, heading, cb, networked)
local modelHash = ESX.Streaming.RequestModel(model)
if not modelHash then
if promise then
return promise:reject(("Tried to spawn invalid vehicle - ^5%s^7!"):format(model))
promise:reject(("Tried to spawn invalid vehicle - ^5%s^7!"):format(model))
return
end
error(("Tried to spawn invalid vehicle - ^5%s^7!"):format(model))
end
Expand Down
4 changes: 2 additions & 2 deletions [core]/es_extended/client/imports/point.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local Point = ESX.Class()

local nearby, loop = {}
local nearby, loop = {}, nil

function Point:constructor(properties)
self.coords = properties.coords
Expand All @@ -23,7 +23,7 @@ function Point:constructor(properties)
point:inside(#(coords - point.coords))
end
end
Wait()
Wait(0)
end
end)
end
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/client/modules/callback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ end

---@param eventName string
---@param ... any
---@return any
---@return ...
function ESX.AwaitServerCallback(eventName, ...)
local invokingResource = GetInvokingResource()
local invoker = (invokingResource and invokingResource ~= "unknown") and invokingResource or "es_extended"
Expand Down
3 changes: 2 additions & 1 deletion [core]/es_extended/imports.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,10 @@ if GetResourceState("ox_lib") == "missing" then
return nil, err or 'unknown error'
end

---@diagnostic disable-next-line: duplicate-doc-alias
---@alias PackageSearcher
---| fun(modName: string): function loader
---| fun(modName: string): nil, string errmsg
---| fun(modName: string): nil|false, string errmsg

---@type PackageSearcher[]
package.searchers = {
Expand Down
322 changes: 147 additions & 175 deletions [core]/es_extended/server/classes/player.lua

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions [core]/es_extended/server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ end

---@param key? string
---@param val? string|table
---@return table
---@return xPlayer[]|table<any, xPlayer[]>
function ESX.GetExtendedPlayers(key, val)
if not key then
return ESX.Table.ToArray(ESX.Players)
Expand Down Expand Up @@ -348,13 +348,13 @@ function ESX.GetNumPlayers(key, val)
end

---@param source number
---@return table
---@return xPlayer?
function ESX.GetPlayerFromId(source)
return ESX.Players[tonumber(source)]
end

---@param identifier string
---@return table
---@return xPlayer?
function ESX.GetPlayerFromIdentifier(identifier)
return Core.playersByIdentifier[identifier]
end
Expand All @@ -367,16 +367,17 @@ end

---@param source number
---@return boolean
---@diagnostic disable-next-line: duplicate-set-field
function ESX.IsPlayerLoaded(source)
return ESX.Players[source] ~= nil
end

---@param playerId number | string
---@return string
---@return string, number
function ESX.GetIdentifier(playerId)
local fxDk = GetConvarInt("sv_fxdkMode", 0)
if fxDk == 1 then
return "ESX-DEBUG-LICENCE"
return "ESX-DEBUG-LICENCE", 0
end

playerId = tostring(playerId)
Expand Down
42 changes: 42 additions & 0 deletions [core]/es_extended/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,10 @@ if not Config.CustomInventory then
if itemType == "item_standard" then
local sourceItem = sourceXPlayer.getInventoryItem(itemName)

if not sourceItem then
return
end

if itemCount < 1 or sourceItem.count < itemCount then
return sourceXPlayer.showNotification(TranslateCap("imp_invalid_quantity"))
end
Expand Down Expand Up @@ -453,6 +457,10 @@ if not Config.CustomInventory then
end

local _, weapon = sourceXPlayer.getWeapon(itemName)
if not weapon then
return
end

local _, weaponObject = ESX.GetWeapon(itemName)
itemCount = weapon.ammo
local weaponComponents = ESX.Table.Clone(weapon.components)
Expand Down Expand Up @@ -485,6 +493,9 @@ if not Config.CustomInventory then
end

local _, weapon = sourceXPlayer.getWeapon(itemName)
if not weapon then
return
end

if not targetXPlayer.hasWeapon(itemName) then
sourceXPlayer.showNotification(TranslateCap("gave_weapon_noweapon", targetXPlayer.name))
Expand All @@ -511,12 +522,19 @@ if not Config.CustomInventory then
local playerId = source
local xPlayer = ESX.GetPlayerFromId(playerId)

if not xPlayer then
return
end

if itemType == "item_standard" then
if not itemCount or itemCount < 1 then
return xPlayer.showNotification(TranslateCap("imp_invalid_quantity"))
end

local xItem = xPlayer.getInventoryItem(itemName)
if not xItem then
return
end

if itemCount > xItem.count or xItem.count < 1 then
return xPlayer.showNotification(TranslateCap("imp_invalid_quantity"))
Expand All @@ -532,6 +550,9 @@ if not Config.CustomInventory then
end

local account = xPlayer.getAccount(itemName)
if not account then
return
end

if itemCount > account.money or account.money < 1 then
return xPlayer.showNotification(TranslateCap("imp_invalid_amount"))
Expand All @@ -547,6 +568,10 @@ if not Config.CustomInventory then
if not xPlayer.hasWeapon(itemName) then return end

local _, weapon = xPlayer.getWeapon(itemName)
if not weapon then
return
end

local _, weaponObject = ESX.GetWeapon(itemName)
-- luacheck: ignore weaponPickupLabel
local weaponPickupLabel = ""
Expand All @@ -569,6 +594,11 @@ if not Config.CustomInventory then
RegisterNetEvent("esx:useItem", function(itemName)
local source = source
local xPlayer = ESX.GetPlayerFromId(source)

if not xPlayer then
return
end

local count = xPlayer.getInventoryItem(itemName).count

if count < 1 then
Expand All @@ -581,6 +611,10 @@ if not Config.CustomInventory then
RegisterNetEvent("esx:onPickup", function(pickupId)
local pickup, xPlayer, success = Core.Pickups[pickupId], ESX.GetPlayerFromId(source)

if not xPlayer then
return
end

if not pickup then return end

local playerPickupDistance = #(pickup.coords - xPlayer.getCoords(true))
Expand Down Expand Up @@ -623,6 +657,10 @@ end
ESX.RegisterServerCallback("esx:getPlayerData", function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)

if not xPlayer then
return
end

cb({
identifier = xPlayer.identifier,
accounts = xPlayer.getAccounts(),
Expand All @@ -646,6 +684,10 @@ end)
ESX.RegisterServerCallback("esx:getOtherPlayerData", function(_, cb, target)
local xPlayer = ESX.GetPlayerFromId(target)

if not xPlayer then
return
end

cb({
identifier = xPlayer.identifier,
accounts = xPlayer.getAccounts(),
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/server/modules/callback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ end
---@param player number playerId
---@param eventName string
---@param ... any
---@return any
---@return ...
function ESX.AwaitClientCallback(player, eventName, ...)
local invokingResource = GetInvokingResource()
local invoker = (invokingResource and invokingResource ~= "Unknown") and invokingResource or "es_extended"
Expand Down
3 changes: 2 additions & 1 deletion [core]/es_extended/shared/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ end

---@param weaponName string
---@param weaponComponent string
---@return table | nil
---@return ESXWeaponComponent?
function ESX.GetWeaponComponent(weaponName, weaponComponent)
weaponName = string.upper(weaponName)

assert(weaponsByName[weaponName], "Invalid weapon name!")
local weapon = Config.Weapons[weaponsByName[weaponName]]

for _, component in ipairs(weapon.components) do
---@cast component ESXWeaponComponent
if component.name == weaponComponent then
return component
end
Expand Down
Loading