Skip to content

Commit

Permalink
show vehicles stored in other garages as guests
Browse files Browse the repository at this point in the history
  • Loading branch information
swkeep committed Nov 8, 2022
1 parent 5699276 commit b56d5ec
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.vscode
/dev-tool
/dev-config.lua
/watch.js
81 changes: 51 additions & 30 deletions client/menu/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

local QBCore = exports['qb-core']:GetCoreObject()
local keep_menu = {}
local Cachedata = nil
local currentVeh = {}

function Open_menu()
Expand Down Expand Up @@ -141,8 +140,13 @@ function keep_menu:categories()
}

for _, category in pairs(categories) do
local header = category.name
if category.name == 'default' then
header = 'Guests'
end

Menu[#Menu + 1] = {
header = category.name,
header = header,
subheader = category.count .. " Vehicles",
icon = category.icon or 'fa-solid fa-car-side',
action = function()
Expand Down Expand Up @@ -264,11 +268,17 @@ function keep_menu:vehicles_inside_category(category)
header = 'Leave',
leave = true
},
{
header = "-------- (List Of Vehicles) --------",
subheader = 'Category: ' .. category.name,
disabled = true
},

}

local subheader = category.name
if subheader == 'default' then
subheader = 'Guests'
end
Menu[#Menu + 1] = {
header = "-------- (List Of Vehicles) --------",
subheader = 'Category: ' .. subheader,
disabled = true
}
for _, vehicle in pairs(vehicles) do
local veh_data = get_vehicle_data(vehicle.model)
Expand Down Expand Up @@ -503,7 +513,7 @@ function keep_menu:take_out_menu(data, vehicle, veh, per, category)
plate = vehicle.plate,
data = data,
vehicle = vehicle,
veh = veh
veh = veh,
}, per)
end
},
Expand Down Expand Up @@ -668,38 +678,49 @@ function keep_menu:take_out_menu(data, vehicle, veh, per, category)
end

function keep_menu:vehicle_parking_log(data, per)
local Menu = {}
local Menu = {
{
header = 'Leave',
leave = true
},
{
header = 'Logs',
icon = 'fa-solid fa-car',
disabled = true,
is_header = true
},
}

TriggerCallback('keep-sharedgarages:server:get_vehicle_log', function(LOGS)
local icons = {
retrive = 'fa-solid fa-arrow-right-arrow-left',
store = 'fa-solid fa-arrow-right-to-bracket',
out = 'fa-solid fa-arrow-right-from-bracket'
}
if type(LOGS) == "table" then
for _, log in pairs(LOGS) do

local header = log.action
local _data = json.decode(log.data)
local sub_header = "Name: " .. _data.charinfo.firstname .. " " .. _data.charinfo.lastname
Menu[#Menu + 1] = {
header = header,
subheader = sub_header,
footer = log.Action_timestamp,
icon = icons[log.action],
disabled = true
}
end
if not (type(LOGS) == "table") then return end

for _, log in pairs(LOGS) do
local header = log.action
local _data = json.decode(log.data)
local sub_header = "Name: " .. _data.charinfo.firstname .. " " .. _data.charinfo.lastname
Menu[#Menu + 1] = {
header = header,
subheader = sub_header,
footer = log.Action_timestamp,
icon = icons[log.action],
disabled = true
}
end

local op = exports['keep-menu']:createMenu(Menu)
local op = exports['keep-menu']:createMenu(Menu)

if not op then
TriggerServerEvent('keep-sharedgarages:server:update_out_vehicles', {
type = 'remove',
plate = data.plate
})
QBCore.Functions.DeleteVehicle(data.veh)
end
if not op then
TriggerServerEvent('keep-sharedgarages:server:update_out_vehicles', {
type = 'remove',
plate = data.plate
})
QBCore.Functions.DeleteVehicle(data.veh)
end
end, { plate = data.plate })
end
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fx_version 'cerulean'
games { 'gta5' }

author "Swkeep#7049"
version '2.0.3'
version '2.0.4'

