Skip to content

Commit

Permalink
Merge pull request #1424 from esx-framework/dev
Browse files Browse the repository at this point in the history
🔁 Dev -> main
  • Loading branch information
Arctos2win authored Oct 20, 2024
2 parents 2c14e5b + 6728540 commit c63620f
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 58 deletions.
2 changes: 1 addition & 1 deletion [core]/es_extended/client/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ end)

AddEventHandler("esx:getSharedObject", function()
local Invoke = GetInvokingResource()
print(("[^1ERROR^7] Resource ^5%s^7 Used the ^5getSharedObject^7 Event, this event ^1no longer exists!^7 Visit https://documentation.esx-framework.org/tutorials/tutorials-esx/sharedevent for how to fix!"):format(Invoke))
error(("Resource ^5%s^7 Used the ^5getSharedObject^7 Event, this event ^1no longer exists!^7 Visit https://documentation.esx-framework.org/tutorials/tutorials-esx/sharedevent for how to fix!"):format(Invoke))
end)
16 changes: 9 additions & 7 deletions [core]/es_extended/client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,13 @@ function ESX.RefreshContext(...)
end

function ESX.RegisterInput(command_name, label, input_group, key, on_press, on_release)
RegisterCommand(on_release and '+' .. command_name or command_name, on_press)
Core.Input[command_name] = ESX.HashString(command_name)
local command = on_release and '+' .. command_name or command_name
RegisterCommand(command, on_press)
Core.Input[command_name] = ESX.HashString(command)
if on_release then
RegisterCommand('-' .. command_name, on_release)
end
RegisterKeyMapping(command_name, label or '', input_group or 'keyboard', key or '')
RegisterKeyMapping(command, label or '', input_group or 'keyboard', key or '')
end

function ESX.UI.Menu.RegisterType(menuType, open, close)
Expand Down Expand Up @@ -321,7 +322,7 @@ function ESX.Game.Teleport(entity, coords, cb)
end

function ESX.Game.SpawnObject(object, coords, cb, networked)
local obj = CreateObject(ESX.Streaming.RequestModel(object), coords.x, coords.y. coords.z, networked == nil or networked, false, true)
local obj = CreateObject(ESX.Streaming.RequestModel(object), coords.x, coords.y, coords.z, networked == nil or networked, false, true)
return cb and cb(obj) or obj
end

