Skip to content

Commit

Permalink
feat! replace QBCore support with Qbox
Browse files Browse the repository at this point in the history
  • Loading branch information
NietThijmen committed Aug 11, 2024
1 parent 09da141 commit 0a151de
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 78 deletions.
19 changes: 6 additions & 13 deletions client/nui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ NUI = {}
--- Open the NUI with playerdata setup
function NUI:Open()
local headshot = GetHeadshot()
local PlayerData = QBCore.Functions.GetPlayerData()

local name = PlayerData.charinfo.firstname .. " " .. PlayerData.charinfo.lastname
local citizenid = PlayerData.citizenid
local name = QBX.PlayerData.charinfo.firstname .. " " .. QBX.PlayerData.charinfo.lastname
local citizenid = QBX.PlayerData.citizenid

if not headshot then
print("Failed to get headshot")
Expand Down Expand Up @@ -37,11 +36,11 @@ end
---Setup the jobs for the NUI
function NUI:SetupJobs()
local jobs = {}

local coreJobs = exports.qbx_core:GetJobs()
for key = 1, #Config.jobs, 1 do
jobs[#jobs + 1] = {
name = Config.jobs[key].label,
salary = QBCore.Shared.Jobs[Config.jobs[key].job].grades["0"].payment, -- Pulls the salary data from QBCore, Credit to 42MARTIN42 for the change, instead of using a set config value using - Config.jobs[key].salary,
salary = coreJobs[Config.jobs[key].job].grades[0].payment, -- Pulls the salary data from QBCore, Credit to 42MARTIN42 for the change, instead of using a set config value using - Config.jobs[key].salary,
id = key
}
end
Expand All @@ -55,13 +54,7 @@ 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"]
local PlayerLicenses = QBX.PlayerData.metadata["licences"]

for key = 1, #Config.items, 1 do
for k, value in pairs(PlayerLicenses) do
Expand All @@ -83,7 +76,7 @@ end

--- Setup the licenses/information for the NUI
function NUI:SetupLicenses()
local PlayerLicenses = QBCore.Functions.GetPlayerData().metadata["licences"]
local PlayerLicenses = QBX.PlayerData.metadata["licences"]
local LicenseItems = {}
local Licenses = {}

