diff --git a/client/admin.lua b/client/admin.lua index d3fbeec..20b4555 100644 --- a/client/admin.lua +++ b/client/admin.lua @@ -481,3 +481,22 @@ RegisterNetEvent('qb-admin:client:Show', function(players) end end end) + +RegisterNetEvent('qb-admin:client:SaveCar', function() + local ped = cache.ped + local veh = GetVehiclePedIsIn(ped) + + if veh ~= nil and veh ~= 0 then + local plate = GetPlate(veh) + local props = lib.getVehicleProperties(veh) + local hash = props.model + local vehname = GetDisplayNameFromVehicleModel(hash):lower() + if exports.qbx_core:GetVehiclesByName()[vehname] then + TriggerServerEvent('admin:server:SaveCar', props, exports.qbx_core:GetVehiclesByName()[vehname], plate) + else + exports.qbx_core:Notify(Lang:t("error.no_store_vehicle_garage"), 'error') + end + else + exports.qbx_core:Notify(Lang:t("error.no_vehicle"), 'error') + end +end) diff --git a/client/dev.lua b/client/dev.lua index 03b7f8d..f2ba29e 100644 --- a/client/dev.lua +++ b/client/dev.lua @@ -51,8 +51,7 @@ lib.registerMenu({ {label = Lang:t('dev_options.label4'), description = Lang:t('dev_options.desc4'), icon = 'fas fa-compass'}, {label = Lang:t('dev_options.label5'), description = Lang:t('dev_options.desc5'), icon = 'fas fa-compass-drafting', close = false}, {label = Lang:t('dev_options.label6'), description = Lang:t('dev_options.desc6'), icon = 'fas fa-car-side', close = false}, - {label = Lang:t('admin_options.label1'), description = Lang:t('admin_options.desc1'), icon = 'fab fa-fly', close = false}, } }, function(selected) Options[selected]() -end) \ No newline at end of file +end) diff --git a/config.lua b/config.lua index 89ca29e..14e7dc6 100644 --- a/config.lua +++ b/config.lua @@ -22,6 +22,7 @@ Config.Events = { ['playeroptionsgeneral'] = 'mod', ['kick'] = 'mod', ['ban'] = 'admin', + ['savecar'] = 'god', ['changeperms'] = 'admin', ['clothing menu'] = 'admin', ['play sounds'] = 'admin', diff --git a/locales/en.lua b/locales/en.lua index 6c4ca65..50e2f0f 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -146,11 +146,15 @@ local Translations = { names_activated = 'Names activated', coords_copied = 'Coordinates copied to clipboard', heading_copied = 'Heading copied to clipboard', + success_vehicle_owner = 'The vehicle is now yours!', }, error = { no_perms = 'You don\'t have permission to do this', blips_deactivated = 'Blips deactivated', names_deactivated = 'Names deactivated', + failed_vehicle_owner = 'This vehicle is already yours..', + no_store_vehicle_garage = 'You cant store this vehicle in your garage..', + no_vehicle = 'You are not in a vehicle..', } } diff --git a/server/commands.lua b/server/commands.lua index 4bd04c0..95a5e45 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -12,6 +12,13 @@ lib.addCommand('noclip', { TriggerClientEvent('qb-admin:client:noclip', source) end) +lib.addCommand('admincar', { + help = 'Toggle Admin Car', + restricted = 'admin', +}, function(source) + TriggerClientEvent('qb-admin:client:SaveCar', source) +end) + lib.addCommand('names', { help = 'Toggle Player Names', restricted = 'admin', @@ -67,4 +74,4 @@ lib.addCommand('heading', { restricted = 'admin', }, function(source) TriggerClientEvent('qb-admin:client:copyToClipboard', source, 'heading') -end) \ No newline at end of file +end) diff --git a/server/main.lua b/server/main.lua index 0314e2b..e3a468d 100644 --- a/server/main.lua +++ b/server/main.lua @@ -122,6 +122,31 @@ RegisterNetEvent('qb-admin:server:changeplayerdata', function(Selected, Selected PlayerDataOptions[Selected](Target, Input) end) +RegisterNetEvent('qb-admin:server:SaveCar', function(mods, vehicle, plate) + local Player = exports.qbx_core:GetPlayer(source) + local result = MySQL.Sync.fetchAll('SELECT plate FROM player_vehicles WHERE plate = ?', { plate }) + if result[1] ~= nil then + TriggerClientEvent('ox_lib:notify', source, Lang:t("error.failed_vehicle_owner"), 'error', 3000) + return + end + if not exports.qbx_core:HasPermission(source, Config.Events['savecar']) then NoPerms(source) return end + local playerName = GetPlayerName(source) + local citizenID = Player.PlayerData.citizenid + TriggerEvent('qb-log:server:CreateLog', 'admin', 'Admin menu', 'pink', string.format( + "**%s** (CitizenID: %s | ID: %s) - Saved a car to their garage **%s**", + playerName, citizenID, source, vehicle.model + )) + MySQL.Async.insert('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, state) VALUES (?, ?, ?, ?, ?, ?, ?)', { + Player.PlayerData.license, + citizenID, + vehicle.model, + vehicle.hash, + json.encode(mods), + plate, + 0 + }) + TriggerClientEvent('ox_lib:notify', source, Lang:t("success.success_vehicle_owner"), 'success', 5000) +end) RegisterNetEvent('qb-admin:server:giveallweapons', function(Weapontype, PlayerID) local src = PlayerID or source local Target = exports.qbx_core:GetPlayer(src) @@ -250,4 +275,4 @@ CreateThread(function() sounds[#sounds + 1] = filename:match('(.+)%..+$') end end -end) \ No newline at end of file +end)