Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
feat: Job garages
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWasTakenn committed Jan 7, 2022
1 parent eefead0 commit e2956a4
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 52 deletions.
44 changes: 21 additions & 23 deletions client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ exports['qtarget']:Vehicle({
})

Citizen.CreateThread(function()
local garagePeds = {Config.DefaultGaragePed}
for k, v in pairs(Config.Garages) do

GarageBlips(vector3(v.pedCoords.x, v.pedCoords.y, v.pedCoords.z), v.type, v.label)
Expand All @@ -149,7 +148,24 @@ Citizen.CreateThread(function()
garages[k].type = v.type
garages[k].label = v.label

table.insert(garagePeds, v.ped)
exports['qtarget']:AddTargetModel({v.ped or Config.DefaultGaragePed}, {
options = {
{
event = "luke_garages:GetOwnedVehicles",
icon = "fas fa-warehouse",
label = Locale('take_out_vehicle'),
job = v.job or nil,
canInteract = function(entity)
hasChecked = false
if IsInsideZone('garage', entity) and not hasChecked then
hasChecked = true
return true
end
end
},
},
distance = 2.5,
})

garages[k]:onPlayerInOut(function(isPointInside, point)
local model = v.ped or Config.DefaultGaragePed
Expand All @@ -174,24 +190,6 @@ Citizen.CreateThread(function()
end
end)
end

exports['qtarget']:AddTargetModel(garagePeds, {
options = {
{
event = "luke_garages:GetOwnedVehicles",
icon = "fas fa-warehouse",
label = Locale('take_out_vehicle'),
canInteract = function(entity)
hasChecked = false
if IsInsideZone('garage', entity) and not hasChecked then
hasChecked = true
return true
end
end
},
},
distance = 2.5,
})
end)

Citizen.CreateThread(function()
Expand Down Expand Up @@ -405,7 +403,7 @@ AddEventHandler('luke_garages:GetOwnedVehicles', function()
}
})
end
end, currentGarage.type)
end, currentGarage.type, currentGarage.job)
end)

RegisterNetEvent('luke_garages:ImpoundVehicleMenu')
Expand Down Expand Up @@ -520,7 +518,7 @@ AddEventHandler('luke_garages:StoreVehicle', function(target)

ESX.TriggerServerCallback('luke_garages:CheckOwnership', function(doesOwn)
if doesOwn then

if type(doesOwn) == 'table' then return ESX.ShowNotification("You can't store your job vehicle here") end
ESX.Game.DeleteVehicle(vehicle)

TriggerServerEvent('luke_garages:ChangeStored', vehPlate, true, currentGarage.zone.name)
Expand All @@ -529,6 +527,6 @@ AddEventHandler('luke_garages:StoreVehicle', function(target)
else
ESX.ShowNotification(Locale('no_ownership'))
end
end, vehPlate, vehProps.model)
end, vehPlate, vehProps.model, currentGarage.job)

end)
50 changes: 41 additions & 9 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,37 @@ Config.Impounds = {
}

