Ox Inventory

Please follow step by step to not get any errors

1. Modify Weapon Equip Behavior

Go to file:

ox_inventory/modules/weapon/client.lua

Instructions:

  1. Scroll to around line 18, then replace the entire function with the following code:

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

	if client.weaponanims and data.hash ~= `weapon_snowball` then
		if noWeaponAnim or (cache.vehicle and vehicleIsCycle(cache.vehicle)) then
			goto skipAnim
		end

		local anim = data.anim or anims[GetWeapontypeGroup(data.hash)]

		if anim == anims[`GROUP_PISTOL`] and not client.hasGroup(shared.police) then
			anim = nil
		end

		sleep = anim and anim[3] or 1200

		Utils.PlayAnimAdvanced(sleep, anim and anim[1] or 'reaction@intimidation@1h', anim and anim[2] or 'intro', coords.x, coords.y, coords.z, 0, 0, GetEntityHeading(playerPed), 8.0, 3.0, sleep*2, 50, 0.1)
	end

	::skipAnim::

	item.hash = data.hash
	item.ammo = data.ammoname
	item.melee = GetWeaponDamageType(data.hash) == 2 and 0
	item.timer = 0
	item.throwable = data.throwable
	item.group = GetWeapontypeGroup(item.hash)

	GiveWeaponToPed(playerPed, data.hash, 0, false, true)

	if item.metadata.tint then SetPedWeaponTintIndex(playerPed, data.hash, item.metadata.tint) end

	if item.metadata.components then
		for i = 1, #item.metadata.components do
			local components = Items[item.metadata.components[i]].client.component
			for v=1, #components do
				local component = components[v]
				if DoesWeaponTakeWeaponComponent(data.hash, component) then
					if not HasPedGotWeaponComponent(playerPed, data.hash, component) then
						GiveWeaponComponentToPed(playerPed, data.hash, component)
					end
				end
			end
		end
	end

	
	if item.metadata.specialAmmo then
		local clipComponentKey = ('%s_CLIP'):format(data.model:gsub('WEAPON_', 'COMPONENT_'))
		local specialClip = ('%s_%s'):format(clipComponentKey, item.metadata.specialAmmo:upper())

		if DoesWeaponTakeWeaponComponent(data.hash, specialClip) then
			GiveWeaponComponentToPed(playerPed, data.hash, specialClip)
		end
	end


	if data.hash == `weapon_snowball` then
		item.throwable = false
		local ammo = lib.callback.await('v-christmas:server:getSnowballCount')
		if ammo and ammo > 0 then
			SetCurrentPedWeapon(playerPed, data.hash, true)
			GiveWeaponToPed(playerPed, data.hash, ammo, false, true)
			SetPedAmmo(playerPed, data.hash, ammo)
			SetAmmoInClip(playerPed, data.hash, ammo)
			SetWeaponsNoAutoswap(true)
			SetPedCurrentWeaponVisible(playerPed, true, false, false, false)
			SetTimeout(0, function() RefillAmmoInstantly(playerPed) end)
		end
	else
		local ammo = item.metadata.ammo or item.throwable and 1 or 0
		SetCurrentPedWeapon(playerPed, data.hash, true)
		SetPedCurrentWeaponVisible(playerPed, true, false, false, false)
		SetWeaponsNoAutoswap(true)
		SetPedAmmo(playerPed, data.hash, ammo)
		SetTimeout(0, function() RefillAmmoInstantly(playerPed) end)
	end

	if item.group == `GROUP_PETROLCAN` or item.group == `GROUP_FIREEXTINGUISHER` then
		item.metadata.ammo = item.metadata.durability
		SetPedInfiniteAmmo(playerPed, true, data.hash)
	end

	TriggerEvent('ox_inventory:currentWeapon', item)

	if client.weaponnotify then
		Utils.ItemNotify({ item, 'ui_equipped' })
	end

	return item, sleep
end
  1. Scroll to around line 112, then replace the entire function with the following code:

This will get the amount of snowballs inside the inventory as well as remove the animation for pulling out and putting away snowballs


2. Prevent Snowball From Being Auto-Unequipped

Go to file:

ox_inventory/client.lua

Find:

RegisterNetEvent('ox_inventory:setPlayerInventory', function(currentDrops, inventory, weight, player)

Instructions:

Scroll to around line 1410 and replace the code with the following updated version:

This prevents ox_inventory from auto disarming when the players picks up snowballs.


3. Make Snowballs stack (optional)

Go to ox_inventory/data/weapons.lua Replace ['WEAPON_SNOWBALL'] with:


Done!

Save changes and restart server

Last updated