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

Feature: New hook: useItem #1709

Open
Alexr03 opened this issue May 20, 2024 · 6 comments
Open

Feature: New hook: useItem #1709

Alexr03 opened this issue May 20, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@Alexr03
Copy link

Alexr03 commented May 20, 2024

Is your feature request related to a problem? Please describe.
We have an arena system for players to do activities like 1v1s, we like to disable the players use of their inventory to prevent healing, putting armour on etc by using items in their inventory. Right now our only option is to disable use of the inventory all together. We tried to use invBusy state on the player, this works but has a side effect of no longer being able to shoot their weapon

DisablePlayerFiring(playerId, true)

We could disable this ourself but we're trying to keep ox_inventory as vanilla as possible to make updates easier.

This has led to the idea of making a useItem hook where we can return false if we want to stop the item from being used, then we can disable all items and setup a "whitelist" of allowed items that can be used while in the arena.

Describe the solution you'd like
Ability to create a hook for useItem that will allow us to cancel the request to use the item.
Example:

local hookId = exports.ox_inventory:registerHook('useItem', function(payload)
    print(json.encode(payload, { indent = true }))

    local playerState = Player(payload.source).state
    if (not playerState.inArena) then
        return
    end

    if (payload.itemName == 'water') then -- Only allow water to be used in arena, otherwise cancel the use.
        return
    end
    return false
end, {
    print = true,
})

Describe alternatives you've considered
(The alternatives below will prevent the inventory from opening and allowing weapon shooting, but won't allow us to dynamically cancel the useItem)

  • Remove/Comment code that disables shooting when invBusy is true.
  • Check every frame for if state invOpen is true, and then call export to closeInventory immediately.

Additional context
N/A

@Alexr03 Alexr03 added the enhancement New feature or request label May 20, 2024
@Demigod916
Copy link
Contributor

Demigod916 commented May 20, 2024

https://overextended.dev/ox_inventory/Functions/Client#weaponwheel

this will disable the inventory while allowing you to shoot still

exports.ox_inventory:weaponWheel(true)
GiveWeaponToPed(cache.ped, self.private.weapon, 9999, false, true)
SetCurrentPedWeapon(cache.ped, self.private.weapon, true)
SetPedInfiniteAmmo(cache.ped, true, self.private.weapon)
SetPedInfiniteAmmoClip(cache.ped, true)

here is an export from something ive useed it for. and then when the weaponwheel is disabled again, it will actually unequip the weapon given this way if they dont have it in their inventory. assuming you have the weapon mismatch checking on for the inventory

ultimately the hook here is not that useful since if you register item uses through the export callbacks you have access to all the different stages of item use already.

https://overextended.dev/ox_inventory/Guides/creatingItems#client-callbacks
https://overextended.dev/ox_inventory/Guides/creatingItems#server-callbacks

@Alexr03
Copy link
Author

Alexr03 commented May 20, 2024

That is what we currently do to give a temporary weapon.
Its my understanding that it will disable using weapons from the inventory, but will allow other items like bandages? At least this is how it works for us. (https://aka.x3.dev/s/HRjXNJe/raw it wont let us use a weapon, when weaponWheel is enabled, but can still use other items)

I see what you're saying with the callbacks, but surely a hook is better to define the logic in one place of what can/cannot be used rather than in each callback?

@Demigod916
Copy link
Contributor

Demigod916 commented May 20, 2024

The weaponwheel being active should completely disable the use of all items. At least thats what the description seems to imply on the docs

image

@Alexr03
Copy link
Author

Alexr03 commented May 20, 2024

Yes the docs imply it but code wise it only disable weapons being used as far as I can see.

if EnableWeaponWheel or not plyState.canUseWeapons then return end

Regardless I still think having a hook for useItem is a good addition.

@Demigod916
Copy link
Contributor

Interesting. I guess i can see the convenience of the hook in some cases then.

@Demigod916
Copy link
Contributor

836a0b2

Alexr03 added a commit to Alexr03/overextended.github.io that referenced this issue May 20, 2024
Right now the docs state that enabling the weaponWheel via export will disable the use of inventory items, as a user reading the docs I would assume that is all items but this is not the case. It only disables weapons from being used

Discussion: overextended/ox_inventory#1709
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants