Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion modules/compatibility/frameworks/esx/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local ESX = GetResourceState('es_extended'):find('start') and exports['es_extend
if not ESX then return end

Framework = {}
medicalBags = medicalBags or {}
local useOxInventory = lib.load("config").useOxInventory
local ox_inventory = useOxInventory and exports.ox_inventory

Expand Down Expand Up @@ -34,6 +35,13 @@ function Framework.playerJob(target)
return xPlayer.job.name
end

function Framework.getPlayerJobGrade(target)
local xPlayer = ESX.GetPlayerFromId(target)
if not xPlayer then return end

return xPlayer.job.grade
end

function Framework.updateStatus(data)
local xPlayer = ESX.GetPlayerFromId(data.target)

Expand Down Expand Up @@ -72,13 +80,23 @@ function Framework.getDeathStatus(target)
return data
end

local moneyTypes = {
money = 'money',
cash = 'cash',
bank = 'bank',
black_money = 'black_money',
}

function Framework.addItem(target, item, amount)
if ox_inventory then
return ox_inventory:AddItem(target, item, amount)
end

local xPlayer = ESX.GetPlayerFromId(target)
if not xPlayer then return end
if moneyTypes[item] then
return xPlayer.addMoney(amount)
end
return xPlayer.addInventoryItem(item, amount)
end

Expand All @@ -89,6 +107,9 @@ function Framework.removeItem(target, item, amount)

local xPlayer = ESX.GetPlayerFromId(target)
if not xPlayer then return end
if moneyTypes[item] then
return xPlayer.removeMoney(amount)
end
return xPlayer.removeInventoryItem(item, amount)
end

Expand All @@ -114,14 +135,42 @@ function Framework.wipeInventory(target, keep)
end
end

function Framework.hasItem(target, item, amount)
local quantity = amount or 1

if ox_inventory then
local count = ox_inventory:Search(target, 'count', item)
return count and count >= quantity
end

local xPlayer = ESX.GetPlayerFromId(target)
if not xPlayer then return end

if moneyTypes[item] then
return xPlayer.getMoney() >= quantity
end

for _, data in pairs(xPlayer.inventory or {}) do
if data and data.name == item and data.count >= quantity then
return true
end
end

return false
end

local medicBagItem = lib.load("config").medicBagItem
local emsJobs = lib.load("config").emsJobs
local tabletItem = lib.load("config").tabletItem

ESX.RegisterUsableItem(medicBagItem, function(source, a, b)
if not Framework.hasJob(source, emsJobs) then return end

TriggerClientEvent("ars_ambulancejob:placeMedicalBag", source)
if Framework.hasItem(source, medicBagItem, 1) then
Framework.removeItem(source, medicBagItem, 1)
medicalBags[source] = (medicalBags[source] or 0) + 1
TriggerClientEvent("ars_ambulancejob:placeMedicalBag", source)
end
end)

ESX.RegisterUsableItem(tabletItem, function(source, a, b)
Expand Down
40 changes: 39 additions & 1 deletion modules/compatibility/frameworks/qb/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ QBCore = GetResourceState('qb-core'):find('start') and exports['qb-core']:GetCor
if not QBCore then return end

Framework = {}
medicalBags = medicalBags or {}
local useOxInventory = lib.load("config").useOxInventory
local ox_inventory = useOxInventory and exports.ox_inventory

Expand Down Expand Up @@ -35,6 +36,14 @@ function Framework.playerJob(target)
return xPlayer.PlayerData.job.name
end

function Framework.getPlayerJobGrade(target)
local xPlayer = QBCore.Functions.GetPlayer(target)
if not xPlayer then return end

local grade = xPlayer.PlayerData.job.grade
return type(grade) == "table" and grade.level or grade
end

function Framework.updateStatus(data)
local Player = QBCore.Functions.GetPlayer(data.target)

Expand Down Expand Up @@ -108,14 +117,43 @@ function Framework.wipeInventory(target, keep)
exports["qb-inventory"]:ClearInventory(target, keep)
end

function Framework.hasItem(target, item, amount)
local quantity = amount or 1

if ox_inventory then
local count = ox_inventory:Search(target, 'count', item)
return count and count >= quantity
end

local xPlayer = QBCore.Functions.GetPlayer(target)
if not xPlayer then return end

if item == "money" or item == "cash" then
return xPlayer.PlayerData.money["cash"] >= quantity
end

local inventory = xPlayer.PlayerData.items or {}
for _, data in pairs(inventory) do
if data and data.name == item and data.amount >= quantity then
return true
end
end

return false
end

local medicBagItem = lib.load("config").medicBagItem
local emsJobs = lib.load("config").emsJobs
local tabletItem = lib.load("config").tabletItem

QBCore.Functions.CreateUseableItem(medicBagItem, function(source, item)
if not Framework.hasJob(source, emsJobs) then return end

TriggerClientEvent("ars_ambulancejob:placeMedicalBag", source)
local removed = Framework.removeItem(source, medicBagItem, 1)
if removed then
medicalBags[source] = (medicalBags[source] or 0) + 1
TriggerClientEvent("ars_ambulancejob:placeMedicalBag", source)
end
end)
QBCore.Functions.CreateUseableItem(tabletItem, function(source, item)
if not Framework.hasJob(source, emsJobs) then return end
Expand Down
6 changes: 5 additions & 1 deletion modules/injuries/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ function checkInjuries(data)
dataToSend.bone = v.bone
TriggerServerEvent("ars_ambulancejob:healPlayer", dataToSend)

utils.addRemoveItem("add", "money", (100 * (v.value / 10)))
TriggerServerEvent("ars_ambulancejob:claimReward", {
type = "injury",
target = data.target,
bone = v.bone
})

utils.showNotification(locale("injury_treated"))
utils.debug("Injury treated " .. dataToSend.bone)
Expand Down
5 changes: 4 additions & 1 deletion modules/job/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,10 @@ RegisterNetEvent("ars_ambulancejob:playHealAnim", function(data)


utils.useItem("defibrillator", consumeItemPerUse)
utils.addRemoveItem("add", "money", reviveReward)
TriggerServerEvent("ars_ambulancejob:claimReward", {
type = "revive",
target = data.targetServerId
})
elseif data.anim == "dead" then
utils.showNotification(locale("action_revived_notification"))

Expand Down
5 changes: 2 additions & 3 deletions modules/job/client/medical_bag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local PlaceObjectOnGroundProperly = PlaceObjectOnGroundProperly
local DeleteEntity = DeleteEntity
local ClearPedTasks = ClearPedTasks
local RegisterNetEvent = RegisterNetEvent
local TriggerServerEvent = TriggerServerEvent

local medicBagProp = lib.load("config").medicBagProp
local useOxInventory = lib.load("config").useOxInventory
Expand Down Expand Up @@ -35,8 +36,6 @@ local function placeMedicalBag()
medicBag = CreateObjectNoOffset(medicBagProp, coords.x, coords.y, coords.z, true, false)
PlaceObjectOnGroundProperly(medicBag)

utils.addRemoveItem("remove", "medicalbag", 1)

Target.addLocalEntity(medicBag, {
{
label = locale('open_medical_bag'),
Expand All @@ -61,7 +60,7 @@ local function placeMedicalBag()
DeleteEntity(type(data) == "number" and data or data.entity)
ClearPedTasks(playerPed)

utils.addRemoveItem("add", "medicalbag", 1)
TriggerServerEvent("ars_ambulancejob:returnMedicalBag")
end
},
})
Expand Down
14 changes: 8 additions & 6 deletions modules/job/client/shops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ local function createShops()
})
if not amount then return end

local quantity = amount[1]
local totalPrice = item.price * quantity
local quantity = tonumber(amount[1])
if not quantity or quantity < 1 then return end

local hasMoney = Framework.hasItem("money", totalPrice)
if not hasMoney then return utils.showNotification(locale("not_enough_money")) end
quantity = math.floor(quantity)
if quantity < 1 then return end

utils.addRemoveItem("remove", "money", totalPrice)
utils.addRemoveItem("add", item.name, quantity)
local result = lib.callback.await('ars_ambulancejob:purchaseItem', false, name, item.name, quantity)
if not result or result.success then return end

utils.showNotification(locale(result.reason))
end,
}
end
Expand Down
9 changes: 4 additions & 5 deletions modules/paramedic/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ local function openParamedicMenu(ped, hospital)
{
title = locale("get_treated_paramedic"),
onSelect = function()
local hasMoney = Framework.hasItem("money", paramedicTreatmentPrice)
if not hasMoney then return utils.showNotification(locale("not_enough_money")) end


utils.addRemoveItem("remove", "money", paramedicTreatmentPrice)
local paid = lib.callback.await('ars_ambulancejob:payParamedicTreatment', false)
if not paid then
return utils.showNotification(locale("not_enough_money"))
end

local dict = lib.requestAnimDict("anim@gangops@morgue@table@")
local playerPed = cache.ped or PlayerPedId()
Expand Down
12 changes: 0 additions & 12 deletions modules/utils/client/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,6 @@ function utils.getClosestHospital()
return closestHospital
end

function utils.addRemoveItem(type, item, quantity)
local data = {}
data.toggle = type == "remove"
data.item = item
data.quantity = quantity

utils.debug(type, item, quantity)
utils.debug(data)

TriggerServerEvent("ars_ambulancejob:removAddItem", data)
end

function utils.useItem(item, value)
local data = {}
data.item = item
Expand Down
Loading