Skip to content

Commit

Permalink
Handle armor on server
Browse files Browse the repository at this point in the history
  • Loading branch information
GhzGarage committed Nov 29, 2023
1 parent 57ebf25 commit d1318cb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 53 deletions.
5 changes: 0 additions & 5 deletions client/consumables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,7 @@ RegisterNetEvent('consumables:client:UseArmor', function()
disableMouse = false,
disableCombat = true,
}, {}, {}, {}, function() -- Done
TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items['armor'], 'remove')
TriggerServerEvent('hospital:server:SetArmor', 75)
TriggerServerEvent('consumables:server:useArmor')
SetPedArmour(PlayerPedId(), 75)
end)
end)

Expand Down Expand Up @@ -477,9 +474,7 @@ RegisterNetEvent('consumables:client:UseHeavyArmor', function()
SetPedComponentVariation(ped, 9, 30, 0, 2)
end
end
TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items['heavyarmor'], 'remove')
TriggerServerEvent('consumables:server:useHeavyArmor')
SetPedArmour(ped, 100)
end)
end)

Expand Down
102 changes: 54 additions & 48 deletions server/consumables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local QBCore = exports['qb-core']:GetCoreObject()

for k, _ in pairs(Config.Consumables.alcohol) do
QBCore.Functions.CreateUseableItem(k, function(source, item)
TriggerClientEvent("consumables:client:DrinkAlcohol", source, item.name)
TriggerClientEvent('consumables:client:DrinkAlcohol', source, item.name)
end)
end

Expand All @@ -13,7 +13,7 @@ for k, _ in pairs(Config.Consumables.eat) do
QBCore.Functions.CreateUseableItem(k, function(source, item)
local Player = QBCore.Functions.GetPlayer(source)
if not Player.Functions.RemoveItem(item.name, 1, item.slot) then return end
TriggerClientEvent("consumables:client:Eat", source, item.name)
TriggerClientEvent('consumables:client:Eat', source, item.name)
end)
end

Expand All @@ -22,7 +22,7 @@ for k, _ in pairs(Config.Consumables.drink) do
QBCore.Functions.CreateUseableItem(k, function(source, item)
local Player = QBCore.Functions.GetPlayer(source)
if not Player.Functions.RemoveItem(item.name, 1, item.slot) then return end
TriggerClientEvent("consumables:client:Drink", source, item.name)
TriggerClientEvent('consumables:client:Drink', source, item.name)
end)
end

Expand All @@ -31,101 +31,101 @@ for k, _ in pairs(Config.Consumables.custom) do
QBCore.Functions.CreateUseableItem(k, function(source, item)
local Player = QBCore.Functions.GetPlayer(source)
if not Player.Functions.RemoveItem(item.name, 1, item.slot) then return end
TriggerClientEvent("consumables:client:Custom", source, item.name)
TriggerClientEvent('consumables:client:Custom', source, item.name)
end)
end

local function createItem(name, type)
QBCore.Functions.CreateUseableItem(name, function(source, item)
local Player = QBCore.Functions.GetPlayer(source)
if not Player.Functions.RemoveItem(item.name, 1, item.slot) then return end
TriggerClientEvent("consumables:client:"..type, source, item.name)
TriggerClientEvent('consumables:client:' .. type, source, item.name)
end)
end
----------- / Drug

