diff --git a/client/client.lua b/client/client.lua index 371c106..a429b32 100644 --- a/client/client.lua +++ b/client/client.lua @@ -75,6 +75,54 @@ local function generateCrafting(craftItems) end end +local function openCashRegister(job) + local cashBalance = lib.callback.await('pls_jobsystem:server:getBalance',100,job) + if cashBalance then + lib.registerContext({ + id = "cash_register", + title = "Cash register", + options = { + { + name = 'balance', + icon = 'fa-solid fa-dollar', + title = "Balance: "..cashBalance, + }, + { + name = 'withdraw', + icon = 'fa-solid fa-arrow-down', + title = "Withdraw", + -- groups = job.job, + onSelect = function(data) + local input = lib.inputDialog('Create new job', + { + {type = 'number', label = 'Withdraw', description = 'How much you want withdraw?', icon = 'hashtag', min = 1,}, + }) + if input then + TriggerSecureEvent("pls_jobsystem:server:makeRegisterAction", job, "withdraw", input[1]) + end + end + }, + { + name = 'deposit', + icon = 'fa-solid fa-arrow-up', + title = "Deposit", + -- groups = job.job, + onSelect = function(data) + local input = lib.inputDialog('Create new job', + { + {type = 'number', label = 'Deposit', description = 'How much you want deposit', icon = 'hashtag', min = 1,}, + }) + if input then + TriggerSecureEvent("pls_jobsystem:server:makeRegisterAction", job, "deposit", input[1]) + end + end + }, + } + }) + lib.showContext("cash_register") + end +end + local function GenerateCraftings() for _, job in pairs(Jobs) do for _, crafting in pairs(job.craftings) do @@ -105,10 +153,83 @@ local function GenerateCraftings() }) table.insert(Targets, targetId) end + + ------- CASH REGISTER + + if job.register then + local CashRegister = BRIDGE.AddSphereTarget({ + coords = vector3(job.register.x, job.register.y, job.register.z), + options = { + { + name = 'bell', + icon = 'fa-solid fa-circle', + label = "Cash register", + -- groups = job.job, + onSelect = function(data) + local jobname = BRIDGE.GetPlayerJob() + if jobname == job.job then + openCashRegister(job.job) + else + lib.notify({ + title="Not for you", + description="You can't use this.", + type="error" + }) + end + end + }, + }, + debug = false, + radius = 0.2, + }) + table.insert(Targets, CashRegister) + end + + ------- ALARM + if job.alarm then + local AlarmTarget = BRIDGE.AddSphereTarget({ + coords = vector3(job.alarm.x, job.alarm.y, job.alarm.z), + options = { + { + name = 'bell', + icon = 'fa-solid fa-circle', + label = "Alarm", + -- groups = job.job, + onSelect = function(data) + local jobname = BRIDGE.GetPlayerJob() + if jobname == job.job then + local alert = lib.alertDialog({ + header = "Call police", + content = "You really want call police? ", + centered = true, + cancel = true + }) + if alert == "confirm" then + SendDispatch(GetEntityCoords(cache.ped), job.label) + end + else + lib.notify({ + title="Not for you", + description="You can't use this.", + type="error" + }) + end + end + }, + }, + debug = false, + radius = 0.2, + }) + table.insert(Targets, AlarmTarget) + end end + end + + + RegisterNetEvent("pls_jobsystem:client:recivieJobs") AddEventHandler("pls_jobsystem:client:recivieJobs", function(ServerJobs) if Jobs then diff --git a/client/creation.lua b/client/creation.lua index 90a51f2..7e01b73 100644 --- a/client/creation.lua +++ b/client/creation.lua @@ -78,6 +78,13 @@ local function CreateCraftingTable() end end +local function AddonsExists(value) + if value then + return "Created" + else + return "Not created" + end +end local function selectJob(jobData) selectedJob = jobData @@ -88,7 +95,7 @@ local function selectJob(jobData) { title = selectedJob.label, description = "Click here for rename", - icon = 'circle', + icon = 'quote-left', onSelect = function() local input = lib.inputDialog('Editing job', { @@ -102,7 +109,7 @@ local function selectJob(jobData) { title = "Area size: "..selectedJob.area, description = "Click here for change job area", - icon = 'circle', + icon = 'expand', onSelect = function() local input = lib.inputDialog('Editing job', { @@ -113,10 +120,60 @@ local function selectJob(jobData) TriggerSecureEvent("pls_jobsystem:server:saveJob", selectedJob) end, }, + { + title = "Cash register", + description = "Status: "..AddonsExists(selectedJob.register), + icon = 'dollar', + onSelect = function() + if selectedJob.register then + local alert = lib.alertDialog({ + header = "Delete cash register", + content = "Do you really want to delete? ", + centered = true, + cancel = true + }) + if alert == "confirm" then + selectedJob.register = nil + TriggerSecureEvent("pls_jobsystem:server:saveJob", selectedJob) + end + else + local coords = CreateNewCraftingPoint() + if coords then + selectedJob.register = coords + TriggerSecureEvent("pls_jobsystem:server:saveJob", selectedJob) + end + end + end, + }, + { + title = "Alarm", + description = "Status: "..AddonsExists(selectedJob.alarm), + icon = 'bell', + onSelect = function() + if selectedJob.alarm then + local alert = lib.alertDialog({ + header = "Delete alarm", + content = "Do you really want to delete? ", + centered = true, + cancel = true + }) + if alert == "confirm" then + selectedJob.alarm = nil + TriggerSecureEvent("pls_jobsystem:server:saveJob", selectedJob) + end + else + local coords = CreateNewCraftingPoint() + if coords then + selectedJob.alarm = coords + TriggerSecureEvent("pls_jobsystem:server:saveJob", selectedJob) + end + end + end, + }, { title = "Craftings", description = "Click here for open crafting menu", - icon = 'circle', + icon = 'box', onSelect = function() EditCrafings() end, diff --git a/config.lua b/config.lua index 739c35a..af8f9b7 100644 --- a/config.lua +++ b/config.lua @@ -1,3 +1,5 @@ +local IS_SERVER = IsDuplicityVersion() + Config = {} Config.DefaultDataJob = { @@ -14,4 +16,13 @@ Config.BlacklistedStrings = { "weapon", "weed", "meth","coke", "ammo", "gun", "pistol", "drug", "c4", "WEAPON", "AMMO", "at_", "keycard", "gun", "money", "black_money" } -Config.DirectoryToInventoryImages = "nui://ox_inventory/web/images/" \ No newline at end of file +Config.DirectoryToInventoryImages = "nui://ox_inventory/web/images/" + +if not IS_SERVER then + function SendDispatch(coords, jobLabel) + -- YOU DISPATCH + -- cache.ped + print(coords) + print(jobLabel) + end +end \ No newline at end of file diff --git a/server/jobs.json b/server/jobs.json index 0637a08..fda9acd 100644 --- a/server/jobs.json +++ b/server/jobs.json @@ -1 +1 @@ -[] \ No newline at end of file +[{"coords":{"y":-1190.78955078125,"z":14.30922698974609,"x":-1833.031982421875},"job":"pearls","register":{"x":-1834.1085205078126,"y":-1189.989501953125,"z":14.44417858123779},"alarm":{"x":-1837.2142333984376,"y":-1189.4954833984376,"z":14.13875007629394},"craftings":[{"coords":{"y":-1193.454345703125,"z":14.22590637207031,"x":-1838.96044921875},"items":[],"label":"First crafting","id":"pearls0_7504"}],"area":50,"balance":301,"label":"Pearls"}] \ No newline at end of file diff --git a/server/server.lua b/server/server.lua index e0fea72..f885e9e 100644 --- a/server/server.lua +++ b/server/server.lua @@ -33,6 +33,18 @@ local function IsPlayerHasCustomPerms(playerId) return true end + +lib.callback.register('pls_jobsystem:server:getBalance', function(source,jobName) + for _, job in pairs(Jobs) do + if job.job == jobName then + if not job.balance then + job.balance = 0 + end + return job.balance + end + end +end) + RegisterNetEvent("pls_jobsystem:server:saveNewJob") AddEventHandler("pls_jobsystem:server:saveNewJob", function(jobData) local src = source @@ -163,6 +175,57 @@ AddEventHandler("pls_jobsystem:server:createItem", function(craftingData) end end) +RegisterNetEvent("pls_jobsystem:server:makeRegisterAction") +AddEventHandler("pls_jobsystem:server:makeRegisterAction", function(jobName, action, number) + local src = source + if CanTrustPlayer(src) then + if IsJobExist(jobName) then + for _, job in pairs(Jobs) do + if job.job == jobName then + if not job.balance then + job.balance = 0 + end + if action == "withdraw" then + if job.balance > 0 and job.balance >= number and job.balance-number > 0 then + job.balance = job.balance - number + BRIDGE.AddItem(src, "money", number) + lib.notify(src, { + title="Withdraw", + description="Done!", + type="success" + }) + SaveJobs() + else + lib.notify(src, { + title="Withdraw", + description="Cannot be done", + type="error" + }) + end + elseif action == "deposit" then + local playerMoney = BRIDGE.GetItemCount(src, "money") + if playerMoney >= number then + job.balance = job.balance + number + BRIDGE.RemoveItem(src, "money", number) + lib.notify(src, { + title="Deposit", + description="Done!", + type="success" + }) + SaveJobs() + else + lib.notify(src, { + title="Deposit", + description="You don't have enough money", + type="error" + }) + end + end + end + end + end + end +end) lib.addCommand('createjob', { help = 'This command create job',