Expand Down
40 changes: 22 additions & 18 deletions client/ped.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
CreateThread(function()
if not Config.ped.enabled then return end
local spawnedPed = nil

RequestModel(joaat(Config.ped.model))
while not HasModelLoaded(joaat(Config.ped.model)) do
Wait(100)
end
local point = lib.points.new({coords = Config.ped.coords.xyz, distance = 15})

local ped = CreatePed(4, joaat(Config.ped.model), Config.ped.coords, 0.0, false, false)
function point:onEnter()
if spawnedPed then return end
local pedHash = joaat(Config.ped.model)
lib.requestModel(pedHash)

spawnedPed = CreatePed(4, pedHash, Config.ped.coords, 0.0, false,
false)
SetBlockingOfNonTemporaryEvents(ped, true)
SetPedDiesWhenInjured(ped, false)
SetPedCanPlayAmbientAnims(ped, true)
Expand All @@ -15,15 +17,17 @@ CreateThread(function()
FreezeEntityPosition(ped, true)
SetEntityHeading(ped, Config.ped.coords.w)

-- Change to your target, ox_target should work because of the compatibility layer
exports['qb-target']:AddTargetEntity(ped, {
options = {
{
event = "mtc-cityhall:client:open",
icon = "fas fa-id-card",
label = Config.ped.label,
}
},
distance = 2.5
exports.ox_target:addLocalEntity(spawnedPed, {
{
event = "mtc-cityhall:client:open",
icon = "fas fa-id-card",
label = Config.ped.label
}
})
end)
end

function point:onExit()
if not spawnedPed then return end
DeleteEntity(spawnedPed)
spawnedPed = nil
end
2 changes: 1 addition & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ QBCore = exports['qb-core']:GetCoreObject()
Config = {}

Config.RenewedPhone = false --> Set to true if you are using Renewed scripts their qb-phone
Config.idcard = "default" -- default, bl_idcard, qbx_idcard, um_idcard
Config.idcard = "qbx_idcard" -- bl_idcard, qbx_idcard, um_idcard

-- Ped spawner
Config.ped = {
Expand Down
5 changes: 4 additions & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ fx_version 'cerulean'
games { 'rdr3', 'gta5' }

author 'More Than Code'
description 'Cityhall (mtc-cityhall) 1.0.0'
description 'Replacement cityhall script for qbx_core'
version '1.0.0'

client_scripts {
'@qbx_core/modules/playerdata.lua',
'client/headshot.lua',
'client/nui.lua',
'client/callbacks.lua',
Expand All @@ -20,6 +21,8 @@ server_scripts {
}

shared_scripts {
'@ox_lib/init.lua',
'@qbx_core/modules/lib.lua',
'config.lua',
'lang.lua',
}
Expand Down
1 change: 1 addition & 0 deletions lang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Lang = {
['hired'] = "You have been hired as a %s!",
['not_enough_money'] = "You do not have enough money!",
['bought'] = "You have bought a %s!",
["no_space"] = "You don't have enough space to carry this. We've refunded your purchase"
}
3 changes: 1 addition & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
4. Trigger the event `mtc-cityhall:client:open` or the `Open` export.

### Dependencies

- [qb-core](https://github.com/qbcore-framework/qb-core) or [qbx-core](https://github.com/Qbox-project/qbx-core)
- [qbx_core](https://github.com/Qbox-project/qbx_core)

### How to change the UI language?

Expand Down
31 changes: 0 additions & 31 deletions server/idcard.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
local function default(source, item)
local Player = QBCore.Functions.GetPlayer(source)
local info = {}
if item.item == "id_card" then
info.citizenid = Player.PlayerData.citizenid
info.firstname = Player.PlayerData.charinfo.firstname
info.lastname = Player.PlayerData.charinfo.lastname
info.birthdate = Player.PlayerData.charinfo.birthdate
info.gender = Player.PlayerData.charinfo.gender
info.nationality = Player.PlayerData.charinfo.nationality
elseif item.item == "driver_license" then
info.firstname = Player.PlayerData.charinfo.firstname
info.lastname = Player.PlayerData.charinfo.lastname
info.birthdate = Player.PlayerData.charinfo.birthdate
info.gender = Player.PlayerData.charinfo.gender
info.type = "Class C Driver License"
elseif item.item == "weaponlicense" then
info.firstname = Player.PlayerData.charinfo.firstname
info.lastname = Player.PlayerData.charinfo.lastname
info.birthdate = Player.PlayerData.charinfo.birthdate
info.gender = Player.PlayerData.charinfo.gender
end

Player.Functions.AddItem(item.item, 1, false, info)
return true
end

local function bl_idcard(source, item)
exports.bl_idcard:createLicense(source, item.item)
return true
Expand All @@ -42,10 +15,6 @@ end

function giveIdCard(source, item)
if not item.id_card then return false end

if Config.idcard == "default" then
return default(source, item)
end

if Config.idcard == "bl_idcard" then
return bl_idcard(source, item)
Expand Down
27 changes: 15 additions & 12 deletions server/server.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
RegisterNetEvent('mtc-cityhall:server:ApplyJob', function(id)
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return end
local xPlayer = exports.qbx_core:GetPlayer(source)
if not xPlayer then return end

local job = Config.jobs[id]
if not job then return end

Player.Functions.SetJob(job.job, 0)
xPlayer.Functions.SetJob(job.job, 0)
if Config.RenewedPhone then
exports['qb-phone']:hireUser(job.job, Player.PlayerData.citizenid, 0)
end
TriggerClientEvent('QBCore:Notify', source, Lang['hired']:format(job.label), 'success')
end)

RegisterNetEvent('mtc-cityhall:server:BuyIdentity', function(id)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
local xPlayer = exports.qbx_core:GetPlayer(source)
if not xPlayer 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', src, Lang['not_enough_money'], 'error')
if not exports.ox_inventory:CanCarryItem(source, item.item) then
TriggerClientEvent('QBCore:Notify', source, Lang['no_space'], 'error')
return
end

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

if not giveIdCard(src, item) then -- Handles id_card items using qb-inventory or um_idcard if it was not an id_card give the item to the user
Player.Functions.AddItem(item.item, 1, false)
if not giveIdCard(source, item) then -- Handles id_card items using qb-inventory or um_idcard if it was not an id_card give the item to the user
exports.ox_inventory:AddItem(source, item.item)
end

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

0 comments on commit 0a151de

Please sign in to comment.