diff --git a/client/menus/main.lua b/client/menus/main.lua index ed00cad..1924cc6 100644 --- a/client/menus/main.lua +++ b/client/menus/main.lua @@ -128,10 +128,12 @@ end menu.onClose = function() inMenu = false stopDragCam() - lib.showTextUI('Press [E] to tune your car', { - icon = 'fa-solid fa-car', - position = 'left-center', - }) + 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/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/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' diff --git a/server.lua b/server.lua index 6a39986..550caa7 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,24 @@ 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] then + if currentAdmins[source].admin then + return true + end + 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 +77,12 @@ end) lib.callback.register('customs:server:repair', function(source, bodyHealth) local zone = lib.callback.await('customs:client:zone', source) + if currentAdmins[source] then + if currentAdmins[source].admin then + return true + end + 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 @@ -76,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 @@ -89,7 +120,19 @@ 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}) end end) + +--Commands +lib.addCommand('admincustoms', { + help = 'Toggle customs menu for admins', + restricted = 'customs.admin', +}, function(source, args, raw) + currentAdmins[source] = currentAdmins[source] or {} + currentAdmins[source].admin = true + TriggerClientEvent('customs:client:adminMenu', source) +end) \ No newline at end of file