Skip to content

Commit

Permalink
fix: RadialMenu seat changing menu and add missing language options i…
Browse files Browse the repository at this point in the history
…n en locale (#66)

* fix: add missing error message (Locale: en) for seat_occupied

* fix: corrected config.vehicleSeats key, changed title -> label as ox_lib does not support title option

* fix: resolve vehicle seat changing menu bug in radialemenu

* refactor : used lib.onCache instead of events

* refactor: added all the missing options in Locale -> en.json
  • Loading branch information
frostfire575 authored Dec 18, 2024
1 parent 574e401 commit 9ae4101
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 114 deletions.
146 changes: 87 additions & 59 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
local config = require 'config.client'

-----------------------
------- Events --------
-----------------------

if config.vehicleSeats then
lib.onCache('vehicle', function(vehicle)
if vehicle then
setupVehicleMenu(true)
local vehicleSeats = {}
local veh = vehicle
local amountOfSeats = GetVehicleModelNumberOfSeats(GetEntityModel(veh))

local seatTable = {
[1] = locale('options.driver_seat'),
[2] = locale('options.passenger_seat'),
[3] = locale('options.rear_left_seat'),
[4] = locale('options.rear_right_seat')
}

for i = 1, amountOfSeats do
vehicleSeats[#vehicleSeats + 1] = {
id = 'vehicleSeat' .. i,
label = seatTable[i] or locale('options.other_seats'),
icon = 'caret-up',
onSelect = function()
if cache.vehicle then
TriggerEvent('radialmenu:client:ChangeSeat', i,
seatTable[i] or locale('options.other_seats'))
else
exports.qbx_core:Notify(locale('error.not_in_vehicle'), 'error')
end
lib.hideRadial()
end
}
end

lib.registerRadial({
id = 'vehicleSeatsMenu',
items = vehicleSeats
})
else
setupVehicleMenu(false)
end
end)

end

-----------------------
------ Functions ------
-----------------------

local function convert(tbl)
if tbl.items then
local items = {}
Expand All @@ -8,15 +59,15 @@ local function convert(tbl)
end

lib.registerRadial({
id = tbl.id..'Menu',
id = tbl.id .. 'Menu',
items = items
})

return {
id = tbl.id,
label = tbl.label,
icon = tbl.icon,
menu = tbl.id..'Menu'
menu = tbl.id .. 'Menu'
}
end

Expand All @@ -42,52 +93,15 @@ local function convert(tbl)
label = tbl.label,
icon = tbl.icon,
onSelect = tbl.onSelect or function()
if action then action() end
if action then
action()
end
end,
keepOpen = tbl.keepOpen
}
end

local function addVehicleSeats() -- luacheck: ignore
while true do
if IsPedInAnyVehicle(cache.ped, true) and not cache.vehicle then
local coords = GetEntityCoords(cache.ped)
local vehicle = lib.getClosestVehicle(coords)
if vehicle then
local vehicleSeats = {}
local seatTable = {
[1] = locale('options.driver_seat'),
[2] = locale('options.passenger_seat'),
[3] = locale('options.rear_left_seat'),
[4] = locale('options.rear_right_seat'),
}
local amountOfSeats = GetVehicleModelNumberOfSeats(GetEntityModel(vehicle))
for i = 1, amountOfSeats do
vehicleSeats[#vehicleSeats + 1] = {
id = 'vehicleSeat'..i,
label = seatTable[i] or locale('options.other_seats'),
icon = 'caret-up',
onSelect = function()
if cache.vehicle then
TriggerEvent('radialmenu:client:ChangeSeat', i, seatTable[i] or locale('options.other_seats'))
else
exports.qbx_core:Notify(locale('error.not_in_vehicle'), 'error')
end
lib.hideRadial()
end,
}
end
lib.registerRadial({
id = 'vehicleSeatsMenu',
items = vehicleSeats
})
end
end
Wait(1000)
end
end

local function setupVehicleMenu()
function setupVehicleMenu(seat)
local vehicleMenu = {
id = 'vehicle',
label = locale('options.vehicle'),
Expand All @@ -102,7 +116,7 @@ local function setupVehicleMenu()
onSelect = function()
TriggerEvent('radialmenu:flipVehicle')
lib.hideRadial()
end,
end
}}

