Skip to content

Commit

Permalink
feat: add useSlot item anim skip (#1614)
Browse files Browse the repository at this point in the history
  • Loading branch information
Demigod916 committed Feb 29, 2024
1 parent 52d9928 commit 91f74cb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ local Items = require 'modules.items.client'
local usingItem = false

---@param data { name: string, label: string, count: number, slot: number, metadata: table<string, any>, weight: number }
lib.callback.register('ox_inventory:usingItem', function(data)
lib.callback.register('ox_inventory:usingItem', function(data, noAnim)
local item = Items[data.name]

if item and usingItem then
Expand Down Expand Up @@ -368,7 +368,7 @@ lib.callback.register('ox_inventory:usingItem', function(data)
item.disable.combat = true
end

local success = (not item.usetime or lib.progressBar({
local success = (not item.usetime or noAnim or lib.progressBar({
duration = item.usetime,
label = item.label or locale('using', data.metadata.label or data.label),
useWhileDead = item.useWhileDead,
Expand Down Expand Up @@ -409,7 +409,8 @@ end

---@param data table
---@param cb fun(response: SlotWithItem | false)?
local function useItem(data, cb)
---@param noAnim boolean
local function useItem(data, cb, noAnim)
local slotData, result = PlayerData.inventory[data.slot]

if not slotData or not canUseItem(data.ammo and true) then return end
Expand All @@ -420,7 +421,7 @@ local function useItem(data, cb)

usingItem = true
---@type boolean?
result = lib.callback.await('ox_inventory:useItem', 200, data.name, data.slot, slotData.metadata)
result = lib.callback.await('ox_inventory:useItem', 200, data.name, data.slot, slotData.metadata, noAnim)

if result and cb then
local success, response = pcall(cb, result and slotData)
Expand All @@ -447,7 +448,7 @@ exports('useItem', useItem)

---@param slot number
---@return boolean?
local function useSlot(slot)
local function useSlot(slot, noAnim)
local item = PlayerData.inventory[slot]
if not item then return end

Expand Down Expand Up @@ -514,11 +515,11 @@ local function useSlot(slot)
useItem(data, function(result)
if result then
local sleep
currentWeapon, sleep = Weapon.Equip(item, data)
currentWeapon, sleep = Weapon.Equip(item, data, noAnim)

if sleep then Wait(sleep) end
end
end)
end, noAnim)
elseif currentWeapon then
if data.ammo then
if EnableWeaponWheel or currentWeapon.metadata.durability <= 0 then return end
Expand Down
4 changes: 2 additions & 2 deletions modules/weapon/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ local function vehicleIsCycle(vehicle)
return class == 8 or class == 13
end

function Weapon.Equip(item, data)
function Weapon.Equip(item, data, noWeaponAnim)
local playerPed = cache.ped
local coords = GetEntityCoords(playerPed, true)
local sleep

if client.weaponanims then
if cache.vehicle and vehicleIsCycle(cache.vehicle) then
if noWeaponAnim or (cache.vehicle and vehicleIsCycle(cache.vehicle)) then
goto skipAnim
end

Expand Down
4 changes: 2 additions & 2 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ end)
---@param slot number?
---@param metadata { [string]: any }?
---@return table | boolean | nil
lib.callback.register('ox_inventory:useItem', function(source, itemName, slot, metadata)
lib.callback.register('ox_inventory:useItem', function(source, itemName, slot, metadata, noAnim)
local inventory = Inventory(source) --[[@as OxInventory]]

if inventory.player then
Expand Down Expand Up @@ -366,7 +366,7 @@ lib.callback.register('ox_inventory:useItem', function(source, itemName, slot, m
data.consume = consume

---@type boolean
local success = lib.callback.await('ox_inventory:usingItem', source, data)
local success = lib.callback.await('ox_inventory:usingItem', source, data, noAnim)

if item.weapon then
inventory.weapon = success and slot or nil
Expand Down

0 comments on commit 91f74cb

Please sign in to comment.