shared_script {
'config.lua',
Expand Down
89 changes: 85 additions & 4 deletions server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ RegisterNetEvent("keep-sharedgarages:server:update_state", function(plate, prope
MySQL.Async.execute(s, {
1,
properties.currentgarage,
math.floor(properties.VehicleProperties.fuelLevel),
math.floor(properties.VehicleProperties.engineHealth),
math.floor(properties.VehicleProperties.bodyHealth),
math.floor(properties.VehicleProperties.fuelLevel or 0),
math.floor(properties.VehicleProperties.engineHealth or 100.0),
math.floor(properties.VehicleProperties.bodyHealthor or 100.0),
json.encode(properties.metadata),
plate
}, function(result)
Expand Down Expand Up @@ -501,20 +501,54 @@ CreateCallback('keep-sharedgarages:server:GET:player_job_gang', function(source,
end)

CreateCallback('keep-sharedgarages:server:GET:garage_categories', function(source, cb, current_garage)
local function count_guest_vehicles(res)
local q = ''
local qq = 'SELECT COUNT(id_keep_garage_categories) FROM keep_garage WHERE garage = ? AND '
for key, c in ipairs(res) do
local string = 'id_keep_garage_categories != ' .. c.id
if key > 1 then
string = ' AND id_keep_garage_categories != ' .. c.id
end
q = q .. string
end
qq = qq .. q
-- check for default but for guest vehicles
return MySQL.Sync.fetchScalar(qq, { current_garage })
end

MySQL.Async.fetchAll('SELECT * FROM keep_garage_categories WHERE garage = ?', { current_garage }, function(res)
for key, c in pairs(res) do
c.count = MySQL.Sync.fetchScalar('SELECT COUNT(id_keep_garage_categories) FROM keep_garage WHERE id_keep_garage_categories = ?', { c.id })
end

-- check for default category
local default_count = MySQL.Sync.fetchScalar('SELECT COUNT(id_keep_garage_categories) FROM keep_garage WHERE id_keep_garage_categories = ?', { 0 })
local default_index = #res + 1
if default_count > 0 then
res[#res + 1] = {
res[default_index] = {
id = 0,
name = 'default',
count = default_count
}
end

-- guest vehicles are vehicles that doesn't belong to this garage
local guests = count_guest_vehicles(res)

if guests > 0 then
local count = 0
if not res[default_index] then
count = 0 + guests
else
count = res[default_index].count + guests
end
res[default_index] = {
id = 0,
name = 'default',
count = count
}
end

cb(res)
end)
end)
Expand All @@ -534,9 +568,55 @@ CreateCallback('keep-sharedgarages:server:GET:vehicles_on_category', function(so
end)
end

local function get_guest_vehicles(res)
local q = ''
local qq = 'SELECT * FROM keep_garage WHERE garage = ? AND '
for key, c in ipairs(res) do
local string = 'id_keep_garage_categories != ' .. c.id
if key > 1 then
string = ' AND id_keep_garage_categories != ' .. c.id
end
q = q .. string
end
qq = qq .. q
-- check for default but for guest vehicles
return MySQL.Sync.fetchAll(qq, { current_garage })
end

local function send_vehicles_list(category_id)
local tmp = {}
MySQL.Async.fetchAll('SELECT * FROM keep_garage WHERE id_keep_garage_categories = ? AND garage = ?', { category_id, current_garage }, function(vehicles)
if category_id == 0 then
MySQL.Async.fetchAll('SELECT * FROM keep_garage_categories WHERE garage = ?', { current_garage }, function(res)
local guests = get_guest_vehicles(res)

for key, vehicle in pairs(guests) do
if tmp[vehicle.model] == nil then
tmp[vehicle.model] = {}
end
vehicle.mods = json.decode(vehicle.mods)
vehicle.metadata = json.decode(vehicle.metadata)
vehicle.permissions = json.decode(vehicle.permissions)
vehicle.current_player_id = Player.PlayerData.citizenid
tmp[#tmp + 1] = vehicle
end

-- vehicles the are acually on default category
for key, vehicle in pairs(vehicles) do
if tmp[vehicle.model] == nil then
tmp[vehicle.model] = {}
end
vehicle.mods = json.decode(vehicle.mods)
vehicle.metadata = json.decode(vehicle.metadata)
vehicle.permissions = json.decode(vehicle.permissions)
vehicle.current_player_id = Player.PlayerData.citizenid
tmp[#tmp + 1] = vehicle
end
cb(tmp)
end)
return
end

for key, vehicle in pairs(vehicles) do
if tmp[vehicle.model] == nil then
tmp[vehicle.model] = {}
Expand All @@ -547,6 +627,7 @@ CreateCallback('keep-sharedgarages:server:GET:vehicles_on_category', function(so
vehicle.current_player_id = Player.PlayerData.citizenid
tmp[#tmp + 1] = vehicle
end

cb(tmp)
end)
end
Expand Down

0 comments on commit b56d5ec

Please sign in to comment.