Skip to content

Commit

Permalink
Merge pull request #2 from Flek26/main
Browse files Browse the repository at this point in the history
Only Buy licenses you have meta data for
  • Loading branch information
NietThijmen authored Apr 4, 2023
2 parents f2a2edc + 9bcaf77 commit 396b59e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 23 deletions.
21 changes: 16 additions & 5 deletions client/nui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,24 @@ end
--- Setup the items for the NUI
function NUI:SetupItems()
local items = {}
items[1] = {
name = "ID Card",
price = 100,
id = 1
}

local PlayerLicenses = QBCore.Functions.GetPlayerData().metadata["licences"]

for key = 1, #Config.items, 1 do
items[#items + 1] = {
name = Config.items[key].label,
price = Config.items[key].price,
id = key
}
for k, value in pairs(PlayerLicenses) do
if (value == true and Config.items[key].meta == k) then
items[#items + 1] = {
name = Config.items[key].label,
price = Config.items[key].price,
id = key
}
end
end
end

SendNUIMessage({
Expand Down
41 changes: 32 additions & 9 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,44 @@ Config.blip = {
}

-- Jobs for hire
Config.jobs = {{
job = "police",
label = "LSPD",
salary = 100
}, {
job = 'ambulance',
label = "EMS",
salary = -1
}}
Config.jobs = {
{
job = "trucker",
label = "Trucker",
salary = 50
},
{
job = "taxi",
label = "Taxi",
salary = 50
},
{
job = "tow",
label = "Tow Truck",
salary = 50
},
{
job = "reporter",
label = "News Reporter",
salary = 50
},
}

-- Items for purchase
Config.items = {{
item = "id_card",
meta = 'id',
label = "ID Card",
price = 100
}, {
item = "driver_license",
label = "Driver License",
meta = 'driver',
price = 100
}, {
item = "weaponlicense",
label = "Weapon License",
meta = 'weapon',
price = 100
}}

Expand All @@ -50,4 +70,7 @@ Config.licenseItems = {{
}, {
item = 'driver_license',
label = 'Driver License'
}, {
item = 'weaponlicense',
label = 'Weapon License'
}}
8 changes: 7 additions & 1 deletion html/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ class Main {
document.getElementById('Sidebar.close').onclick = () => {
this.HideCityhall();
}

document.onkeyup = (data) => {
if (data.which == 27) {
this.HideCityhall();
}
}
}
}

Expand Down Expand Up @@ -362,4 +368,4 @@ let job = new Jobs();
let identity = new Identity();
let information = new Information();

let main = new Main();
let main = new Main();
8 changes: 4 additions & 4 deletions html/js/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ let stringsEN = {
"text_information": "My info",
"text_close": "Close",

"text_identification": "Identification",
"desc_identification": "Below you can see which identification methods you currently have.",
"text_identification": "ID Cards",
"desc_identification": "Below you can see which ID cards you currently have in your pockets.",

"text_licenses": "Licenses",
"desc_licenses": "Below you can see which licenses you currently have.",
"text_licenses": "Permissions",
"desc_licenses": "Below you can see which ID cards you currently have access to print.",

"text_buy": "Buy",
"text_apply": "Apply",
Expand Down
9 changes: 5 additions & 4 deletions server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ RegisterNetEvent('mtc-cityhall:server:ApplyJob', function(id)
end)

RegisterNetEvent('mtc-cityhall:server:BuyIdentity', function(id)
local Player = QBCore.Functions.GetPlayer(source)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end

local item = Config.items[id]
if not item then return end

if not Player.Functions.RemoveMoney('bank', item.price, "Cityhall purchase") then
TriggerClientEvent('QBCore:Notify', source, Lang['not_enough_money'], 'error')
TriggerClientEvent('QBCore:Notify', src, Lang['not_enough_money'], 'error')
return
end

Expand All @@ -43,6 +44,6 @@ RegisterNetEvent('mtc-cityhall:server:BuyIdentity', function(id)
end

Player.Functions.AddItem(item.item, 1, false, info)
TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[item.item], 'add')
TriggerClientEvent('QBCore:Notify', source, Lang['bought']:format(item.label), 'success')
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item.item], 'add')
TriggerClientEvent('QBCore:Notify', src, Lang['bought']:format(item.label), 'success')
end)

0 comments on commit 396b59e

Please sign in to comment.