Customs functions
CheckOnlineCops (shared/utils.lua)
This function returns the number of police officers (depending on the list of police jobs) on duty. Customize it if your server in another way.
function CheckOnlineCops()
local copsOnline = 0
for key, job in pairs(Config.utility.policeJobs) do
if GlobalState[job] then
copsOnline += GlobalState[job]
end
end
return copsOnline
endDispatch (client/dispatch.lua)
Replaced the export with either the event or the export of your dispatch script
function CustomDispatch(coords)
exports["ps-dispatch-esx"]:DrugSale(coords)
endInventory (server/framework/framework.lua)
Firstly, before modifying, be sure of what you are doing. In all functions you will see "xPlayerSource" know that this represents the "player source" depending on your framework (esx or qbcore) so you don't need to touch it !
By default the script uses ox_inventory, it's up to you to adapt the script according to yours but while keeping the parameters intact.
PlayerHasDrugs
function PlayerHasDrugs(xPlayerSource)
local totalItems = 0
local items = {}
if xPlayerSource then
items = exports.ox_inventory:Search(xPlayerSource, "count", Config.Drugs.list, nil)
for name, count in pairs(items) do
totalItems += count
end
return items, totalItems
end
endHere we check in the player's inventory if he has any drugs (depends on the list in "Config.Drugs.list") and return the total number of items and the items with their metadata
RemoveDrugsItem
function RemoveDrugsItem(xPlayerSource, drugItem, amount)
if xPlayerSource then
exports.ox_inventory:RemoveItem(xPlayerSource, drugItem, amount)
end
endSimply remove the drug that has just been sold from the player's inventory.
AddRewardPlayer
function AddRewardPlayer(xPlayerSource, priceToPlayer)
if xPlayerSource then
exports.ox_inventory:AddItem(xPlayerSource, Config.Drugs.reward, priceToPlayer)
end
endGive the reward to the player
SendNotification
function SendNotification(xPlayerSource, type, msgInfo) -- type = "success" or "error"
if xPlayerSource then
if type == "success" then
TriggerClientEvent("ox_lib:notify", xPlayerSource, {type = "success",
title = locale("Title_EndSale"),
description = msgInfo,
duration = 5000})
else
TriggerClientEvent("ox_lib:notify", xPlayerSource, {type = 'error',
title = locale("Title_Negotiate_failed"),
description = locale("Desc_Negotiate_failed"),
position = "center-right",
duration = 3500})
end
end
endBy default we use ox_lib to make notifications, it's up to you to change for your own notifications
Last updated