vehicleItems[#vehicleItems + 1] = convert(config.vehicleDoors)
Expand All @@ -111,10 +125,9 @@ local function setupVehicleMenu()
vehicleItems[#vehicleItems + 1] = convert(config.vehicleExtras)
end

--[[if config.vehicleSeats then
CreateThread(addVehicleSeats)
if config.vehicleSeats and seat then
vehicleItems[#vehicleItems + 1] = config.vehicleSeats
end]]--
end

lib.registerRadial({
id = 'vehicleMenu',
Expand All @@ -140,7 +153,9 @@ local function setupRadialMenu()
}))
end

if not config.jobItems[QBX.PlayerData.job.name] or not QBX.PlayerData.job.onduty then return end
if not config.jobItems[QBX.PlayerData.job.name] or not QBX.PlayerData.job.onduty then
return
end

lib.addRadialItem(convert({
id = 'jobInteractions',
Expand All @@ -162,13 +177,15 @@ end
RegisterNetEvent('radialmenu:client:deadradial', function(isDead)
if isDead then
local ispolice, isems = isPolice(), isEMS()
if not ispolice or isems then return lib.disableRadial(true) end
if not ispolice or isems then
return lib.disableRadial(true)
end
lib.clearRadialItems()
lib.addRadialItem({
id = 'emergencybutton2',
label = locale('options.emergency_button'),
icon = 'circle-exclamation',
onSelect = function ()
onSelect = function()
if ispolice then
TriggerEvent('police:client:SendPoliceEmergencyAlert')
elseif isems then
Expand Down Expand Up @@ -207,10 +224,14 @@ RegisterNetEvent('radialmenu:client:ChangeSeat', function(id, label)
end)

RegisterNetEvent('qb-radialmenu:trunk:client:Door', function(plate, door, open)
if not cache.vehicle then return end
if not cache.vehicle then
return
end

local pl = qbx.getVehiclePlate(cache.vehicle)
if pl ~= plate then return end
if pl ~= plate then
return
end

if open then
SetVehicleDoorOpen(cache.vehicle, door, false, false)
Expand Down Expand Up @@ -278,10 +299,14 @@ RegisterNetEvent('radialmenu:client:setExtra', function(id)
end)

RegisterNetEvent('radialmenu:flipVehicle', function()
if cache.vehicle then return end
if cache.vehicle then
return
end
local coords = GetEntityCoords(cache.ped)
local vehicle = lib.getClosestVehicle(coords)
if not vehicle then return exports.qbx_core:Notify(locale('error.no_vehicle_nearby'), 'error') end
if not vehicle then
return exports.qbx_core:Notify(locale('error.no_vehicle_nearby'), 'error')
end
if lib.progressBar({
label = locale('progress.flipping_car'),
duration = config.flipTime,
Expand All @@ -296,9 +321,8 @@ RegisterNetEvent('radialmenu:flipVehicle', function()
anim = {
dict = 'mini@repair',
clip = 'fixing_a_ped'
},
})
then
}
}) then
SetVehicleOnGroundProperly(vehicle)
exports.qbx_core:Notify(locale('success.flipped_car'), 'success')
else
Expand All @@ -307,14 +331,18 @@ RegisterNetEvent('radialmenu:flipVehicle', function()
end)

AddEventHandler('onResourceStart', function(resource)
if cache.resource ~= resource then return end
if cache.resource ~= resource then
return
end
if LocalPlayer.state.isLoggedIn then
setupRadialMenu()
end
end)

AddEventHandler('onResourceStop', function(resource)
if cache.resource ~= resource then return end
if cache.resource ~= resource then
return
end
lib.clearRadialItems()
end)

Expand Down
2 changes: 1 addition & 1 deletion config/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ return {
vehicleSeats = {
id = 'vehicleSeats',
icon = 'chair',
title = 'Vehicle Seats',
label = 'Vehicle Seats',
menu = 'vehicleSeatsMenu'
},

Expand Down
107 changes: 53 additions & 54 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
{
"error": {
"no_people_nearby": "No Players Nearby",
"no_vehicle_found": "No Vehicle Found",
"extra_deactivated": "Extra %s Has Been Deactivated",
"extra_not_present": "Extra %s Is Not Present on This Vehicle",
"not_driver": "You Are Not the Driver of the Vehicle",
"vehicle_driving_fast": "This Vehicle Is Moving Too Fast",
"race_harness_on": "You Have a Race Harness On; You Can't Switch",
"obj_not_found": "Could Not Create the Requested Object",
"not_near_ambulance": "You Are Not Near an Ambulance",
"far_away": "You Are Too Far Away",
"not_kidnapped": "You Did Not Kidnap This Person",
"trunk_closed": "The Trunk Is Closed",
"cant_enter_trunk": "You Can't Get In This Trunk",
"already_in_trunk": "You Are Already In The Trunk",
"cancel_task": "Task Cancelled",
"someone_in_trunk": "Someone Is Already In The Trunk",
"no_vehicle_nearby": "No Vehicle Nearby For Flipping."
},
"progress": {
"flipping_car": "Flipping Vehicle..."
},
"success": {
"extra_activated": "Extra %s Has Been Activated",
"entered_trunk": "You're In The Trunk",
"flipped_car": "Vehicle Flipped Successfully!"
},
"info": {
"no_variants": "There Don't Seem to Be Any Variants for This",
"wrong_ped": "This Ped Model Does Not Allow for This Option",
"nothing_to_remove": "You Don't Appear to Have Anything to Remove",
"already_wearing": "You Are Already Wearing That"
},
"general": {
"command_description": "Open Radial Menu",
"get_out_trunk_button": "[E] Get Out Of The Trunk",
"close_trunk_button": "[G] Close The Trunk",
"open_trunk_button": "[G] Open The Trunk",
"getintrunk_command_desc": "Get In Trunk",
"putintrunk_command_desc": "Put Player In Trunk",
"gang_radial": "Gang",
"job_radial": "Job"
},
"options": {
"flip": "Flip Vehicle",
"vehicle": "Vehicle",
"emergency_button": "Emergency Button",
"driver_seat": "Drivers Seat",
"passenger_seat": "Passenger Seat",
"other_seats": "Other Seat",
"rear_left_seat": "Rear Left Seat",
"rear_right_seat": "Rear Right Seat"
}
"error": {
"no_people_nearby": "No players nearby.",
"no_vehicle_found": "No vehicle found.",
"extra_deactivated": "Extra %s has been deactivated.",
"extra_not_present": "Extra %s is not present on this vehicle.",
"not_driver": "You are not the driver of the vehicle.",
"vehicle_driving_fast": "This vehicle is going too fast.",
"seat_occupied": "This seat is occupied.",
"race_harness_on": "You have a racing harness. You cannot switch.",
"obj_not_found": "Unable to create the requested object.",
"not_near_ambulance": "You are not near an ambulance.",
"far_away": "You are too far away.",
"not_kidnapped": "You have not kidnapped this person.",
"trunk_closed": "The trunk is closed.",
"cant_enter_trunk": "You cannot enter this trunk.",
"already_in_trunk": "You are already in the trunk.",
"someone_in_trunk": "Someone is already in the trunk.",
"cancel_task": "Cancelled"
},
"progress": {
"flipping_car": "Flipping the vehicle..."
},
"success": {
"extra_activated": "Extra %s has been activated.",
"entered_trunk": "You are in the trunk."
},
"info": {
"no_variants": "There don't seem to be any variants for this.",
"wrong_ped": "This ped model does not allow this option.",
"nothing_to_remove": "You have nothing to remove.",
"already_wearing": "You are already wearing it.",
"switched_seats": "You are now in the %s."
},
"general": {
"command_description": "Open the Radial Menu",
"get_out_trunk_button": "[E] Exit Trunk",
"close_trunk_button": "[G] Close Trunk",
"open_trunk_button": "[G] Open Trunk",
"getintrunk_command_desc": "Enter the Trunk",
"putintrunk_command_desc": "Put the Player in the Trunk",
"gang_radial": "Gang",
"job_radial": "Job"
},
"options": {
"flip": "Flip the Vehicle",
"vehicle": "Vehicle",
"emergency_button": "Emergency Button",
"driver_seat": "Driver Seat",
"passenger_seat": "Passenger Seat",
"other_seats": "Other Seat",
"rear_left_seat": "Rear Left Seat",
"rear_right_seat": "Rear Right Seat"
}
}

0 comments on commit 9ae4101

Please sign in to comment.