- big update to labs
This commit is contained in:
1 parent
eaec5fc40f
commit
0956b1d49c
9 files changed
+547
-33
No files matched your search
@@ -0,0 +1,156 @@
|
||||
local locations = MySQL.query.await('SELECT * FROM druglabs WHERE type = ?', {'cocaine'})
|
||||
|
||||
ps.registerCallback('md-drugs:server:GetCokeLabLocations', function()
|
||||
return locations
|
||||
end)
|
||||
|
||||
RegisterNetEvent('TestCokeLab', function(num)
|
||||
local src = source
|
||||
saveBucket(src, num)
|
||||
SetEntityCoords(GetPlayerPed(src), vector3(1088.62, -3187.54, -38.99))
|
||||
TriggerClientEvent('md-drugs:client:EnterCokeLab', src)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('RestoreCokeLab', function(num)
|
||||
local src = source
|
||||
restoreBucket(src)
|
||||
local loc = json.decode(locations[num].coords)
|
||||
SetEntityCoords(GetPlayerPed(src), vector3(loc.x, loc.y, loc.z))
|
||||
end)
|
||||
|
||||
ps.registerCallback('md-drugs:server:GetAvailableEmployees',function(source)
|
||||
local src = source
|
||||
local identifier = ps.getIdentifier(src)
|
||||
local hasLab = MySQL.query.await('SELECT * FROM druglabs WHERE owner = ?', {identifier})
|
||||
if hasLab and #hasLab > 0 then
|
||||
return MySQL.query.await('SELECT * FROM drug_employees', {})
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('md-drugs:server:HireEmployee', function(employeeId)
|
||||
local src = source
|
||||
local identifier = ps.getIdentifier(src)
|
||||
|
||||
local hasLab = MySQL.query.await('SELECT * FROM druglabs WHERE owner = ?', {identifier})
|
||||
if not hasLab or #hasLab == 0 then
|
||||
ps.notify(src, 'You do not own a drug lab.', 'error')
|
||||
return
|
||||
end
|
||||
|
||||
local employee = MySQL.query.await('SELECT * FROM drug_employees WHERE id = ?', {employeeId})
|
||||
if not employee or #employee == 0 then
|
||||
ps.notify(src, 'Employee not found.', 'error')
|
||||
return
|
||||
end
|
||||
|
||||
local employeeData = employee[1]
|
||||
local currentEmployees = json.decode(hasLab[1].employees) or {}
|
||||
|
||||
for _, emp in ipairs(currentEmployees) do
|
||||
if emp.type == employeeData.type then
|
||||
ps.notify(src, 'You already have an employee of this type hired.', 'error')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if ps.removeMoney(src, 'bank', employeeData.salary * 10) then
|
||||
table.insert(currentEmployees, employeeData)
|
||||
MySQL.update.await('UPDATE druglabs SET employees = ? WHERE owner = ?', {json.encode(currentEmployees), identifier})
|
||||
MySQL.query.await('DELETE FROM drug_employees WHERE id = ?', {employeeId})
|
||||
TriggerClientEvent('md-drugs:client:EmployeeHired', src, employeeId)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('md-drugs:server:cokeAddStock',function(stock)
|
||||
local src = source
|
||||
local identifier = ps.getIdentifier(src)
|
||||
|
||||
local hasLab = MySQL.query.await('SELECT * FROM druglabs WHERE owner = ?', {identifier})
|
||||
if not hasLab or #hasLab == 0 then
|
||||
ps.notify(src, 'You do not own a drug lab.', 'error')
|
||||
return
|
||||
end
|
||||
|
||||
local stockCheck = verifyHas(src, stock)
|
||||
if not stockCheck then
|
||||
ps.notify(src, 'You do not have enough items to add to the lab.', 'error')
|
||||
return
|
||||
end
|
||||
|
||||
for item, amount in pairs(stock) do
|
||||
ps.removeItem(src, item, amount)
|
||||
end
|
||||
|
||||
local currentStock = json.decode(hasLab[1].inputItems) or {}
|
||||
for item, amount in pairs(stock) do
|
||||
currentStock[item] = (currentStock[item] or 0) + amount
|
||||
end
|
||||
MySQL.update.await('UPDATE druglabs SET inputItems = ? WHERE owner = ?', {json.encode(currentStock), identifier})
|
||||
ps.notify(src, 'Stock added to your lab successfully.', 'success')
|
||||
end)
|
||||
|
||||
ps.registerCallback('md-drugs:server:getCokeLabItemCount',function(source)
|
||||
local src = source
|
||||
local identifier = ps.getIdentifier(src)
|
||||
|
||||
local hasLab = MySQL.query.await('SELECT * FROM druglabs WHERE owner = ?', {identifier})
|
||||
if not hasLab or #hasLab == 0 then
|
||||
ps.notify(src, 'You do not own a drug lab.', 'error')
|
||||
return
|
||||
end
|
||||
|
||||
local stock = json.decode(hasLab[1].inputItems) or {}
|
||||
local inputData, itemOrder = {}, {}
|
||||
for item, amount in pairs(stock) do
|
||||
table.insert(inputData, {
|
||||
type = 'number',
|
||||
max = amount,
|
||||
title = ps.getItemLabel(item),
|
||||
required = true,
|
||||
min = 0,
|
||||
item = item,
|
||||
})
|
||||
itemOrder[item] = amount
|
||||
end
|
||||
return {input = inputData, order = itemOrder}
|
||||
end)
|
||||
|
||||
RegisterNetEvent('md-drugs:server:cokeTakeDrugs', function(data)
|
||||
local src = source
|
||||
local identifier = ps.getIdentifier(src)
|
||||
ps.debug(data)
|
||||
local hasLab = MySQL.query.await('SELECT * FROM druglabs WHERE owner = ?', {identifier})
|
||||
if not hasLab or #hasLab == 0 then
|
||||
ps.notify(src, 'You do not own a drug lab.', 'error')
|
||||
return
|
||||
end
|
||||
|
||||
local stock = json.decode(hasLab[1].inputItems) or {}
|
||||
if next(stock) == nil then
|
||||
ps.notify(src, 'No drugs available to take.', 'error')
|
||||
return
|
||||
end
|
||||
|
||||
for item, amount in pairs(data) do
|
||||
if not stock[item] then
|
||||
goto skip
|
||||
end
|
||||
if stock[item] < amount then
|
||||
ps.notify(src, 'Insufficient stock for ' .. ps.getItemLabel(item) .. '.', 'error')
|
||||
goto skip
|
||||
end
|
||||
if amount == 0 then
|
||||
goto skip
|
||||
end
|
||||
if ps.addItem(src, item, amount) then
|
||||
stock[item] = stock[item] - amount
|
||||
if stock[item] == 0 then
|
||||
stock[item] = nil
|
||||
end
|
||||
else
|
||||
ps.notify(src, 'Failed to add ' .. ps.getItemLabel(item) .. ' to your inventory.', 'error')
|
||||
end
|
||||
::skip::
|
||||
end
|
||||
MySQL.update.await('UPDATE druglabs SET inputItems = ? WHERE owner = ?', {json.encode(stock), identifier})
|
||||
end)
|
||||
@@ -16,6 +16,39 @@ function timeOut(src, event)
|
||||
timeOutThread(src)
|
||||
return false
|
||||
end
|
||||
-- Drug Labs Functions
|
||||
local Buckets = {}
|
||||
function setBucket(src, bucket)
|
||||
if src and bucket then
|
||||
Player(src).state:set('instance', bucket, true)
|
||||
SetPlayerRoutingBucket(src, bucket)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function saveBucket(src, bucket)
|
||||
Buckets[ps.getIdentifier(src)] = {original = GetEntityRoutingBucket(GetPlayerPed(src)), new = bucket}
|
||||
setBucket(src, bucket)
|
||||
end
|
||||
|
||||
function restoreBucket(src)
|
||||
local id = ps.getIdentifier(src)
|
||||
if Buckets[id] then
|
||||
setBucket(src, Buckets[id].original)
|
||||
Buckets[id] = nil
|
||||
end
|
||||
end
|
||||
|
||||
local firstNames = {'John', 'Jacob', 'Matt', 'Michael', 'Chris', 'David', 'James', 'Robert', 'William', 'Joseph', 'Daniel', 'Lucas', 'Mason', 'Ethan', 'Alexander', 'Liam'}
|
||||
local lastNames = {'Smith', 'Johnson', 'Williams', 'Jones', 'Brown', 'Davis', 'Miller', 'Wilson', 'Moore', 'Taylor', 'Anderson', 'Thomas', 'Jackson', 'White', 'Harris', 'Martin'}
|
||||
|
||||
function generateRandomName()
|
||||
local firstName = firstNames[math.random(#firstNames)]
|
||||
local lastName = lastNames[math.random(#lastNames)]
|
||||
return firstName .. ' ' .. lastName
|
||||
end
|
||||
|
||||
function verifyHas(source, items)
|
||||
local need = 0
|
||||
|
||||
+2
-26
@@ -1,36 +1,12 @@
|
||||
|
||||
local Bags = {}
|
||||
local function setBucket(src, bucket)
|
||||
if src and bucket then
|
||||
Player(src).state:set('instance', bucket, true)
|
||||
SetPlayerRoutingBucket(src, bucket)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
local function saveBags(src)
|
||||
ps.debug('Current', GetEntityRoutingBucket(GetPlayerPed(src)))
|
||||
Bags[ps.getIdentifier(src)] = {original = GetEntityRoutingBucket(GetPlayerPed(src)), new = GetEntityRoutingBucket(GetPlayerPed(src)) + 1}
|
||||
setBucket(src, Bags[ps.getIdentifier(src)].new)
|
||||
ps.debug('New', Bags[ps.getIdentifier(src)].new)
|
||||
end
|
||||
|
||||
local function restoreBags(src)
|
||||
local id = ps.getIdentifier(src)
|
||||
if Bags[id] then
|
||||
setBucket(src, Bags[id].original)
|
||||
Bags[id] = nil
|
||||
end
|
||||
end
|
||||
|
||||
RegisterNetEvent('TestMethLab', function()
|
||||
local src = source
|
||||
saveBags(src)
|
||||
saveBucket(src, 2)
|
||||
TriggerClientEvent('md-methlab:client:EnterMethLab', src)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('RestoreMethLab', function()
|
||||
local src = source
|
||||
restoreBags(src)
|
||||
restoreBucket(src)
|
||||
end)
|
||||
Reference in new issue
Block a user