local QBCore = exports['qb-core']:GetCoreObject()
RegisterServerEvent('cr-drugs:server:updateDealerItems')
AddEventHandler('cr-drugs:server:updateDealerItems', function(itemData, amount, dealer)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Config.Dealers[dealer]["products"][itemData.slot].amount - 1 >= 0 then
Config.Dealers[dealer]["products"][itemData.slot].amount =
Config.Dealers[dealer]["products"][itemData.slot].amount - amount
TriggerClientEvent('cr-drugs:client:setDealerItems', -1, itemData, amount, dealer)
else
Player.Functions.RemoveItem(itemData.name, amount)
Player.Functions.AddMoney('cash', amount * Config.Dealers[dealer]["products"][itemData.slot].price)
TriggerClientEvent("QBCore:Notify", src, "This item is not available.. You've got an refund.", "error")
end
end)
RegisterServerEvent('cr-drugs:server:giveDeliveryItems')
AddEventHandler('cr-drugs:server:giveDeliveryItems', function(amount)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
Player.Functions.AddItem('weed_brick', amount)
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items["weed_brick"], "add")
----TriggerEvent('cr-logs:server:createLog', 'crash', 'Triggered Fake Event lmao (ban incoming bye bye) (cornerselling)', "", src)
end)
QBCore.Functions.CreateCallback('cr-drugs:server:RequestConfig', function(source, cb)
cb(Config.Dealers)
end)
RegisterServerEvent('cr-drugs:server:succesDelivery')
AddEventHandler('cr-drugs:server:succesDelivery', function(deliveryData, inTime)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local curRep = Player.PlayerData.metadata["dealerrep"]
if inTime then
if Player.Functions.GetItemByName('weed_brick') ~= nil and Player.Functions.GetItemByName('weed_brick').amount >=
deliveryData["amount"] then
Player.Functions.RemoveItem('weed_brick', deliveryData["amount"])
local cops = GetCurrentCops()
local price = 3000
if cops == 1 then
price = 4000
elseif cops == 2 then
price = 5000
elseif cops >= 3 then
price = 6000
end
if curRep < 10 then
Player.Functions.AddMoney('cash', (deliveryData["amount"] * price / 100 * 8), "dilvery-drugs")
elseif curRep >= 10 then
Player.Functions.AddMoney('cash', (deliveryData["amount"] * price / 100 * 10), "dilvery-drugs")
elseif curRep >= 20 then
Player.Functions.AddMoney('cash', (deliveryData["amount"] * price / 100 * 12), "dilvery-drugs")
elseif curRep >= 30 then
Player.Functions.AddMoney('cash', (deliveryData["amount"] * price / 100 * 15), "dilvery-drugs")
elseif curRep >= 40 then
Player.Functions.AddMoney('cash', (deliveryData["amount"] * price / 100 * 18), "dilvery-drugs")
end
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items["weed_brick"], "remove")
TriggerClientEvent('QBCore:Notify', src, 'The order has been delivered completely', 'success')
SetTimeout(math.random(5000, 10000), function()
TriggerClientEvent('cr-drugs:client:sendDeliveryMail', src, 'perfect', deliveryData)
Player.Functions.SetMetaData('dealerrep', (curRep + 1))
end)
else
TriggerClientEvent('QBCore:Notify', src, 'This doesn\'t meet the order...', 'error')
if Player.Functions.GetItemByName('weed_brick').amount ~= nil then
Player.Functions.RemoveItem('weed_brick', Player.Functions.GetItemByName('weed_brick').amount)
Player.Functions
.AddMoney('cash', (Player.Functions.GetItemByName('weed_brick').amount * 6000 / 100 * 5))
end
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items["weed_brick"], "remove")
SetTimeout(math.random(5000, 10000), function()
TriggerClientEvent('cr-drugs:client:sendDeliveryMail', src, 'bad', deliveryData)
if curRep - 1 > 0 then
Player.Functions.SetMetaData('dealerrep', (curRep - 1))
else
Player.Functions.SetMetaData('dealerrep', 0)
end
end)
end
else
TriggerClientEvent('QBCore:Notify', src, 'You\'re too late...', 'error')
Player.Functions.RemoveItem('weed_brick', deliveryData["amount"])
Player.Functions.AddMoney('cash', (deliveryData["amount"] * 6000 / 100 * 4), "dilvery-drugs-too-late")
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items["weed_brick"], "remove")
SetTimeout(math.random(5000, 10000), function()
TriggerClientEvent('cr-drugs:client:sendDeliveryMail', src, 'late', deliveryData)
if curRep - 1 > 0 then
Player.Functions.SetMetaData('dealerrep', (curRep - 1))
else
Player.Functions.SetMetaData('dealerrep', 0)
end
end)
end
end)
RegisterServerEvent('cr-drugs:server:callCops')
AddEventHandler('cr-drugs:server:callCops', function(streetLabel, coords)
local msg = "A suspicious situation has been located at " .. streetLabel .. ", possibly drug dealing."
local alertData = {
title = "Drug Dealing",
coords = {
x = coords.x,
y = coords.y,
z = coords.z
},
description = msg
}
for k, v in pairs(QBCore.Functions.GetPlayers()) do
local Player = QBCore.Functions.GetPlayer(v)
if Player ~= nil then
if (Player.PlayerData.job.name == "police" and Player.PlayerData.job.onduty) then
TriggerClientEvent("cr-drugs:client:robberyCall", Player.PlayerData.source, msg, streetLabel, coords)
TriggerClientEvent("cr-phone:client:addPoliceAlert", Player.PlayerData.source, alertData)
end
end
end
end)
function GetCurrentCops()
local amount = 0
for k, v in pairs(QBCore.Functions.GetPlayers()) do
local Player = QBCore.Functions.GetPlayer(v)
if Player ~= nil then
if (Player.PlayerData.job.name == "police" and Player.PlayerData.job.onduty) then
amount = amount + 1
end
end
end
return amount
end
QBCore.Commands.Add("newdealer", "Place A Dealer (Admin Only)", {{
name = "name",
help = "Dealer name"
}, {
name = "min",
help = "Minimum time"
}, {
name = "max",
help = "Maximum time"
}}, true, function(source, args)
local dealerName = args[1]
local mintime = tonumber(args[2])
local maxtime = tonumber(args[3])
TriggerClientEvent('cr-drugs:client:CreateDealer', source, dealerName, mintime, maxtime)
end, "admin")
QBCore.Commands.Add("deletedealer", "Delete A Dealer (Admin Only)", {{
name = "name",
help = "Name of the dealer"
}}, true, function(source, args)
local dealerName = args[1]
local result = exports.oxmysql:executeSync('SELECT * FROM dealers WHERE name = ?', {dealerName})
if result[1] ~= nil then
exports.oxmysql:execute('DELETE FROM dealers WHERE name = ?', {dealerName})
Config.Dealers[dealerName] = nil
TriggerClientEvent('cr-drugs:client:RefreshDealers', -1, Config.Dealers)
TriggerClientEvent('QBCore:Notify', source, "Dealer: " .. dealerName .. " Has Been Deleted", "success")
else
TriggerClientEvent('QBCore:Notify', source, "Dealer: " .. dealerName .. " Doesn\'t Exist", "error")
end
end, "admin")
QBCore.Commands.Add("dealers", "View All Dealers (Admin Only)", {}, false, function(source, args)
local DealersText = ""
if Config.Dealers ~= nil and next(Config.Dealers) ~= nil then
for k, v in pairs(Config.Dealers) do
DealersText = DealersText .. "Name: " .. v["name"] .. "
"
end
TriggerClientEvent('chat:addMessage', source, {
template = '