Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: utils to lib and proper function casing #46

Merged
merged 2 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/admin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ lib.registerMenu({
title = locale('title.admin_menu'),
position = 'top-right',
onClose = function(keyPressed)
closeMenu(false, keyPressed, 'qbx_adminmenu_main_menu')
CloseMenu(false, keyPressed, 'qbx_adminmenu_main_menu')
end,
onSelected = function(selected)
MenuIndexes.qbx_adminmenu_admin_menu = selected
Expand Down
39 changes: 33 additions & 6 deletions client/dev.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ local options = {
showCoords = not showCoords
while showCoords do
local coords, heading = GetEntityCoords(cache.ped), GetEntityHeading(cache.ped)
DrawText2D(string.format('~o~vector4~w~(%s, %s, %s, %s)', math.round(coords.x, 2), math.round(coords.y, 2), math.round(coords.z, 2), math.round(heading, 2)), vec2(1.0, 0.5), 1.0, 1.0, 0.5, 6, 255, 255, 255)

qbx.drawText2d({
text = ('~o~vector4~w~(%s, %s, %s, %s)'):format(qbx.math.round(coords.x, 2), qbx.math.round(coords.y, 2), qbx.math.round(coords.z, 2), qbx.math.round(heading, 2)),
coords = vec2(1.0, 0.5),
scale = 0.5,
font = 6
})

Wait(0)
end
end,
Expand All @@ -22,10 +29,30 @@ local options = {
local oil, angle, body, class = GetVehicleOilLevel(cache.vehicle), GetVehicleSteeringAngle(cache.vehicle), GetVehicleBodyHealth(cache.vehicle), vehicleTypes[GetVehicleClass(cache.vehicle)]
local dirt, maxSpeed, netId, hash = GetVehicleDirtLevel(cache.vehicle), GetVehicleEstimatedMaxSpeed(cache.vehicle), VehToNet(cache.vehicle), GetEntityModel(cache.vehicle)
local name = GetLabelText(GetDisplayNameFromVehicleModel(hash))
DrawText2D(string.format('~o~Clutch: ~w~ %s | ~o~Gear: ~w~ %s | ~o~Rpm: ~w~ %s | ~o~Temperature: ~w~ %s', math.round(clutch, 4), gear, math.round(rpm, 4), temperature), vec2(1.0, 0.575), 1.0, 1.0, 0.45, 6, 255, 255, 255)
DrawText2D(string.format('~o~Oil: ~w~ %s | ~o~Steering Angle: ~w~ %s | ~o~Body: ~w~ %s | ~o~Class: ~w~ %s', math.round(oil, 4), math.round(angle, 4), math.round(body, 4), class), vec2(1.0, 0.600), 1.0, 1.0, 0.45, 6, 255, 255, 255)
DrawText2D(string.format('~o~Dirt: ~w~ %s | ~o~Est Max Speed: ~w~ %s | ~o~Net ID: ~w~ %s | ~o~Hash: ~w~ %s', math.round(dirt, 4), math.round(maxSpeed, 4) * 3.6, netId, hash), vec2(1.0, 0.625), 1.0, 1.0, 0.45, 6, 255, 255, 255)
DrawText2D(string.format('~o~Vehicle Name: ~w~ %s', name), vec2(1.0, 0.650), 1.0, 1.0, 0.45, 6, 255, 255, 255)
qbx.drawText2d({
text = ('~o~Clutch: ~w~ %s | ~o~Gear: ~w~ %s | ~o~Rpm: ~w~ %s | ~o~Temperature: ~w~ %s'):format(qbx.math.round(clutch, 4), gear, qbx.math.round(rpm, 4), temperature),
coords = vec2(1.0, 0.575),
scale = 0.45,
font = 6
})
qbx.drawText2d({
text = ('~o~Oil: ~w~ %s | ~o~Steering Angle: ~w~ %s | ~o~Body: ~w~ %s | ~o~Class: ~w~ %s'):format(qbx.math.round(oil, 4), qbx.math.round(angle, 4), qbx.math.round(body, 4), class),
coords = vec2(1.0, 0.600),
scale = 0.45,
font = 6
})
qbx.drawText2d({
text = ('~o~Dirt: ~w~ %s | ~o~Est Max Speed: ~w~ %s | ~o~Net ID: ~w~ %s | ~o~Hash: ~w~ %s'):format(qbx.math.round(dirt, 4), qbx.math.round(maxSpeed, 4) * 3.6, netId, hash),
coords = vec2(1.0, 0.625),
scale = 0.45,
font = 6
})
qbx.drawText2d({
text = ('~o~Vehicle Name: ~w~ %s'):format(name),
coords = vec2(1.0, 0.650),
scale = 0.45,
font = 6
})
Wait(0)
else
Wait(800)
Expand All @@ -39,7 +66,7 @@ lib.registerMenu({
title = locale('title.dev_menu'),
position = 'top-right',
onClose = function(keyPressed)
closeMenu(false, keyPressed, 'qbx_adminmenu_main_menu')
CloseMenu(false, keyPressed, 'qbx_adminmenu_main_menu')
end,
onSelected = function(selected)
MenuIndexes.qbx_adminmenu_dev_menu = selected
Expand Down
4 changes: 2 additions & 2 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lib.registerMenu({
title = locale('title.main_menu'),
position = 'top-right',
onClose = function()
closeMenu(true)
CloseMenu(true)
end,
onSelected = function(selected)
MenuIndexes.qbx_adminmenu_main_menu = selected
Expand All @@ -25,7 +25,7 @@ lib.registerMenu({
end
end)

function closeMenu(isFullMenuClose, keyPressed, previousMenu)
function CloseMenu(isFullMenuClose, keyPressed, previousMenu)
if isFullMenuClose or not keyPressed or keyPressed == 'Escape' then
lib.hideMenu(false)
return
Expand Down
10 changes: 5 additions & 5 deletions client/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function GeneratePlayersMenu()
title = locale('title.players_menu'),
position = 'top-right',
onClose = function(keyPressed)
closeMenu(false, keyPressed, 'qbx_adminmenu_main_menu')
CloseMenu(false, keyPressed, 'qbx_adminmenu_main_menu')
end,
onSelected = function(selected)
MenuIndexes.qbx_adminmenu_players_menu = selected
Expand All @@ -160,7 +160,7 @@ function GeneratePlayersMenu()
title = player.name,
position = 'top-right',
onClose = function(keyPressed)
closeMenu(false, keyPressed, 'qbx_adminmenu_players_menu')
CloseMenu(false, keyPressed, 'qbx_adminmenu_players_menu')
end,
onSelected = function(selected)
MenuIndexes[('qbx_adminmenu_player_menu_%s'):format(args[1].id)] = selected
Expand Down Expand Up @@ -200,7 +200,7 @@ lib.registerMenu({
title = locale('player_options.label1'),
position = 'top-right',
onClose = function(keyPressed)
closeMenu(false, keyPressed, ('qbx_adminmenu_player_menu_%s'):format(selectedPlayer?.id))
CloseMenu(false, keyPressed, ('qbx_adminmenu_player_menu_%s'):format(selectedPlayer?.id))
end,
onSelected = function(selected)
MenuIndexes.qbx_adminmenu_player_general_menu = selected
Expand Down Expand Up @@ -232,7 +232,7 @@ lib.registerMenu({
title = locale('player_options.label2'),
position = 'top-right',
onClose = function(keyPressed)
closeMenu(false, keyPressed, ('qbx_adminmenu_player_menu_%s'):format(selectedPlayer?.id))
CloseMenu(false, keyPressed, ('qbx_adminmenu_player_menu_%s'):format(selectedPlayer?.id))
end,
onSelected = function(selected)
MenuIndexes.qbx_adminmenu_player_administration_menu = selected
Expand Down Expand Up @@ -270,7 +270,7 @@ lib.registerMenu({
title = locale('player_options.label2'),
position = 'top-right',
onClose = function(keyPressed)
closeMenu(false, keyPressed, ('qbx_adminmenu_player_menu_%s'):format(selectedPlayer?.id))
CloseMenu(false, keyPressed, ('qbx_adminmenu_player_menu_%s'):format(selectedPlayer?.id))
end,
onSelected = function(selected)
MenuIndexes.qbx_adminmenu_player_extra_menu = selected
Expand Down
2 changes: 1 addition & 1 deletion client/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ lib.registerMenu({
title = locale('title.server_menu'),
position = 'top-right',
onClose = function(keyPressed)
closeMenu(false, keyPressed, 'qbx_adminmenu_main_menu')
CloseMenu(false, keyPressed, 'qbx_adminmenu_main_menu')
end,
onSelected = function(selected)
MenuIndexes.qbx_adminmenu_server_menu = selected
Expand Down
4 changes: 2 additions & 2 deletions client/vectors.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function CopyToClipboard(dataType)
local coords = GetEntityCoords(cache.ped)
local x, y, z = math.round(coords.x, 2), math.round(coords.y, 2), math.round(coords.z, 2)
local x, y, z = qbx.math.round(coords.x, 2), qbx.math.round(coords.y, 2), qbx.math.round(coords.z, 2)
local heading = GetEntityHeading(cache.ped)
local h = math.round(heading, 2)
local h = qbx.math.round(heading, 2)

local data
local message
Expand Down
10 changes: 5 additions & 5 deletions client/vehicle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ function GenerateVehiclesSpawnMenu()
end)

for i = 1, #categories do
lib.setMenuOptions('qbx_adminmenu_spawn_vehicles_menu', {label = string.firstToUpper(categories[i]), args = {('qbx_adminmenu_spawn_vehicles_menu_%s'):format(categories[i])}}, i)
lib.setMenuOptions('qbx_adminmenu_spawn_vehicles_menu', {label = qbx.string.capitalize(categories[i]), args = {('qbx_adminmenu_spawn_vehicles_menu_%s'):format(categories[i])}}, i)

lib.registerMenu({
id = ('qbx_adminmenu_spawn_vehicles_menu_%s'):format(categories[i]),
title = categories[i],
position = 'top-right',
onClose = function(keyPressed)
closeMenu(false, keyPressed, 'qbx_adminmenu_spawn_vehicles_menu')
CloseMenu(false, keyPressed, 'qbx_adminmenu_spawn_vehicles_menu')
end,
onSelected = function(selected)
MenuIndexes[('qbx_adminmenu_spawn_vehicles_menu_%s'):format(categories[i])] = selected
Expand All @@ -49,7 +49,7 @@ function GenerateVehiclesSpawnMenu()
veh = NetToVeh(vehNetId)
Wait(100)
until DoesEntityExist(veh)
TriggerEvent('qb-vehiclekeys:client:AddKeys', GetPlate(veh))
TriggerEvent('qb-vehiclekeys:client:AddKeys', qbx.getVehiclePlate(veh))
SetVehicleNeedsToBeHotwired(veh, false)
SetVehicleHasBeenOwnedByPlayer(veh, true)
SetEntityAsMissionEntity(veh, true, false)
Expand Down Expand Up @@ -86,7 +86,7 @@ lib.registerMenu({
title = 'Vehicles',
position = 'top-right',
onClose = function(keyPressed)
closeMenu(false, keyPressed, 'qbx_adminmenu_main_menu')
CloseMenu(false, keyPressed, 'qbx_adminmenu_main_menu')
end,
onSelected = function(selected)
MenuIndexes.qbx_adminmenu_vehicles_menu = selected
Expand Down Expand Up @@ -165,7 +165,7 @@ lib.registerMenu({
title = 'Spawn Vehicle',
position = 'top-right',
onClose = function(keyPressed)
closeMenu(false, keyPressed, 'qbx_adminmenu_main_menu')
CloseMenu(false, keyPressed, 'qbx_adminmenu_main_menu')
end,
onSelected = function(selected)
MenuIndexes.qbx_adminmenu_spawn_vehicles_menu = selected
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ox_lib 'locale'

shared_scripts {
'@ox_lib/init.lua',
'@qbx_core/modules/utils.lua',
'@qbx_core/modules/lib.lua',
}

server_scripts {
Expand Down
13 changes: 11 additions & 2 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ lib.callback.register('qbx_admin:server:canUseMenu', function(source)
end)

lib.callback.register('qbx_admin:server:spawnVehicle', function(source, model)
local hash = joaat(model)
return SpawnVehicle(source, hash, nil, true)
local ped = GetPlayerPed(source)
local netId = qbx.spawnVehicle({
model = model,
spawnSource = ped,
warp = true,
})

local plate = qbx.getVehiclePlate(NetworkGetEntityFromNetworkId(netId))

exports.qbx_vehiclekeys:GiveKeys(source, plate)
return netId
end)
Loading