mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 16:23:21 +00:00
Merge pull request #1111 from btwlouis/remove-weapon-rpc
Remove weapon using rpc
This commit is contained in:
@@ -332,9 +332,7 @@ if not Config.OxInventory then
|
|||||||
|
|
||||||
RegisterNetEvent('esx:removeWeapon')
|
RegisterNetEvent('esx:removeWeapon')
|
||||||
AddEventHandler('esx:removeWeapon', function(weapon)
|
AddEventHandler('esx:removeWeapon', function(weapon)
|
||||||
local playerPed = ESX.PlayerData.ped
|
print("[^1ERROR^7] event ^5'esx:removeWeapon'^7 Has Been Removed. Please use ^5xPlayer.removeWeapon^7 Instead!")
|
||||||
RemoveWeaponFromPed(playerPed, joaat(weapon))
|
|
||||||
SetPedAmmo(ESX.PlayerData.ped, joaat(weapon), 0)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('esx:removeWeaponComponent')
|
RegisterNetEvent('esx:removeWeaponComponent')
|
||||||
|
|||||||
@@ -460,7 +460,11 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
|||||||
end
|
end
|
||||||
|
|
||||||
function self.removeWeapon(weaponName)
|
function self.removeWeapon(weaponName)
|
||||||
local weaponLabel
|
local weaponLabel, playerPed = nil, GetPlayerPed(self.source)
|
||||||
|
|
||||||
|
if not playerPed then
|
||||||
|
return print("[^1ERROR^7] xPlayer.removeWeapon ^5invalid^7 player ped!")
|
||||||
|
end
|
||||||
|
|
||||||
for k, v in ipairs(self.loadout) do
|
for k, v in ipairs(self.loadout) do
|
||||||
if v.name == weaponName then
|
if v.name == weaponName then
|
||||||
@@ -469,6 +473,11 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
|||||||
for _, v2 in ipairs(v.components) do
|
for _, v2 in ipairs(v.components) do
|
||||||
self.removeWeaponComponent(weaponName, v2)
|
self.removeWeaponComponent(weaponName, v2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local weaponHash = joaat(v.name)
|
||||||
|
|
||||||
|
RemoveWeaponFromPed(playerPed, weaponHash)
|
||||||
|
SetPedAmmo(playerPed, weaponHash, 0)
|
||||||
|
|
||||||
table.remove(self.loadout, k)
|
table.remove(self.loadout, k)
|
||||||
break
|
break
|
||||||
@@ -476,7 +485,6 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
|||||||
end
|
end
|
||||||
|
|
||||||
if weaponLabel then
|
if weaponLabel then
|
||||||
self.triggerEvent('esx:removeWeapon', weaponName)
|
|
||||||
self.triggerEvent('esx:removeInventoryItem', weaponLabel, false, true)
|
self.triggerEvent('esx:removeInventoryItem', weaponLabel, false, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user