RegisterNetEvent('qb-weapons:client:UseWeapon', function(weaponData, shootbool)
local ped = PlayerPedId()
local weaponName = tostring(weaponData.name)
local weaponHash = joaat(weaponData.name)
if currentWeapon == weaponName then
TriggerEvent('qb-weapons:client:DrawWeapon', nil)
SetCurrentPedWeapon(ped, `WEAPON_UNARMED`, true)
RemoveAllPedWeapons(ped, true)
TriggerEvent('qb-weapons:client:SetCurrentWeapon', nil, shootbool)
currentWeapon = nil
elseif weaponName == 'weapon_stickybomb' or weaponName == 'weapon_pipebomb' or weaponName == 'weapon_smokegrenade' or weaponName == 'weapon_flare' or weaponName == 'weapon_proxmine' or weaponName == 'weapon_ball' or weaponName == 'weapon_molotov' or weaponName == 'weapon_grenade' or weaponName == 'weapon_bzgas' then
TriggerEvent('qb-weapons:client:DrawWeapon', weaponName)
GiveWeaponToPed(ped, weaponHash, 1, false, false)
SetPedAmmo(ped, weaponHash, 1)
SetCurrentPedWeapon(ped, weaponHash, true)
TriggerEvent('qb-weapons:client:SetCurrentWeapon', weaponData, shootbool)
currentWeapon = weaponName
elseif weaponName == 'weapon_snowball' then
local weaponHash = GetHashKey(weaponName)
local amount = lib.callback.await('v-christmas:server:getSnowballCount')
if amount and amount > 0 then
TriggerEvent('qb-weapons:client:DrawWeapon', weaponName)
GiveWeaponToPed(ped, weaponHash, amount, false, false)
SetPedAmmo(ped, weaponHash, amount)
SetCurrentPedWeapon(ped, weaponHash, true)
TriggerEvent('qb-weapons:client:SetCurrentWeapon', weaponData, shootbool)
currentWeapon = weaponName
end
else
TriggerEvent('qb-weapons:client:DrawWeapon', weaponName)
TriggerEvent('qb-weapons:client:SetCurrentWeapon', weaponData, shootbool)
local ammo = tonumber(weaponData.info.ammo) or 0
if weaponName == 'weapon_petrolcan' or weaponName == 'weapon_fireextinguisher' then
ammo = 4000
end
GiveWeaponToPed(ped, weaponHash, ammo, false, false)
SetPedAmmo(ped, weaponHash, ammo)
SetCurrentPedWeapon(ped, weaponHash, true)
if weaponData.info.attachments then
for _, attachment in pairs(weaponData.info.attachments) do
GiveWeaponComponentToPed(ped, weaponHash, joaat(attachment.component))
end
end
if weaponData.info.tint then
SetPedWeaponTintIndex(ped, weaponHash, weaponData.info.tint)
end
currentWeapon = weaponName
end
end)
QBCore.Functions.CreateCallback('prison:server:checkThrowable', function(source, cb, weapon)
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return cb(false) end
local throwable = false
for _, v in pairs(Config.Throwables) do
if QBCore.Shared.Weapons[weapon].name == 'weapon_' .. v and not QBCore.Shared.Weapons[weapon].name == 'weapon_snowball' then
if not exports['qb-inventory']:RemoveItem(source, 'weapon_' .. v, 1, false, 'prison:server:checkThrowable') then return cb(false) end
throwable = true
break
end
end
cb(throwable)
end)