Skip to content

Commit

Permalink
fix: drop items player cannot carry on the ground (#20)
Browse files Browse the repository at this point in the history
* fix for overweight item carry and custom item drop

* fix reward_dropped notification

* check if customDropItems is not empty.

* removed config option for custom drops

* removed config option for custom drops

* fix lint error

---------

Co-authored-by: Manason <[email protected]>
  • Loading branch information
Virus18sp and Manason authored Jun 3, 2024
1 parent a4cdc79 commit fbbd5ca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ return {
[`weapon_heavyrifle`] = true,
[`weapon_tacticalrifle`] = true,
},
}
}
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"noweapon": "You don't have a weapon in hand",
"noitem": "You don't have an %s with you",
"police": "Vangelico Store robbery reported",
"nopolice": "Not Enough Police (%s Required)"
"nopolice": "Not Enough Police (%s Required)",
"reward_dropped": "You dropped some jewels"
}
}
17 changes: 14 additions & 3 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ local function fireAlarm()
end

RegisterNetEvent('qbx_jewelery:server:endcabinet', function()
local player = exports.qbx_core:GetPlayer(source)
local playerCoords = GetEntityCoords(GetPlayerPed(source))
local closestVitrine = startedVitrine[source]

Expand All @@ -109,9 +108,21 @@ RegisterNetEvent('qbx_jewelery:server:endcabinet', function()
sharedConfig.vitrines[closestVitrine].isBusy = false
startedVitrine[source] = nil

local customDropItems = {}
for _ = 1, math.random(config.reward.minAmount, config.reward.maxAmount) do
local RandomItem = config.reward.items[math.random(1, #config.reward.items)]
player.Functions.AddItem(RandomItem.name, math.random(RandomItem.min, RandomItem.max))
local quantity = math.random(RandomItem.min, RandomItem.max)

if exports.ox_inventory:CanCarryItem(source, RandomItem.name, quantity) then
exports.ox_inventory:AddItem(source, RandomItem.name, quantity)
else
customDropItems[#customDropItems+1] = {RandomItem.name, quantity}
end
end

if #customDropItems > 0 then
exports.ox_inventory:CustomDrop('jewelery', customDropItems, playerCoords)
exports.qbx_core:Notify(source, locale('notify.reward_dropped'), 'warning')
end

TriggerClientEvent('qbx_jewelery:client:syncconfig', -1, sharedConfig.vitrines)
Expand Down Expand Up @@ -139,4 +150,4 @@ end)

AddEventHandler('playerJoining', function(source)
TriggerClientEvent('qbx_jewelery:client:syncconfig', source, sharedConfig.vitrines)
end)
end)

0 comments on commit fbbd5ca

Please sign in to comment.