QBCore.Functions.CreateUseableItem("joint", function(source, item)
QBCore.Functions.CreateUseableItem('joint', function(source, item)
local Player = QBCore.Functions.GetPlayer(source)
if not Player.Functions.RemoveItem(item.name, 1, item.slot) then return end
TriggerClientEvent("consumables:client:UseJoint", source)
TriggerClientEvent('consumables:client:UseJoint', source)
end)

QBCore.Functions.CreateUseableItem("cokebaggy", function(source)
TriggerClientEvent("consumables:client:Cokebaggy", source)
QBCore.Functions.CreateUseableItem('cokebaggy', function(source)
TriggerClientEvent('consumables:client:Cokebaggy', source)
end)

QBCore.Functions.CreateUseableItem("crack_baggy", function(source)
TriggerClientEvent("consumables:client:Crackbaggy", source)
QBCore.Functions.CreateUseableItem('crack_baggy', function(source)
TriggerClientEvent('consumables:client:Crackbaggy', source)
end)

QBCore.Functions.CreateUseableItem("xtcbaggy", function(source)
TriggerClientEvent("consumables:client:EcstasyBaggy", source)
QBCore.Functions.CreateUseableItem('xtcbaggy', function(source)
TriggerClientEvent('consumables:client:EcstasyBaggy', source)
end)

QBCore.Functions.CreateUseableItem("oxy", function(source)
TriggerClientEvent("consumables:client:oxy", source)
QBCore.Functions.CreateUseableItem('oxy', function(source)
TriggerClientEvent('consumables:client:oxy', source)
end)

QBCore.Functions.CreateUseableItem("meth", function(source)
TriggerClientEvent("consumables:client:meth", source)
QBCore.Functions.CreateUseableItem('meth', function(source)
TriggerClientEvent('consumables:client:meth', source)
end)

----------- / Tools

QBCore.Functions.CreateUseableItem("armor", function(source)
TriggerClientEvent("consumables:client:UseArmor", source)
QBCore.Functions.CreateUseableItem('armor', function(source)
TriggerClientEvent('consumables:client:UseArmor', source)
end)

QBCore.Functions.CreateUseableItem("heavyarmor", function(source)
TriggerClientEvent("consumables:client:UseHeavyArmor", source)
QBCore.Functions.CreateUseableItem('heavyarmor', function(source)
TriggerClientEvent('consumables:client:UseHeavyArmor', source)
end)

QBCore.Commands.Add("resetarmor", "Resets Vest (Police Only)", {}, false, function(source)
QBCore.Commands.Add('resetarmor', 'Resets Vest (Police Only)', {}, false, function(source)
local Player = QBCore.Functions.GetPlayer(source)
if Player.PlayerData.job.name == "police" then
TriggerClientEvent("consumables:client:ResetArmor", source)
if Player.PlayerData.job.name == 'police' then
TriggerClientEvent('consumables:client:ResetArmor', source)
else
TriggerClientEvent('QBCore:Notify', source, "For Police Officer Only", "error")
TriggerClientEvent('QBCore:Notify', source, 'For Police Officer Only', 'error')
end
end)

QBCore.Functions.CreateUseableItem("binoculars", function(source)
TriggerClientEvent("binoculars:Toggle", source)
QBCore.Functions.CreateUseableItem('binoculars', function(source)
TriggerClientEvent('binoculars:Toggle', source)
end)

QBCore.Functions.CreateUseableItem("parachute", function(source, item)
QBCore.Functions.CreateUseableItem('parachute', function(source, item)
local Player = QBCore.Functions.GetPlayer(source)
if not Player.Functions.RemoveItem(item.name, 1, item.slot) then return end
TriggerClientEvent("consumables:client:UseParachute", source)
TriggerClientEvent('consumables:client:UseParachute', source)
end)

QBCore.Commands.Add("resetparachute", "Resets Parachute", {}, false, function(source)
TriggerClientEvent("consumables:client:ResetParachute", source)
QBCore.Commands.Add('resetparachute', 'Resets Parachute', {}, false, function(source)
TriggerClientEvent('consumables:client:ResetParachute', source)
end)

RegisterNetEvent('qb-smallpenis:server:AddParachute', function()
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return end
Player.Functions.AddItem("parachute", 1)
Player.Functions.AddItem('parachute', 1)
end)

----------- / Firework

for _, v in pairs(Config.Fireworks.items) do
QBCore.Functions.CreateUseableItem(v, function(source, item)
local src = source
TriggerClientEvent("fireworks:client:UseFirework", src, item.name, "proj_indep_firework")
TriggerClientEvent('fireworks:client:UseFirework', src, item.name, 'proj_indep_firework')
end)
end

----------- / Lockpicking

QBCore.Functions.CreateUseableItem("lockpick", function(source)
TriggerClientEvent("lockpicks:UseLockpick", source, false)
QBCore.Functions.CreateUseableItem('lockpick', function(source)
TriggerClientEvent('lockpicks:UseLockpick', source, false)
end)

QBCore.Functions.CreateUseableItem("advancedlockpick", function(source)
TriggerClientEvent("lockpicks:UseLockpick", source, true)
QBCore.Functions.CreateUseableItem('advancedlockpick', function(source)
TriggerClientEvent('lockpicks:UseLockpick', source, true)
end)

-- Events for adding and removing specific items to fix some exploits
Expand All @@ -139,13 +139,19 @@ end)
RegisterNetEvent('consumables:server:useHeavyArmor', function()
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return end
Player.Functions.RemoveItem('heavyarmor', 1)
if not Player.Functions.RemoveItem('heavyarmor', 1) then return end
TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['heavyarmor'], 'remove')
TriggerClientEvent('hospital:server:SetArmor', source, 100)
SetPedArmour(GetPlayerPed(source), 100)
end)

RegisterNetEvent('consumables:server:useArmor', function()
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return end
Player.Functions.RemoveItem('armor', 1)
if not Player.Functions.RemoveItem('armor', 1) then return end
TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['armor'], 'remove')
TriggerClientEvent('hospital:server:SetArmor', source, 75)
SetPedArmour(GetPlayerPed(source), 75)
end)

RegisterNetEvent('consumables:server:useMeth', function()
Expand Down Expand Up @@ -234,11 +240,11 @@ end)
---@return boolean, string
local function addDrink(drinkName, replenish)
if Config.Consumables.drink[drinkName] ~= nil then
return false, "already added"
return false, 'already added'
else
Config.Consumables.drink[drinkName] = replenish
createItem(drinkName, 'Drink')
return true, "success"
return true, 'success'
end
end

Expand All @@ -250,11 +256,11 @@ exports('AddDrink', addDrink)
---@return boolean, string
local function addFood(foodName, replenish)
if Config.Consumables.eat[foodName] ~= nil then
return false, "already added"
return false, 'already added'
else
Config.Consumables.eat[foodName] = replenish
createItem(foodName, 'Eat')
return true, "success"
return true, 'success'
end
end

Expand All @@ -266,11 +272,11 @@ exports('AddFood', addFood)
---@return boolean, string
local function addAlcohol(alcoholName, replenish)
if Config.Consumables.alcohol[alcoholName] ~= nil then
return false, "already added"
return false, 'already added'
else
Config.Consumables.alcohol[alcoholName] = replenish
createItem(alcoholName, 'DrinkAlcohol')
return true, "success"
return true, 'success'
end
end

Expand All @@ -282,12 +288,12 @@ exports('AddAlcohol', addAlcohol)
---@return boolean, string
local function addCustom(itemName, data)
if 'consumables:itemdata' ~= nil then
return false, "already added"
return false, 'already added'
else
Config.Consumables.custom[itemName] = data
createItem(itemName, 'Custom')
return true, "success"
return true, 'success'
end
end

exports('AddCustom', addCustom)
exports('AddCustom', addCustom)

0 comments on commit d1318cb

Please sign in to comment.