From c736a88a3d9ea51328ae8729aebc636bf7781858 Mon Sep 17 00:00:00 2001 From: Sqrl Date: Fri, 9 Aug 2024 21:48:08 -0700 Subject: [PATCH 1/6] feat: add admin command command to change vehicles anywhere and for free. --- client/menus/main.lua | 4 ---- client/zones.lua | 15 +++++++++++++++ server.lua | 29 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/client/menus/main.lua b/client/menus/main.lua index ed00cad..3f17297 100644 --- a/client/menus/main.lua +++ b/client/menus/main.lua @@ -128,10 +128,6 @@ end menu.onClose = function() inMenu = false stopDragCam() - lib.showTextUI('Press [E] to tune your car', { - icon = 'fa-solid fa-car', - position = 'left-center', - }) if QBCore then TriggerServerEvent("customs:server:saveVehicleProps") end diff --git a/client/zones.lua b/client/zones.lua index d879d3c..e4e2474 100644 --- a/client/zones.lua +++ b/client/zones.lua @@ -83,3 +83,18 @@ end) lib.callback.register('customs:client:zone', function() return zoneId end) + +RegisterNetEvent('customs:client:adminMenu', function() + local perm = lib.callback.await('customs:server:checkPerms') + if perm then + SetEntityVelocity(cache.vehicle, 0.0, 0.0, 0.0) + require('client.menus.main')() + else + lib.notify({ + title = 'Customs', + description = 'Cound not access menu or no vehicle present', + position = 'top', + type = 'error' + }) + end +end) \ No newline at end of file diff --git a/server.lua b/server.lua index 6a39986..e55d69e 100644 --- a/server.lua +++ b/server.lua @@ -1,6 +1,8 @@ local QBCore +local currentAdmins = {} if GetResourceState('qb-core') == 'started' then QBCore = exports['qb-core']:GetCoreObject() + lib.addAce('group.admin', 'customs.admin') else warn('qb-core is missing, modifications won\'t cost anything') end @@ -39,10 +41,22 @@ local function removeMoney(source, amount) return false end +lib.callback.register('customs:server:checkPerms', function(source) + if IsPlayerAceAllowed(source, 'customs.admin') then + return true + else + return false + end +end) + -- Won't charge money for mods if the player's job is in the list lib.callback.register('customs:server:pay', function(source, mod, level) local zone = lib.callback.await('customs:client:zone', source) + if currentAdmins[source].admin then + return true + end + for i, v in ipairs(Config.Zones) do if i == zone and v.freeMods then local playerJob = QBCore.Functions.GetPlayer(source)?.PlayerData?.job?.name @@ -61,6 +75,10 @@ end) lib.callback.register('customs:server:repair', function(source, bodyHealth) local zone = lib.callback.await('customs:client:zone', source) + if currentAdmins[source].admin then + return true + end + for i, v in ipairs(Config.Zones) do if i == zone and v.freeRepair then local playerJob = QBCore.Functions.GetPlayer(source)?.PlayerData?.job?.name @@ -89,7 +107,18 @@ end RegisterNetEvent('customs:server:saveVehicleProps', function() local src = source --[[@as number]] local vehicleProps = lib.callback.await('customs:client:vehicleProps', src) + currentAdmins[src].admin = false if IsVehicleOwned(vehicleProps.plate) then MySQL.update.await('UPDATE player_vehicles SET mods = ? WHERE plate = ?', {json.encode(vehicleProps), vehicleProps.plate}) end end) + +--Commands +lib.addCommand('admincustoms', { + help = 'Toggle customs menu for admins', + restricted = 'group.admin', +}, function(source, args, raw) + currentAdmins[source] = {} + currentAdmins[source].admin = true + TriggerClientEvent('customs:client:adminMenu', source) +end) \ No newline at end of file From 6af0b40ff7ccd23557fc84df1c956bacbc845365 Mon Sep 17 00:00:00 2001 From: Sqrl Date: Fri, 9 Aug 2024 22:29:05 -0700 Subject: [PATCH 2/6] fix: admin check --- server.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server.lua b/server.lua index e55d69e..91d0e61 100644 --- a/server.lua +++ b/server.lua @@ -107,6 +107,7 @@ end RegisterNetEvent('customs:server:saveVehicleProps', function() local src = source --[[@as number]] local vehicleProps = lib.callback.await('customs:client:vehicleProps', src) + currentAdmins[src] = currentAdmins[src] or {} currentAdmins[src].admin = false if IsVehicleOwned(vehicleProps.plate) then MySQL.update.await('UPDATE player_vehicles SET mods = ? WHERE plate = ?', {json.encode(vehicleProps), vehicleProps.plate}) @@ -118,7 +119,7 @@ lib.addCommand('admincustoms', { help = 'Toggle customs menu for admins', restricted = 'group.admin', }, function(source, args, raw) - currentAdmins[source] = {} + currentAdmins[source] = currentAdmins[source] or {} currentAdmins[source].admin = true TriggerClientEvent('customs:client:adminMenu', source) end) \ No newline at end of file From 7a6d33d5916c85dc51964140381e8b10418031c6 Mon Sep 17 00:00:00 2001 From: Sqrl Date: Sun, 11 Aug 2024 17:07:13 -0700 Subject: [PATCH 3/6] fix: add guard clause --- server.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server.lua b/server.lua index 91d0e61..5b4e6f4 100644 --- a/server.lua +++ b/server.lua @@ -53,8 +53,10 @@ end) lib.callback.register('customs:server:pay', function(source, mod, level) local zone = lib.callback.await('customs:client:zone', source) - if currentAdmins[source].admin then - return true + if currentAdmins[source] then + if currentAdmins[source].admin then + return true + end end for i, v in ipairs(Config.Zones) do @@ -75,8 +77,10 @@ end) lib.callback.register('customs:server:repair', function(source, bodyHealth) local zone = lib.callback.await('customs:client:zone', source) - if currentAdmins[source].admin then - return true + if currentAdmins[source] then + if currentAdmins[source].admin then + return true + end end for i, v in ipairs(Config.Zones) do From 6542a5a7a15bbb0edcdb254475c4a904684b1a56 Mon Sep 17 00:00:00 2001 From: Sqrl Date: Sun, 11 Aug 2024 17:21:06 -0700 Subject: [PATCH 4/6] fix: group.admin -> customs.admin --- server.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.lua b/server.lua index 5b4e6f4..c6e6b0b 100644 --- a/server.lua +++ b/server.lua @@ -121,7 +121,7 @@ end) --Commands lib.addCommand('admincustoms', { help = 'Toggle customs menu for admins', - restricted = 'group.admin', + restricted = 'customs.admin', }, function(source, args, raw) currentAdmins[source] = currentAdmins[source] or {} currentAdmins[source].admin = true From f4975823242d3a56a14ab3c83863fe505dd48184 Mon Sep 17 00:00:00 2001 From: Sqrl Date: Sun, 11 Aug 2024 21:01:09 -0700 Subject: [PATCH 5/6] reverted text ui removal --- client/menus/main.lua | 6 ++++++ server.lua | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/client/menus/main.lua b/client/menus/main.lua index 3f17297..1924cc6 100644 --- a/client/menus/main.lua +++ b/client/menus/main.lua @@ -128,6 +128,12 @@ end menu.onClose = function() inMenu = false stopDragCam() + if not lib.callback.await('customs:server:adminMenuOpened') then + lib.showTextUI('Press [E] to tune your car', { + icon = 'fa-solid fa-car', + position = 'left-center', + }) + end if QBCore then TriggerServerEvent("customs:server:saveVehicleProps") end diff --git a/server.lua b/server.lua index c6e6b0b..550caa7 100644 --- a/server.lua +++ b/server.lua @@ -98,6 +98,15 @@ lib.callback.register('customs:server:repair', function(source, bodyHealth) return removeMoney(source, price) end) +lib.callback.register('customs:server:adminMenuOpened', function(source) + if currentAdmins[source] then + if currentAdmins[source].admin then + return true + end + end + return false +end) + local function IsVehicleOwned(plate) local result = MySQL.scalar.await('SELECT 1 from player_vehicles WHERE plate = ?', {plate}) if result then From fce3db16b40b67270eb4b31548fcbb6a065250d4 Mon Sep 17 00:00:00 2001 From: Sqrl Date: Mon, 12 Aug 2024 02:09:29 -0700 Subject: [PATCH 6/6] bump version 1.3.3 -> 1.4 --- fxmanifest.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fxmanifest.lua b/fxmanifest.lua index 99ec359..1f61e82 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -7,7 +7,7 @@ author 'Jorn#0008' name 'popcornrp-customs' description 'Customs script using ox_lib' repository 'https://github.com/alberttheprince/popcornrp-customs' -version '1.3.3' +version '1.4.0' ui_page 'web/index.html'