Skip to content

Commit

Permalink
refactor: replace client-side event with server-side RemoveWeaponComp…
Browse files Browse the repository at this point in the history
…onentFromPed native
  • Loading branch information
btwlouis committed Jan 16, 2025
1 parent e855be0 commit d92bb95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 2 additions & 3 deletions [core]/es_extended/client/modules/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ if not Config.CustomInventory then
end)

ESX.SecureNetEvent("esx:removeWeaponComponent", function(weapon, weaponComponent)
local componentHash = ESX.GetWeaponComponent(weapon, weaponComponent).hash
RemoveWeaponComponentFromPed(ESX.PlayerData.ped, joaat(weapon), componentHash)
error("event ^5'esx:removeWeaponComponent'^1 Has Been Removed. Please use ^5xPlayer.removeWeaponComponent^1 Instead!")
end)
end

Expand Down Expand Up @@ -582,7 +581,7 @@ ESX.RegisterClientCallback("esx:GetVehicleType", function(cb, model)
end)

ESX.SecureNetEvent('esx:updatePlayerData', function(key, val)
ESX.SetPlayerData(key, val)
ESX.SetPlayerData(key, val)
end)

AddEventHandler("onResourceStop", function(resource)
Expand Down
9 changes: 8 additions & 1 deletion [core]/es_extended/server/classes/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,11 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
---@return nil
function self.removeWeaponComponent(weaponName, weaponComponent)
local loadoutNum <const>, weapon <const> = self.getWeapon(weaponName)
local playerPed <const> = GetPlayerPed(self.source)

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

if weapon then
local component <const> = ESX.GetWeaponComponent(weaponName, weaponComponent)
Expand All @@ -700,8 +705,10 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end

self.triggerEvent("esx:removeWeaponComponent", weaponName, weaponComponent)
self.triggerEvent("esx:removeInventoryItem", component.label, false, true)

local componentHash = component.hash
RemoveWeaponComponentFromPed(playerPed, joaat(weapon.name), componentHash)
end
end
end
Expand Down

0 comments on commit d92bb95

Please sign in to comment.