Expand Down Expand Up @@ -352,7 +353,7 @@ function ESX.Game.SpawnVehicle(vehicleModel, coords, heading, cb, networked)
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(executingResource))
return error(("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()
Expand Down Expand Up @@ -491,8 +492,9 @@ end

function ESX.Game.RaycastScreen(depth, ...)
local world, normal = GetWorldCoordFromScreenCoord(.5, .5)
local origin = world + normal
local target = world + normal * depth
return target, ESX.Game.GetShapeTestResultAsync(StartShapeTestLosProbe(world + normal, target, ...))
return target, ESX.Game.GetShapeTestResultSync(StartShapeTestLosProbe(origin.x, origin.y, origin.z, target.x, target.y, target.z, ...))
end

function ESX.Game.GetClosestEntity(entities, isPlayerEntities, coords, modelFilter)
Expand All @@ -507,7 +509,7 @@ function ESX.Game.GetClosestEntity(entities, isPlayerEntities, coords, modelFilt

if modelFilter then
filteredEntities = {}

for currentEntityIndex = 1, #entities do
if modelFilter[GetEntityModel(entities[currentEntityIndex])] then
filteredEntities[#filteredEntities + 1] = entities[currentEntityIndex]
Expand Down
12 changes: 6 additions & 6 deletions [core]/es_extended/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function ESX.SpawnPlayer(skin, coords, cb)
while not HasCollisionLoadedAroundEntity(playerPed) and (GetGameTimer() - timer) < 5000 do
Wait(0)
end

NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z, coords.heading, true, true, false)
TriggerEvent('playerSpawned', coords)
cb()
Expand Down Expand Up @@ -337,17 +337,17 @@ if not Config.OxInventory then

RegisterNetEvent("esx:addWeapon")
AddEventHandler("esx:addWeapon", function()
print("[^1ERROR^7] event ^5'esx:addWeapon'^7 Has Been Removed. Please use ^5xPlayer.addWeapon^7 Instead!")
error("event ^5'esx:addWeapon'^7 Has Been Removed. Please use ^5xPlayer.addWeapon^7 Instead!")
end)

RegisterNetEvent("esx:addWeaponComponent")
AddEventHandler("esx:addWeaponComponent", function()
print("[^1ERROR^7] event ^5'esx:addWeaponComponent'^7 Has Been Removed. Please use ^5xPlayer.addWeaponComponent^7 Instead!")
error("event ^5'esx:addWeaponComponent'^7 Has Been Removed. Please use ^5xPlayer.addWeaponComponent^7 Instead!")
end)

RegisterNetEvent("esx:setWeaponAmmo")
AddEventHandler("esx:setWeaponAmmo", function()
print("[^1ERROR^7] event ^5'esx:setWeaponAmmo'^7 Has Been Removed. Please use ^5xPlayer.addWeaponAmmo^7 Instead!")
error("event ^5'esx:setWeaponAmmo'^7 Has Been Removed. Please use ^5xPlayer.addWeaponAmmo^7 Instead!")
end)

RegisterNetEvent("esx:setWeaponTint")
Expand All @@ -357,7 +357,7 @@ if not Config.OxInventory then

RegisterNetEvent("esx:removeWeapon")
AddEventHandler("esx:removeWeapon", function()
print("[^1ERROR^7] event ^5'esx:removeWeapon'^7 Has Been Removed. Please use ^5xPlayer.removeWeapon^7 Instead!")
error("event ^5'esx:removeWeapon'^7 Has Been Removed. Please use ^5xPlayer.removeWeapon^7 Instead!")
end)

RegisterNetEvent("esx:removeWeaponComponent")
Expand Down Expand Up @@ -721,4 +721,4 @@ end)

RegisterNetEvent('esx:updatePlayerData', function(key, val)
ESX.SetPlayerData(key, val)
end)
end)
4 changes: 2 additions & 2 deletions [core]/es_extended/client/modules/callback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end

RegisterNetEvent("esx:serverCallback", function(requestId, invoker, ...)
if not serverRequests[requestId] then
return print(("[^1ERROR^7] Server Callback with requestId ^5%s^7 Was Called by ^5%s^7 but does not exist."):format(requestId, invoker))
return error(("Server Callback with requestId ^5%s^7 Was Called by ^5%s^7 but does not exist."):format(requestId, invoker))
end

serverRequests[requestId](...)
Expand All @@ -31,7 +31,7 @@ end

RegisterNetEvent("esx:triggerClientCallback", function(eventName, requestId, invoker, ...)
if not clientCallbacks[eventName] then
return print(("[^1ERROR^7] Client Callback not registered, name: ^5%s^7, invoker resource: ^5%s^7"):format(eventName, invoker))
return error(("Client Callback not registered, name: ^5%s^7, invoker resource: ^5%s^7"):format(eventName, invoker))
end

clientCallbacks[eventName](function(...)
Expand Down
6 changes: 5 additions & 1 deletion [core]/es_extended/config.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Config = {}
Config.Locale = GetConvar("esx:locale", "en")

local txAdminLocale = GetConvar("txAdmin-locale", "en")
local esxLocale = GetConvar("esx:locale", "invalid")

Config.Locale = (esxLocale ~= "invalid") and esxLocale or (txAdminLocale ~= "custom" and txAdminLocale) or "en"

Config.OxInventory = GetResourceState("ox_inventory") ~= 'missing'

Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/locale.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Locales = {}

function Translate(str, ...) -- Translate string
if not str then
print(("[^1ERROR^7] Resource ^5%s^7 You did not specify a parameter for the Translate function or the value is nil!"):format(GetInvokingResource() or GetCurrentResourceName()))
error(("Resource ^5%s^7 You did not specify a parameter for the Translate function or the value is nil!"):format(GetInvokingResource() or GetCurrentResourceName()))
return "Given translate function parameter is nil!"
end
if Locales[Config.Locale] then
Expand Down
56 changes: 28 additions & 28 deletions [core]/es_extended/server/classes/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
function self.setAccountMoney(accountName, money, reason)
reason = reason or "unknown"
if not tonumber(money) then
print(("[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number -> ^5%s^7"):format(accountName, self.playerId, money))
error(("Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number -> ^5%s^7"):format(accountName, self.playerId, money))
return
end
if money >= 0 then
Expand All @@ -286,10 +286,10 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
self.triggerEvent("esx:setAccountMoney", account)
_TriggerEvent("esx:setAccountMoney", self.source, accountName, money, reason)
else
print(("[^1ERROR^7] Tried To Set Invalid Account ^5%s^0 For Player ^5%s^0!"):format(accountName, self.playerId))
error(("Tried To Set Invalid Account ^5%s^0 For Player ^5%s^0!"):format(accountName, self.playerId))
end
else
print(("[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number -> ^5%s^7"):format(accountName, self.playerId, money))
error(("Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number -> ^5%s^7"):format(accountName, self.playerId, money))
end
end

Expand All @@ -300,7 +300,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
function self.addAccountMoney(accountName, money, reason)
reason = reason or "Unknown"
if not tonumber(money) then
print(("[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number -> ^5%s^7"):format(accountName, self.playerId, money))
error(("Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number -> ^5%s^7"):format(accountName, self.playerId, money))
return
end
if money > 0 then
Expand All @@ -312,10 +312,10 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
self.triggerEvent("esx:setAccountMoney", account)
_TriggerEvent("esx:addAccountMoney", self.source, accountName, money, reason)
else
print(("[^1ERROR^7] Tried To Set Add To Invalid Account ^5%s^0 For Player ^5%s^0!"):format(accountName, self.playerId))
error(("Tried To Set Add To Invalid Account ^5%s^0 For Player ^5%s^0!"):format(accountName, self.playerId))
end
else
print(("[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number -> ^5%s^7"):format(accountName, self.playerId, money))
error(("Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number -> ^5%s^7"):format(accountName, self.playerId, money))
end
end

Expand All @@ -326,7 +326,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
function self.removeAccountMoney(accountName, money, reason)
reason = reason or "Unknown"
if not tonumber(money) then
print(("[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number -> ^5%s^7"):format(accountName, self.playerId, money))
error(("Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number -> ^5%s^7"):format(accountName, self.playerId, money))
return
end
if money > 0 then
Expand All @@ -335,18 +335,18 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
if account then
money = account.round and ESX.Math.Round(money) or money
if self.accounts[account.index].money - money > self.accounts[account.index].money then
print(("[^1ERROR^7] Tried To Underflow Account ^5%s^0 For Player ^5%s^0!"):format(accountName, self.playerId))
error(("Tried To Underflow Account ^5%s^0 For Player ^5%s^0!"):format(accountName, self.playerId))
return
end
self.accounts[account.index].money = self.accounts[account.index].money - money

self.triggerEvent("esx:setAccountMoney", account)
_TriggerEvent("esx:removeAccountMoney", self.source, accountName, money, reason)
else
print(("[^1ERROR^7] Tried To Set Add To Invalid Account ^5%s^0 For Player ^5%s^0!"):format(accountName, self.playerId))
error(("Tried To Set Add To Invalid Account ^5%s^0 For Player ^5%s^0!"):format(accountName, self.playerId))
end
else
print(("[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number -> ^5%s^7"):format(accountName, self.playerId, money))
error(("Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number -> ^5%s^7"):format(accountName, self.playerId, money))
end
end

Expand Down Expand Up @@ -396,7 +396,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
self.triggerEvent("esx:removeInventoryItem", item.name, item.count)
end
else
print(("[^1ERROR^7] Player ID:^5%s Tried remove a Invalid count -> %s of %s"):format(self.playerId, count, itemName))
error(("Player ID:^5%s Tried remove a Invalid count -> %s of %s"):format(self.playerId, count, itemName))
end
end
end
Expand Down Expand Up @@ -598,7 +598,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
local weaponLabel, playerPed <const> = nil, _GetPlayerPed(self.source)

if not playerPed then
return print("[^1ERROR^7] xPlayer.removeWeapon ^5invalid^7 player ped!")
return error("xPlayer.removeWeapon ^5invalid^7 player ped!")
end

for k, v in ipairs(self.loadout) do
Expand Down Expand Up @@ -755,12 +755,12 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end

if type(index) ~= "string" then
return print("[^1ERROR^7] xPlayer.getMeta ^5index^7 should be ^5string^7!")
return error("xPlayer.getMeta ^5index^7 should be ^5string^7!")
end

local metaData = self.metadata[index]
if metaData == nil then
return Config.EnableDebug and print(("[^1ERROR^7] xPlayer.getMeta ^5%s^7 not exist!"):format(index)) or nil
return Config.EnableDebug and error(("xPlayer.getMeta ^5%s^7 not exist!"):format(index)) or nil
end

if subIndex and type(metaData) == "table" then
Expand All @@ -779,14 +779,14 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
if type(key) == "string" then
returnValues[key] = self.getMeta(index, key)
else
print(("[^1ERROR^7] xPlayer.getMeta subIndex should be ^5string^7 or ^5table^7! that contains ^5string^7, received ^5%s^7!, skipping..."):format(type(key)))
error(("xPlayer.getMeta subIndex should be ^5string^7 or ^5table^7! that contains ^5string^7, received ^5%s^7!, skipping..."):format(type(key)))
end
end

return returnValues
end

return print(("[^1ERROR^7] xPlayer.getMeta subIndex should be ^5string^7 or ^5table^7!, received ^5%s^7!"):format(_type))
return error(("xPlayer.getMeta subIndex should be ^5string^7 or ^5table^7!, received ^5%s^7!"):format(_type))
end

return metaData
Expand All @@ -798,28 +798,28 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
---@return void
function self.setMeta(index, value, subValue)
if not index then
return print("[^1ERROR^7] xPlayer.setMeta ^5index^7 is Missing!")
return error("xPlayer.setMeta ^5index^7 is Missing!")
end

if type(index) ~= "string" then
return print("[^1ERROR^7] xPlayer.setMeta ^5index^7 should be ^5string^7!")
return error("xPlayer.setMeta ^5index^7 should be ^5string^7!")
end

if value == nil then
return print("[^1ERROR^7] xPlayer.setMeta value is missing!")
return error("xPlayer.setMeta value is missing!")
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))
return error(("xPlayer.setMeta ^5%s^7 should be ^5number^7 or ^5string^7 or ^5table^7!"):format(value))
end

self.metadata[index] = value
else
if _type ~= "string" then
return print(("[^1ERROR^7] xPlayer.setMeta ^5value^7 should be ^5string^7 as a subIndex!"):format(value))
return error(("xPlayer.setMeta ^5value^7 should be ^5string^7 as a subIndex!"):format(value))
end

if not self.metadata[index] or type(self.metadata[index]) ~= "table" then
Expand All @@ -834,16 +834,16 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,

function self.clearMeta(index, subValues)
if not index then
return print("[^1ERROR^7] xPlayer.clearMeta ^5index^7 is Missing!")
return error("xPlayer.clearMeta ^5index^7 is Missing!")
end

if type(index) ~= "string" then
return print("[^1ERROR^7] xPlayer.clearMeta ^5index^7 should be ^5string^7!")
return error("xPlayer.clearMeta ^5index^7 should be ^5string^7!")
end

local metaData = self.metadata[index]
if metaData == nil then
return Config.EnableDebug and print(("[^1ERROR^7] xPlayer.clearMeta ^5%s^7 does not exist!"):format(index)) or nil
return Config.EnableDebug and error(("xPlayer.clearMeta ^5%s^7 does not exist!"):format(index)) or nil
end

if not subValues then
Expand All @@ -854,7 +854,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
if type(metaData) == "table" then
metaData[subValues] = nil
else
return print(("[^1ERROR^7] xPlayer.clearMeta ^5%s^7 is not a table! Cannot clear subValue ^5%s^7."):format(index, subValues))
return error(("xPlayer.clearMeta ^5%s^7 is not a table! Cannot clear subValue ^5%s^7."):format(index, subValues))
end
elseif type(subValues) == "table" then
-- If subValues is a table, we will clear multiple subValues within the table
Expand All @@ -864,14 +864,14 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
if type(metaData) == "table" then
metaData[subValue] = nil
else
print(("[^1ERROR^7] xPlayer.clearMeta ^5%s^7 is not a table! Cannot clear subValue ^5%s^7."):format(index, subValue))
error(("xPlayer.clearMeta ^5%s^7 is not a table! Cannot clear subValue ^5%s^7."):format(index, subValue))
end
else
print(("[^1ERROR^7] xPlayer.clearMeta subValues should contain ^5string^7, received ^5%s^7, skipping..."):format(type(subValue)))
error(("xPlayer.clearMeta subValues should contain ^5string^7, received ^5%s^7, skipping..."):format(type(subValue)))
end
end
else
return print(("[^1ERROR^7] xPlayer.clearMeta ^5subValues^7 should be ^5string^7 or ^5table^7, received ^5%s^7!"):format(type(subValues)))
return error(("xPlayer.clearMeta ^5subValues^7 should be ^5string^7 or ^5table^7, received ^5%s^7!"):format(type(subValues)))
end
self.triggerEvent('esx:updatePlayerData', 'metadata', self.metadata)
end
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/server/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end)

AddEventHandler("esx:getSharedObject", function()
local Invoke = GetInvokingResource()
print(("[^1ERROR^7] Resource ^5%s^7 Used the ^5getSharedObject^7 Event, this event ^1no longer exists!^7 Visit https://documentation.esx-framework.org/tutorials/tutorials-esx/sharedevent for how to fix!"):format(Invoke))
error(("Resource ^5%s^7 Used the ^5getSharedObject^7 Event, this event ^1no longer exists!^7 Visit https://documentation.esx-framework.org/tutorials/tutorials-esx/sharedevent for how to fix!"):format(Invoke))
end)

exports("getSharedObject", function()
Expand Down
Loading

0 comments on commit c63620f

Please sign in to comment.