Config.Garages = {
{
label = 'MRPD Police Garage',
type = 'car',
job = 'police',
ped = `s_m_y_cop_01`,
pedCoords = {x = 450.6633, y = -1027.3324, z = 27.5732, h = 5.1321},
zone = {name = 'mrpd', x = 439.36, y= -1021.04, z = 28.83, l = 20, w = 40, h = 0, minZ = 27.03, maxZ = 31.03},
spawns = {
{x = 446.4181, y = -1026.2117, z = 28.2490, h = 357.9764},
{x = 442.5637, y = -1025.5530, z = 28.2984, h = 1.7611},
{x = 438.6664, y = -1027.0088, z = 28.3936, h = 3.1104},
{x = 434.8707, y = -1026.6675, z = 28.4554, h = 3.9030},
{x = 431.6170, y = -1026.7904, z = 28.5088, h = 0.9789},
{x = 427.3045, y = -1027.6506, z = 28.5950, h = 5.8251}
}
},
{
label = 'Pillbox Ambulance Garage',
type = 'car',
job = 'ambulance',
ped = `s_m_m_doctor_01`,
pedCoords = {x = 319.3737, y = -559.4569, z = 27.7438, h = 21.0252},
zone = {name = 'pillbox', x = 325.59, y = -549.27, z = 28.74, l = 25, w = 25, h = 0, minZ = 27.74, maxZ = 30.74},
spawns = {
{x = 321.0445, y = -542.4713, z = 28.5142, h = 180.9354},
{x = 323.8813, y = -542.8687, z = 28.5135, h = 181.6986},
{x = 326.6019, y = -542.6691, z = 28.5133, h = 179.8377},
{x = 329.3755, y = -542.5102, z = 28.5137, h = 179.7974},
{x = 332.2085, y = -542.5237, z = 28.5125, h = 181.5656}
}
},
{
label = 'Legion Garage',
type = 'car', -- car, boat or aircraft
Expand All @@ -108,10 +139,10 @@ Config.Garages = {
{x = 206.25, y = -801.21, z = 31.00, h = 250.47},
{x = 208.72, y = -796.45, z = 30.95, h = 246.74},
{x = 210.89, y = -791.42, z = 30.90, h = 248.02},
{x = 216.12, y = -801.68, z = 30.80, h = 68.72},
{x = 218.21, y = -796.79, z = 30.77, h = 68.80},
{x = 219.76, y = -791.47, z = 30.76, h = 69.89},
{x = 221.37, y = -786.53, z = 30.78, h = 70.72},
{x = 216.12, y = -801.68, z = 30.80, h = 68.72},
{x = 218.21, y = -796.79, z = 30.77, h = 68.80},
{x = 219.76, y = -791.47, z = 30.76, h = 69.89},
{x = 221.37, y = -786.53, z = 30.78, h = 70.72},
{x = 212.52, y = -783.46, z = 30.89, h = 248.63},
}
},
Expand All @@ -121,7 +152,7 @@ Config.Garages = {
pedCoords = {x = -1651.83, y = 63.90, z = 61.86, h = 338.03},
zone = {name = 'americano', x = -1682.74, y = 60.93, z = 63.5, l = 59.6, w = 60.6, h = 329, minZ = 61.15, maxZ = 68.35},
spawns = {
{x = -1660.57, y = 75.52, z = 63.20, h = 170.90},
{x = -1660.57, y = 75.52, z = 63.20, h = 170.90},
{x = -1666.24, y = 79.84, z = 63.45, h = 171.92},
{x = -1671.97, y = 84.59, z = 63.83, h = 169.94},
{x = -1662.57, y = 57.99, z = 62.90, h = 293.91},
Expand All @@ -135,7 +166,7 @@ Config.Garages = {
pedCoords = {x = 587.23, y = 2723.50, z = 41.13, h = 7.85},
zone = {name = 'route68', x = 573.19, y = 2727.17, z = 42.06, l = 22.4, w = 51.2, h = 4, minZ = 41.08, maxZ = 45.08},
Spawns = {
{x = 584.51, y = 2721.56, z = 41.88, h = 3.59},
{x = 584.51, y = 2721.56, z = 41.88, h = 3.59},
{x = 581.14, y = 2721.32, z = 41.88, h = 3.99},
{x = 578.15, y = 2720.59, z = 41.88, h = 4.65},
{x = 574.86, y = 2721.09, z = 41.88, h = 4.85},
Expand Down Expand Up @@ -166,7 +197,7 @@ Config.Garages = {
pedCoords = {x = -3428.27, y = 967.34, z = 7.35, h = 269.47},
zone = {name = 'pier', x = -3426.48, y = 968.89, z = 8.35, l = 31.2, w = 39.2, h = 0, minZ = nil, maxZ = nil},
spawns = {
{x = -3444.37, y = 952.64, z = 1.02, h = 98.70},
{x = -3444.37, y = 952.64, z = 1.02, h = 98.70},
{x = -3441.02, y = 965.30, z = 0.17, h = 87.18},
}
},
Expand All @@ -178,15 +209,16 @@ Config.Garages = {
spawns = {
{x = -958.57, y = -2987.20, z = 13.95, h = 58.19},
{x = -971.89, y = -3008.83, z = 13.95, h = 59.47},
{x = -984.30, y = -3025.04, z = 13.95, h = 58.52},
{x = -984.30, y = -3025.04, z = 13.95, h = 58.52},
}
},
--[[
TEMPLATE:
{
label = '', -- name that will be displayed in menus
type = 'car', -- can be 'car', 'boat' or 'aircraft',
ped = `ped_model_name` -- Define the model model you want to use for the garage (Optional)
job = 'jobName', -- Set garage to be only accessed and stored into by a job (Optional)
ped = `ped_model_name`, -- Define the model model you want to use for the garage (Optional)
pedCoords = {x = X, y = X, z = X, h = X}, -- Ped MUST be inside the create zone
zone = {name = 'somename', x = X, y = X, z = X, l = X, w = X, h = X, minZ = X, maxZ = x}, -- l is length of the box zone, w is width, h is heading, take all walues from generated zone from /pzcreate
spawns = { -- You can have as many as you'd like
Expand Down
62 changes: 42 additions & 20 deletions server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,45 @@ if Config.RestoreVehicles then
end)
end

ESX.RegisterServerCallback('luke_garages:GetVehicles', function(source, callback, type)
ESX.RegisterServerCallback('luke_garages:GetVehicles', function(source, callback, type, job)
local xPlayer = ESX.GetPlayerFromId(source)
local identifier = xPlayer.getIdentifier()
local vehicles = {}

MySQL.Async.fetchAll('SELECT * FROM `owned_vehicles` WHERE `owner` = @identifier AND `type` = @type', {
['@identifier'] = identifier,
['@type'] = type
}, function(result)
if result[1] ~= nil then
for k, v in pairs(result) do
local veh = json.decode(v.vehicle)
local health = json.decode(v.health)
table.insert(vehicles, {plate = v.plate, vehicle = veh, stored = v.stored, health = health, garage = v.garage})
if not job then
MySQL.Async.fetchAll("SELECT * FROM `owned_vehicles` WHERE `owner` = @identifier AND `type` = @type AND `job` IS NULL OR job = 'civ'", {
['@identifier'] = identifier,
['@type'] = type
}, function(result)
if result[1] ~= nil then
for k, v in pairs(result) do
local veh = json.decode(v.vehicle)
local health = json.decode(v.health)
table.insert(vehicles, {plate = v.plate, vehicle = veh, stored = v.stored, health = health, garage = v.garage})
end
callback(vehicles)
else
callback(nil)
end
callback(vehicles)
else
callback(nil)
end
end)
end)
else
MySQL.Async.fetchAll('SELECT * FROM `owned_vehicles` WHERE `owner` = @identifier AND `type` = @type AND `job` = @job', {
['@identifier'] = identifier,
['@type'] = type,
['@job'] = job
}, function(result)
if result[1] ~= nil then
for k, v in pairs(result) do
local veh = json.decode(v.vehicle)
local health = json.decode(v.health)
table.insert(vehicles, {plate = v.plate, vehicle = veh, stored = v.stored, health = health, garage = v.garage})
end
callback(vehicles)
else
callback(nil)
end
end)
end
end)

ESX.RegisterServerCallback('luke_garages:GetImpound', function(source, callback, type)
Expand Down Expand Up @@ -62,19 +81,22 @@ ESX.RegisterServerCallback('luke_garages:GetImpound', function(source, callback,
end)
end)

ESX.RegisterServerCallback('luke_garages:CheckOwnership', function(source, callback, plate, model)
ESX.RegisterServerCallback('luke_garages:CheckOwnership', function(source, callback, plate, model, job)
local xPlayer = ESX.GetPlayerFromId(source)
local identifier = xPlayer.getIdentifier()

local plate = ESX.Math.Trim(plate)

MySQL.Async.fetchScalar('SELECT `vehicle` FROM `owned_vehicles` WHERE `owner` = @owner AND `plate` = @plate', {
MySQL.Async.fetchAll('SELECT `vehicle`, `job` FROM `owned_vehicles` WHERE `owner` = @owner AND `plate` = @plate', {
['@owner'] = identifier,
['@plate'] = plate
}, function(result)
if result then
result = json.decode(result)
if result.plate == plate and result.model == model then
if result[1] then
local vehicle = json.decode(result[1].vehicle)
local vehicleJob = result[1].job
if vehicle.plate == plate and vehicle.model == model then
if not job and vehicleJob then return callback({true, false})
else return callback(true) end
callback(true)
else
-- Player tried to cheat
Expand Down

0 comments on commit e2956a4

Please sign in to comment.