1
0
Fork 0
forked from Simnation/Main
Main/resources/[carscripts]/ox_commands/client/carmenu.lua
2025-06-25 00:59:30 +02:00

122 lines
3.2 KiB
Lua

local lastVehicle
local modLivery
local menu = {
id = 'ox_commands:carMenu',
title = 'Vehicle Mods',
options = {}
}
-- Client-side group check
local function hasAdminPermission()
local playerGroups = exports.ox_core:GetPlayerData().groups
return playerGroups and playerGroups.admin
end
function menu.onSideScroll(selected, scrollIndex)
local option = menu.options[selected]
if scrollIndex ~= option.defaultIndex then
print('onSideScroll', selected, scrollIndex, option.modIndex)
option.defaultIndex = scrollIndex
lib.setMenuOptions(menu.id, option, selected)
if option.modIndex == 48 and not modLivery then
return SetVehicleLivery(lastVehicle, scrollIndex - 2)
end
SetVehicleMod(lastVehicle, option.modIndex, scrollIndex - 2, false)
end
end
-- Vehicle mod type mapping (same as original)
local vehicleModType = {
[0] = 'VMT_SPOILER',
[1] = 'VMT_BUMPER_F',
-- ... rest of your existing vehicleModType table ...
[49] = 'VMT_LIGHTBAR'
}
local GetLiveryName = GetLiveryName
local GetModTextLabel = GetModTextLabel
local GetLabelText = GetLabelText
local function createModEntry(index, vehicle, modCount)
local entries = table.create(modCount, 0)
for j = -1, modCount - 1 do
local label = (index == 48 and not modLivery) and GetLiveryName(vehicle, j) or GetModTextLabel(vehicle, index, j)
local j2 = j + 2
entries[j2] = label and GetLabelText(label) or (j == -1 and 'Stock') or j2
end
local modType = vehicleModType[index]
return {
label = modType,
description = ('Change the current %s'):format(modType),
values = entries,
modIndex = index,
defaultIndex = GetVehicleMod(vehicle, index) + 1
}
end
local SetVehicleModKit = SetVehicleModKit
local GetNumVehicleMods = GetNumVehicleMods
local GetVehicleLiveryCount = GetVehicleLiveryCount
local function setupVehicleMods(vehicle)
if vehicle == lastVehicle then return menu end
SetVehicleModKit(vehicle, 0)
modLivery = true
local options = {}
local count = 0
for i = 0, 49 do
local modCount = GetNumVehicleMods(vehicle, i)
if i == 48 and modCount == 0 then
modCount = GetVehicleLiveryCount(vehicle)
if modCount ~= 0 then
modLivery = false
end
end
if modCount > 0 then
count += 1
options[count] = createModEntry(i, vehicle, modCount)
end
end
menu.options = options
lib.registerMenu(menu)
lastVehicle = vehicle
return true
end
RegisterCommand('carmenu', function()
-- Admin restriction check
if not hasAdminPermission() then
lib.notify({
title = 'Permission Denied',
description = 'This command is restricted to administrators',
type = 'error'
})
return
end
if not cache.vehicle then
lib.notify({
title = 'Error',
description = 'You must be in a vehicle to use this command',
type = 'error'
})
return
end
if setupVehicleMods(cache.vehicle) then
lib.showMenu('ox_commands:carMenu')
end
end, false)