Files
md-drugs/server/functions.lua
T

164 lines
5.2 KiB
Lua
Raw Normal View History

local timeOutPlayers = {}
2026-01-16 02:57:26 -07:00
local playerRep = {}
2026-01-21 01:36:38 -07:00
local playerWarnings = {}
local trollExploiters = true
2026-01-22 02:08:35 -07:00
2026-01-21 01:36:38 -07:00
local function trollPlayer(src)
if not trollExploiters then return end
CreateThread(function()
local playerPed = GetPlayerPed(src)
SetEntityCoords(playerPed, -3432.36, -6000.42, -2.0, false, false, false, true)
Wait(30000)
SetEntityCoords(playerPed, -1392.98, -2599.29, 2419.18, false, false, false, true)
2026-01-30 01:40:18 -07:00
Wait(40000)
2026-01-21 01:36:38 -07:00
DropPlayer(src, 'You have been caught trying to exploit md-drugs, get rekted.')
end)
end
2026-01-30 01:40:18 -07:00
RegisterCommand('testTroll', function(source, args, rawCommand)
local src = source
trollPlayer(src)
end, false)
2026-01-19 00:46:49 -07:00
function checkDistance(src, coords, dist, event)
2026-01-16 02:57:26 -07:00
local pcoords = GetEntityCoords(GetPlayerPed(src))
coords = vector3(coords.x, coords.y, coords.z)
if #(pcoords - coords) > dist then
2026-01-19 00:46:49 -07:00
Bridge.Prints.Warn(Bridge.Language.Locale('Catches.outOfRangeWarn', Bridge.Framework.GetPlayerIdentifier(src), event))
2026-01-21 01:36:38 -07:00
playerWarnings[src] = (playerWarnings[src] or 0) + 1
if playerWarnings[src] >= 5 then
trollPlayer(src)
end
2026-01-16 02:57:26 -07:00
return false
end
return true
end
2026-01-19 00:46:49 -07:00
local function timeOutThread(src)
2026-01-21 01:36:38 -07:00
src = tonumber(src)
CreateThread(function()
2026-01-21 01:36:38 -07:00
timeOutPlayers[src] = true
Wait(3000)
2026-01-21 01:36:38 -07:00
timeOutPlayers[src] = nil
end)
end
function timeOut(src, event)
2026-01-16 02:57:26 -07:00
if timeOutPlayers[src] then
2026-01-22 02:08:35 -07:00
Bridge.Prints.Warn(Bridge.Language.Locale('Catches.onCooldownWarn', Bridge.Framework.GetPlayerIdentifier(src), event))
2026-01-21 01:36:38 -07:00
playerWarnings[src] = (playerWarnings[src] or 0) + 1
if playerWarnings[src] >= 5 then
trollPlayer(src)
end
return true
end
timeOutThread(src)
return false
end
2026-01-16 02:57:26 -07:00
function craft(source, recipe)
local need, have, oops = 0,0,{}
for item, amount in pairs (recipe.take) do
2025-08-09 03:10:00 -06:00
need = need + 1
2026-01-16 02:57:26 -07:00
local count = Bridge.Inventory.GetItemCount(source, item)
if count >= amount then
2025-08-09 03:10:00 -06:00
have = have + 1
else
2026-01-16 02:57:26 -07:00
table.insert(oops, 'You Need ' .. amount .. ' X ' .. Bridge.Inventory.GetItemInfo(item).label)
2025-08-09 03:10:00 -06:00
end
end
2026-01-16 02:57:26 -07:00
if have ~= need then
for index, text in pairs (oops) do
Bridge.Notify.SendNotify(source, text, 'error')
end
return false
2025-08-09 03:10:00 -06:00
end
2026-01-16 02:57:26 -07:00
for item, amount in pairs (recipe.take) do
if not Bridge.Inventory.RemoveItem(source, item, amount) then
return false
end
end
for item, amount in pairs (recipe.give) do
Bridge.Inventory.AddItem(source, item, amount)
end
return true
2025-08-09 03:10:00 -06:00
end
2025-07-14 01:34:58 -07:00
local function handleFresh(source)
2026-01-16 02:57:26 -07:00
local id = Bridge.Framework.GetPlayerIdentifier(source)
local player = {
coke = 0,
lsd = 0,
heroin = 0,
dealerrep = 0,
cornerselling = {
2026-01-31 02:44:07 -07:00
price = Config.Cornerselling.CornerSellLevel[1].price,
2026-01-16 02:57:26 -07:00
rep = 0,
2026-01-31 02:44:07 -07:00
label = Config.Cornerselling.CornerSellLevel[1].label,
2026-01-16 02:57:26 -07:00
level = 1
}
}
playerRep[id] = player
local first, last = Bridge.Framework.GetPlayerName(source)
MySQL.insert('INSERT INTO drugrep SET cid = ?, drugrep = ?, name = ?', {id, player, first .. ' ' .. last})
end
local function loadRep(source)
local id = Bridge.Framework.GetPlayerIdentifier(source)
local hasRep = MySQL.query.await('SELECT * FROM drugrep WHERE cid = ?', {id})
if hasRep and not hasRep[1] then
handleFresh(source)
end
if hasRep and hasRep[1] then
playerRep[id] = json.decode(hasRep[1].drugrep)
end
2025-07-14 01:34:58 -07:00
end
2025-07-14 01:34:58 -07:00
function getRep(source, type)
2026-01-16 02:57:26 -07:00
local id = Bridge.Framework.GetPlayerIdentifier(source)
if not playerRep[id] then
loadRep(source)
end
2026-01-16 02:57:26 -07:00
return playerRep[id][type]
end
2025-07-14 01:34:58 -07:00
function GetAllRep(source)
2026-01-16 02:57:26 -07:00
local id = Bridge.Framework.GetPlayerIdentifier(source)
if not playerRep[id] then
loadRep(source)
end
2026-01-16 02:57:26 -07:00
return playerRep[id]
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
2026-01-16 02:57:26 -07:00
local id = Bridge.Framework.GetPlayerIdentifier(source)
if not playerRep[id] then
loadRep(source)
end
2024-10-28 14:11:49 -07:00
if type == 'cornerselling' then
2026-01-16 02:57:26 -07:00
local rep = playerRep[id].cornerselling
2026-01-23 04:10:58 -07:00
local cornerData = Config.CornerSellLevel[rep.level]
2026-01-16 02:57:26 -07:00
if rep.rep + amount >= cornerData.maxrep then
rep.level = rep.level + 1
2026-01-23 04:10:58 -07:00
rep.label = Config.CornerSellLevel[rep.level].label
rep.price = Config.CornerSellLevel[rep.level].price
2025-07-14 01:34:58 -07:00
end
2026-01-16 02:57:26 -07:00
rep.rep = rep.rep + amount
2025-07-14 01:34:58 -07:00
else
2026-01-16 02:57:26 -07:00
playerRep[id][type] = playerRep[id][type] + amount
2024-07-21 21:45:06 -07:00
end
2026-01-16 02:57:26 -07:00
MySQL.query.await('UPDATE drugrep SET drugrep = ? WHERE cid = ?', {json.encode(playerRep[id]), id})
2024-07-21 21:45:06 -07:00
end
2026-01-30 01:40:18 -07:00
2026-01-19 00:46:49 -07:00
Bridge.Callback.Register('md-drugs:server:GetCoppers', function(source, cb, args)
return #Bridge.Framework.GetPlayersByJob('police')
2024-05-02 18:34:49 -07:00
end)
2026-01-19 00:38:01 -07:00
Bridge.Callback.Register('md-drugs:server:GetRep', function(source, cb, args)
2025-08-09 03:10:00 -06:00
local rep = GetAllRep(source)
return rep
end)
2026-01-16 02:57:26 -07:00
--TODO: fix versioncheck
2026-01-22 02:08:35 -07:00
Bridge.Version.VersionChecker('Mustachedom/md-drugs', false)