Skip to content

Commit

Permalink
chore(jobsystem): icons, cash register and alarm
Browse files Browse the repository at this point in the history
  • Loading branch information
polisek committed Feb 25, 2024
1 parent 55cbbd8 commit 57d0831
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 5 deletions.
121 changes: 121 additions & 0 deletions client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
63 changes: 60 additions & 3 deletions client/creation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
{
Expand All @@ -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',
{
Expand All @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion config.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local IS_SERVER = IsDuplicityVersion()

Config = {}

Config.DefaultDataJob = {
Expand All @@ -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/"
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
2 changes: 1 addition & 1 deletion server/jobs.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[]
[{"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"}]
63 changes: 63 additions & 0 deletions server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 57d0831

Please sign in to comment.