2025-08-16 23:43:20 -07:00
|
|
|
local timeOutPlayers = {}
|
|
|
|
|
|
|
|
|
|
local function timeOutThread(src)
|
|
|
|
|
CreateThread(function()
|
|
|
|
|
timeOutPlayers[ps.getIdentifier(src)] = true
|
|
|
|
|
Wait(3000)
|
|
|
|
|
timeOutPlayers[ps.getIdentifier(src)] = nil
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function timeOut(src, event)
|
|
|
|
|
if timeOutPlayers[ps.getIdentifier(src)] then
|
|
|
|
|
ps.warn(ps.lang('Catches.onCooldownWarn', ps.getPlayerName(src), event))
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
timeOutThread(src)
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
2025-08-09 03:10:00 -06:00
|
|
|
function verifyHas(source, items)
|
|
|
|
|
local need = 0
|
|
|
|
|
local have = 0
|
|
|
|
|
local missingList = {}
|
2025-07-14 01:34:58 -07:00
|
|
|
|
2025-08-09 03:10:00 -06:00
|
|
|
for k, v in pairs(items) do
|
|
|
|
|
need = need + 1
|
|
|
|
|
if ps.hasItem(source, k, v) then
|
|
|
|
|
have = have + 1
|
|
|
|
|
else
|
|
|
|
|
local label = ps.getItemLabel(k) or k
|
|
|
|
|
table.insert(missingList, v .. " " .. label)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if need == have then
|
|
|
|
|
return true
|
|
|
|
|
end
|
2025-07-14 01:34:58 -07:00
|
|
|
|
2025-08-09 03:10:00 -06:00
|
|
|
local message = ps.lang('Catches.itemMissings') .. table.concat(missingList, "\n")
|
|
|
|
|
ps.notify(source, message, 'error')
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
2025-07-14 01:34:58 -07:00
|
|
|
local function handleFresh(source)
|
|
|
|
|
local table = json.encode({
|
|
|
|
|
coke = 0,lsd = 0,heroin = 0,dealerrep = 0,
|
|
|
|
|
cornerselling = { price = QBConfig.SellLevel[1].price,rep = 0,label = QBConfig.SellLevel[1].label,level = 1}
|
|
|
|
|
})
|
2025-07-15 02:21:34 -07:00
|
|
|
MySQL.insert('INSERT INTO drugrep SET cid = ?, drugrep = ?, name = ?', {ps.getIdentifier(source), table, ps.getPlayerName(source)})
|
2025-07-14 01:34:58 -07:00
|
|
|
return json.decode(table)
|
|
|
|
|
end
|
2024-09-24 15:07:41 -07:00
|
|
|
|
2025-07-14 01:34:58 -07:00
|
|
|
function getRep(source, type)
|
2025-07-15 02:21:34 -07:00
|
|
|
local sql = MySQL.query.await('SELECT JSON_UNQUOTE(JSON_EXTRACT(drugrep, ?)) AS rep FROM drugrep WHERE cid = ?', {'$.' .. type, ps.getIdentifier(source)})
|
2024-09-24 15:07:41 -07:00
|
|
|
if not sql[1] then
|
2025-07-14 01:34:58 -07:00
|
|
|
local new = handleFresh(source)
|
|
|
|
|
return new[type]
|
2024-07-21 21:45:06 -07:00
|
|
|
else
|
2025-08-09 23:58:38 -06:00
|
|
|
return sql[1].rep
|
2024-09-24 15:07:41 -07:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2025-07-14 01:34:58 -07:00
|
|
|
function GetAllRep(source)
|
2025-07-15 02:21:34 -07:00
|
|
|
local sql = MySQL.query.await('SELECT * FROM drugrep WHERE cid = ?', {ps.getIdentifier(source)})
|
2024-09-24 15:07:41 -07:00
|
|
|
if not sql[1] then
|
2025-07-14 01:34:58 -07:00
|
|
|
local new = handleFresh(source)
|
|
|
|
|
return new
|
2024-09-24 15:07:41 -07:00
|
|
|
else
|
2024-10-30 13:03:51 -07:00
|
|
|
local rep = json.decode(sql[1].drugrep)
|
|
|
|
|
if rep.coke == nil then return rep[1] end
|
2024-09-24 15:07:41 -07:00
|
|
|
return rep
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-07-21 21:45:06 -07:00
|
|
|
|
2025-07-14 01:34:58 -07:00
|
|
|
function AddRep(source, type, amount)
|
|
|
|
|
if not Config.TierSystem then return false end
|
2024-10-28 14:11:49 -07:00
|
|
|
if not amount then amount = 1 end
|
2025-07-17 02:06:17 -05:00
|
|
|
local sql = MySQL.query.await('SELECT * FROM drugrep WHERE cid = ?', {ps.getIdentifier(source)})
|
2024-10-30 13:03:51 -07:00
|
|
|
local reps = json.decode(sql[1].drugrep)
|
|
|
|
|
local update
|
|
|
|
|
local rep = ''
|
|
|
|
|
if reps.coke == nil then rep = reps[1] else rep = reps end
|
2024-10-28 14:11:49 -07:00
|
|
|
if type == 'cornerselling' then
|
|
|
|
|
for k, v in pairs (QBConfig.SellLevel) do
|
|
|
|
|
if rep.cornerselling.level == k then
|
|
|
|
|
if rep.cornerselling.rep + amount >= v.maxrep then
|
|
|
|
|
update = json.encode({coke = rep.coke, heroin = rep.heroin, lsd = rep.lsd, dealerrep = rep.dealerrep, cornerselling = {label = v.label, price = v.price, rep = rep.cornerselling.rep + amount, level = k + 1}})
|
|
|
|
|
else
|
|
|
|
|
update = json.encode({coke = rep.coke, heroin = rep.heroin, lsd = rep.lsd, dealerrep = rep.dealerrep, cornerselling = {label = v.label, price = v.price, rep = rep.cornerselling.rep + amount, level = k}})
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-07-14 01:34:58 -07:00
|
|
|
end
|
|
|
|
|
if update == '' then return false end
|
2025-07-17 02:06:17 -05:00
|
|
|
MySQL.update('UPDATE drugrep SET drugrep = ? WHERE cid = ?', {update, ps.getIdentifier(source)})
|
2025-07-14 01:34:58 -07:00
|
|
|
return true
|
|
|
|
|
else
|
|
|
|
|
rep[type] = rep[type] + amount
|
2025-07-17 02:06:17 -05:00
|
|
|
MySQL.update('UPDATE drugrep SET drugrep = ? WHERE cid = ?', {json.encode(rep), ps.getIdentifier(source)})
|
2025-07-14 01:34:58 -07:00
|
|
|
return true
|
2024-07-21 21:45:06 -07:00
|
|
|
end
|
|
|
|
|
end
|
2024-10-24 19:45:39 -07:00
|
|
|
|
2025-08-09 03:10:00 -06:00
|
|
|
ps.registerCallback('md-drugs:server:GetCoppers', function(source, cb, args)
|
|
|
|
|
return ps.getJobTypeCount('leo')
|
2024-05-02 18:34:49 -07:00
|
|
|
end)
|
|
|
|
|
|
2025-07-17 02:06:17 -05:00
|
|
|
ps.registerCallback('md-drugs:server:GetRep', function(source, cb, args)
|
2025-08-09 03:10:00 -06:00
|
|
|
local rep = GetAllRep(source)
|
2024-09-24 15:07:41 -07:00
|
|
|
return rep
|
|
|
|
|
end)
|
2025-09-08 00:16:45 -07:00
|
|
|
ps.versionCheck('md-drugs', 'https://raw.githubusercontent.com/Mustachedom/md-drugs/refs/heads/main/version.txt', 'https://github.com/Mustachedom/md-drugs/')
|