Skip to content

Commit

Permalink
Implement selling
Browse files Browse the repository at this point in the history
  • Loading branch information
Giana committed Feb 17, 2023
1 parent 5f4a51a commit 91bae9e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
15 changes: 3 additions & 12 deletions locales/en.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
local Translations = {
error = {

},
success = {

},
menu = {

},
button = {

not_enough = 'You do not have enough of: %{itemLabel}'
},
other = {

info = {
police_alert = 'Drug sale in progress'
}
}

Expand Down
49 changes: 49 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
local QBCore = exports['qb-core']:GetCoreObject()

-- Events --

RegisterNetEvent('g-drugselling:server:sell', function(sellLocation)
local src = source
local player = QBCore.Functions.GetPlayer(src)
for k, v in pairs(sellLocation.sellable_items) do
local hasItem = player.Functions.GetItemByName(k)
if hasItem then
if hasItem.amount >= v.sell_quantity then
local bundlesToSell = math.floor(hasItem.amount / v.sell_quantity)
local quantityToSell = bundlesToSell * v.sell_quantity
if player.Functions.RemoveItem(k, quantityToSell) then
for k2, v2 in pairs(v.rewards) do
local isMoneyType = false
for k3, v3 in pairs(QBConfig.Money.MoneyTypes) do
if tostring(k3) == k2 then
isMoneyType = true
end
end
if isMoneyType then
if not player.Functions.AddMoney(k2, v2) then
player.Functions.AddItem(k, quantityToSell)
return
end
else
if not player.Functions.AddItem(k2, v2) then
player.Functions.AddItem(k, quantityToSell)
return
end
if sellLocation.itemNotificationsEnabled then
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[k2], 'add', v2)
end
end
end
local notifyPoliceRoll = math.random(1, 100)
if notifyPoliceRoll <= sellLocation.policeAlertChance then
TriggerServerEvent('police:server:policeAlert', Lang:t('info.police_alert'))
end
end
else
if sellLocation.notificationsEnabled then
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_enough', { itemLabel = QBCore.Shared.Items[k]['label'] }), 'error')
end
end
end
end
end)

0 comments on commit 91bae9e

Please sign in to comment.