Skip to content

Commit

Permalink
Merge pull request #34 from Sqrl34/main
Browse files Browse the repository at this point in the history
[WIP] feat: add admin command
  • Loading branch information
alberttheprince authored Aug 12, 2024
2 parents 7f22d9b + fce3db1 commit b5febd2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
10 changes: 6 additions & 4 deletions client/menus/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions client/zones.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
43 changes: 43 additions & 0 deletions server.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)

0 comments on commit b5febd2

Please sign in to comment.