Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with using melee and weapon in ox_inventory #1825

Open
xnooztvFR opened this issue Oct 23, 2024 · 2 comments
Open

Problem with using melee and weapon in ox_inventory #1825

xnooztvFR opened this issue Oct 23, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@xnooztvFR
Copy link

Describe the bug
I am experiencing issues with certain weapons in the ox_inventory. When I attempt to equip melee weapons (such as knives or bats) and certain weapons (like weapon_smg_mk2), I receive an error message in the console stating that these weapons cannot be used in the current context (WEAPON_XXX cannot be used in current context (default game behaviour). As a result, the weapons are automatically removed from the inventory, preventing their usage.

Framework
ESX

Resource version
2.42.3

To Reproduce
Steps to reproduce the behavior:

  1. Open the inventory.
  2. Attempt to equip a melee weapon (e.g., knife, bat) or the weapon_smg_mk2.
  3. See the error message in the console: "WEAPON_XXX cannot be used in current context (default game behaviour)".
  4. The weapon gets removed from the inventory and cannot be used.

Expected behavior
I expected to be able to equip and use the melee weapons and the weapon_smg_mk2 without any issues.

Screenshots
Currently, I do not have screenshots to provide.

Additional context
I have verified that other weapons (like pistols and rifles) work correctly without issues. The affected weapons are defined correctly in the database. If there are any configurations or settings that I need to check, please advise.

@xnooztvFR xnooztvFR added the bug Something isn't working label Oct 23, 2024
@xnooztvFR xnooztvFR changed the title Issue: Problem with Using Melee and Certain Firearm Weapons in ox_inventory problem with using melee and weapon in ox_inventory Oct 23, 2024
@xnooztvFR xnooztvFR changed the title problem with using melee and weapon in ox_inventory Problem with using melee and weapon in ox_inventory Oct 23, 2024
@thelindat
Copy link
Member

thelindat commented Oct 24, 2024

the weapons are automatically removed from the inventory

?????????

This error is literally just the weapon either being forcibly removed by the game or failing to be equipped in the first place because they cannot be used, per the game. There's nothing deleting the items or explicitly disabling those items as part of the resource.

ox_inventory/client.lua

Lines 529 to 535 in c0abafb

GiveWeaponToPed(playerPed, data.hash, 0, false, true)
SetCurrentPedWeapon(playerPed, data.hash, false)
if data.hash ~= GetSelectedPedWeapon(playerPed) then
lib.print.info(('%s cannot be used in current context (default game behaviour)'):format(item.name))
return lib.notify({ type = 'error', description = locale('cannot_use', data.label) })
end

ox_inventory/client.lua

Lines 1388 to 1406 in c0abafb

local weaponHash = GetSelectedPedWeapon(playerPed)
if currentWeapon then
if weaponHash ~= currentWeapon.hash and currentWeapon.timer then
local weaponCount = Items[currentWeapon.name]?.count
if weaponCount > 0 then
SetCurrentPedWeapon(playerPed, currentWeapon.hash, true)
SetAmmoInClip(playerPed, currentWeapon.hash, currentWeapon.metadata.ammo)
SetPedCurrentWeaponVisible(playerPed, true, false, false, false)
weaponHash = GetSelectedPedWeapon(playerPed)
end
if weaponHash ~= currentWeapon.hash then
lib.print.info(('%s cannot be used in current context (default game behaviour)'):format(currentWeapon.name))
currentWeapon = Weapon.Disarm(currentWeapon, true)
end
end

@xnooztvFR
Copy link
Author

Indeed, the weapon is not removed from the inventory, but it is holstered in the inventory. However, I don't understand why this happens with certain weapons (for example, WEAPON_KNIFE and WEAPON_SMG_MK2). Is there a solution?"

the weapons are automatically removed from the inventory

?????????

This error is literally just the weapon either being forcibly removed by the game or failing to be equipped in the first place because they cannot be used, per the game. There's nothing deleting the items or explicitly disabling those items as part of the resource.

ox_inventory/client.lua

Lines 529 to 535 in c0abafb

GiveWeaponToPed(playerPed, data.hash, 0, false, true)
SetCurrentPedWeapon(playerPed, data.hash, false)
if data.hash ~= GetSelectedPedWeapon(playerPed) then
lib.print.info(('%s cannot be used in current context (default game behaviour)'):format(item.name))
return lib.notify({ type = 'error', description = locale('cannot_use', data.label) })
end

ox_inventory/client.lua

Lines 1388 to 1406 in c0abafb

local weaponHash = GetSelectedPedWeapon(playerPed)
if currentWeapon then
if weaponHash ~= currentWeapon.hash and currentWeapon.timer then
local weaponCount = Items[currentWeapon.name]?.count
if weaponCount > 0 then
SetCurrentPedWeapon(playerPed, currentWeapon.hash, true)
SetAmmoInClip(playerPed, currentWeapon.hash, currentWeapon.metadata.ammo)
SetPedCurrentWeaponVisible(playerPed, true, false, false, false)
weaponHash = GetSelectedPedWeapon(playerPed)
end
if weaponHash ~= currentWeapon.hash then
lib.print.info(('%s cannot be used in current context (default game behaviour)'):format(currentWeapon.name))
currentWeapon = Weapon.Disarm(currentWeapon, true)
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants