358 changes: 214 additions & 144 deletions client/client.lua
Expand Up @@ -21,6 +21,7 @@ local propertyspawn = {}
local lastcat = nil
local deleting = false
local housingcustom = nil
local garage_public = false
meter_cars = {}
Citizen.CreateThread(function()
Wait(1000)
Expand All @@ -31,6 +32,7 @@ Citizen.CreateThread(function()
jobgarages[v.garage].coord = vector3(v.garage_x,v.garage_y,v.garage_z)
jobgarages[v.garage].garageid = v.garage
jobgarages[v.garage].job = v.job
jobgarages[v.garage].garage_type = v.garage_type ~= nil and v.garage_type or 'personal'
end
end
while ESX == nil do
Expand Down Expand Up @@ -477,8 +479,8 @@ AddEventHandler('renzu_garage:ingarage', function(table,garage,garage_id, vehicl
local count = 0
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 2000 do
count = count + 101
while not HasModelLoaded(hash) do
RequestModel(hash)
Citizen.Wait(10)
end
end
Expand Down Expand Up @@ -920,8 +922,8 @@ AddEventHandler('renzu_garage:choose', function(table,garage)
local count = 0
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 2000 do
count = count + 101
while not HasModelLoaded(hash) do
RequestModel(hash)
Citizen.Wait(10)
end
end
Expand Down Expand Up @@ -1180,8 +1182,8 @@ CreateThread(function()
local count = 0
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 2000 do
count = count + 101
while not HasModelLoaded(hash) do
RequestModel(hash)
Citizen.Wait(10)
end
end
Expand Down Expand Up @@ -1221,8 +1223,8 @@ CreateThread(function()
while IsAnyVehicleNearPoint(coord.x,coord.y,coord.z,1.1) do local nearveh = GetClosestVehicle(vector3(coord.x,coord.y,coord.z), 2.000, 0, 70) ReqAndDelete(nearveh) Wait(10) end
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 111 do
count = count + 1
while not HasModelLoaded(hash) do
RequestModel(hash)
Citizen.Wait(1)
end
end
Expand Down Expand Up @@ -1281,23 +1283,25 @@ AddEventHandler('opengarage', function()
local req_dist = v.Store_dist or v.Dist
if dist <= req_dist and not jobgarage and not string.find(v.garage, "impound") or dist <= 7.0 and PlayerData.job ~= nil and PlayerData.job.name == v.job and jobgarage and not string.find(v.garage, "impound") then
garageid = v.garage
Storevehicle(vehiclenow)
Storevehicle(vehiclenow,false,false,v.garage_type == 'public' or false)
break
end
elseif not DoesEntityExist(vehiclenow) then
if dist <= v.Dist and not jobgarage and not string.find(v.garage, "impound") or dist <= 7.0 and PlayerData.job ~= nil and PlayerData.job.name == v.job and jobgarage and not string.find(v.garage, "impound") then
garageid = v.garage
tid = k
TriggerEvent('renzu_notify:Notify', 'info','Garage', "Opening Garage...Please wait..")
TriggerServerEvent("renzu_garage:GetVehiclesTable",garageid)
TriggerServerEvent("renzu_garage:GetVehiclesTable",garageid,v.garage_type == 'public' or false)
fetchdone = false
garage_public = v.garage_type == 'public' or false
while not fetchdone do
Wait(0)
end
type = v.Type
if jobgarage then
garagejob = v.job
end
print(garagejob)
propertygarage = false
OpenGarage(v.garage,v.Type,garagejob or false,v.default_vehicle or {})
break
Expand Down Expand Up @@ -1704,82 +1708,89 @@ AddEventHandler('renzu_garage:receive_vehicles', function(tb, vehdata)
local gstate = GlobalState and GlobalState.VehicleImages
for _,value in pairs(tableVehicles) do
local props = json.decode(value.vehicle)
local vehicleModel = tonumber(props.model)
local label = nil
if label == nil then
label = 'Unknown'
end
if IsModelInCdimage(props.model) then
local vehicleModel = tonumber(props.model)
local label = nil
if label == nil then
label = 'Unknown'
end

local vehname = nil
for _,value in pairs(vehdata) do -- fetch vehicle names from vehicles sql table
if tonumber(props.model) == GetHashKey(value.model) then
vehname = value.name
break
local vehname = nil
for _,value in pairs(vehdata) do -- fetch vehicle names from vehicles sql table
if tonumber(props.model) == GetHashKey(value.model) then
vehname = value.name
break
end
end
end

--local vehname = vehicle_data[GetDisplayNameFromVehicleModel(tonumber(props.model))]
--local vehname = vehicle_data[GetDisplayNameFromVehicleModel(tonumber(props.model))]

if vehname == nil then
vehname = GetLabelText(GetDisplayNameFromVehicleModel(tonumber(props.model)):lower())
end
if props ~= nil and props.engineHealth ~= nil and props.engineHealth < 100 then
props.engineHealth = 200
end
local pmult, tmult, handling, brake = 1000,800,GetPerformanceStats(vehicleModel).handling,GetPerformanceStats(vehicleModel).brakes
if value.type == 'boat' or value.type == 'plane' then
pmult,tmult,handling, brake = 10,8,GetPerformanceStats(vehicleModel).handling * 0.1, GetPerformanceStats(vehicleModel).brakes * 0.1
end
if value.job == '' then
value.job = nil
end
local havejob = false
for k,v in pairs(jobgarages) do
if value.job ~= nil and v.job == value.job then
havejob = true
if vehname == nil then
vehname = GetLabelText(GetDisplayNameFromVehicleModel(tonumber(props.model)):lower())
end
end
if value.job ~= nil and not havejob then -- fix incompatibility with vehicles with job column as a default from sql eg. civ fck!
value.job = nil
end
if value.garage_id ~= nil then -- fix blank job column, seperate the car to other non job garages
for k,v in pairs(jobgarages) do
if v.job ~= nil and value.job ~= nil and v.job == value.job and v.garageid == value.garage_id and #(v.coord - GetEntityCoords(PlayerPedId())) < 20 then
value.job = v.job
if props ~= nil and props.engineHealth ~= nil and props.engineHealth < 100 then
props.engineHealth = 200
end
local pmult, tmult, handling, brake = 1000,800,GetPerformanceStats(vehicleModel).handling,GetPerformanceStats(vehicleModel).brakes
if value.type == 'boat' or value.type == 'plane' then
pmult,tmult,handling, brake = 10,8,GetPerformanceStats(vehicleModel).handling * 0.1, GetPerformanceStats(vehicleModel).brakes * 0.1
end
if value.job == '' then
value.job = nil
end
local havejob = false
for k,v in pairs(jobgarages) do
if value.job ~= nil and v.job == value.job then
havejob = true
end
end
--value.garage_id = jobgarages[value.job].garageid
end
local default_thumb = string.lower(GetDisplayNameFromVehicleModel(tonumber(props.model)))
local img = 'https://cfx-nui-renzu_garage/imgs/uploads/'..default_thumb..'.jpg'
if Config.use_renzu_vehthumb and gstate[tostring(props.model)] then
img = gstate[tostring(props.model)]
if value.job ~= nil and not havejob then -- fix incompatibility with vehicles with job column as a default from sql eg. civ fck!
value.job = nil
end
if value.garage_id ~= nil then -- fix blank job column, seperate the car to other non job garages
for k,v in pairs(jobgarages) do
if v.job ~= nil and value.job ~= nil and v.job == value.job and v.garageid == value.garage_id and #(v.coord - GetEntityCoords(PlayerPedId())) < 20 then
value.job = v.job
end
if v.garage_type and v.garage_type == 'public' and #(v.coord - GetEntityCoords(PlayerPedId())) < 20 then
value.garage_type = 'public'
value.job = v.job
end
end
--value.garage_id = jobgarages[value.job].garageid
end
local default_thumb = string.lower(GetDisplayNameFromVehicleModel(tonumber(props.model)))
local img = 'https://cfx-nui-renzu_garage/imgs/uploads/'..default_thumb..'.jpg'
if Config.use_renzu_vehthumb and gstate[tostring(props.model)] then
img = gstate[tostring(props.model)]
end
local VTable =
{
brand = GetVehicleClassnamemodel(tonumber(props.model)),
name = vehname:upper(),
brake = brake,
handling = handling,
topspeed = math.ceil(GetVehicleModelEstimatedMaxSpeed(vehicleModel)*4.605936),
power = math.ceil(GetVehicleModelAcceleration(vehicleModel)*pmult),
torque = math.ceil(GetVehicleModelAcceleration(vehicleModel)*tmult),
model = string.lower(GetDisplayNameFromVehicleModel(tonumber(props.model))),
model2 = tonumber(props.model),
plate = value.plate,
img = img,
props = value.vehicle,
fuel = props.fuelLevel or 100,
bodyhealth = props.bodyHealth or 1000,
enginehealth = props.engineHealth or 1000,
garage_id = value.garage_id,
impound = value.impound,
stored = value.stored,
identifier = value.owner,
type = value.type,
garage_type = value.garage_type ~= nil and value.garage_type or 'personal',
job = value.job ~= nil,
}
table.insert(OwnedVehicles['garage'], VTable)
end
local VTable =
{
brand = GetVehicleClassnamemodel(tonumber(props.model)),
name = vehname:upper(),
brake = brake,
handling = handling,
topspeed = math.ceil(GetVehicleModelEstimatedMaxSpeed(vehicleModel)*4.605936),
power = math.ceil(GetVehicleModelAcceleration(vehicleModel)*pmult),
torque = math.ceil(GetVehicleModelAcceleration(vehicleModel)*tmult),
model = string.lower(GetDisplayNameFromVehicleModel(tonumber(props.model))),
model2 = tonumber(props.model),
plate = value.plate,
img = img,
props = value.vehicle,
fuel = props.fuelLevel or 100,
bodyhealth = props.bodyHealth or 1000,
enginehealth = props.engineHealth or 1000,
garage_id = value.garage_id,
impound = value.impound,
stored = value.stored,
identifier = value.owner,
type = value.type,
job = value.job ~= nil,
}
table.insert(OwnedVehicles['garage'], VTable)
end
fetchdone = true
end)
Expand Down Expand Up @@ -1941,7 +1952,11 @@ function OpenGarage(garageid,garage_type,jobonly,default)
for k2,v in pairs(v2) do
if Config.UniqueCarperGarage and garageid == v.garage_id and garage_type == v.type and v.garage_id ~= 'private' and propertyspawn.x == nil
or not Config.UniqueCarperGarage and garageid ~= nil and garage_type == v.type and jobonly == false and not v.job and v.garage_id ~= 'private' and propertyspawn.x == nil
-- personal job garage
or not Config.UniqueCarperGarage and garageid ~= nil and garage_type == v.type and jobonly == PlayerData.job.name and garageid == v.garage_id and not string.find(v.garage_id, "impound") and v.garage_id ~= 'private' and propertyspawn.x == nil
-- public job garage
or v.garage_type == 'public' and garageid ~= nil and garage_type == v.type and jobonly == PlayerData.job.name and garageid == v.garage_id and not string.find(v.garage_id, "impound") and v.garage_id ~= 'private' and propertyspawn.x == nil
--
or string.find(garageid, "impound") and string.find(v.garage_id, "impound") and garage_type == v.type and propertyspawn.x == nil
or propertyspawn.x ~= nil and Config.UniqueProperty and garage_type == v.type and jobonly == false and not v.job and v.garage_id == garageid
or propertyspawn.x ~= nil and not Config.UniqueProperty and garage_type == v.type and jobonly == false and not v.job and v.garage_id ~= 'private' then
Expand Down Expand Up @@ -1970,7 +1985,11 @@ function OpenGarage(garageid,garage_type,jobonly,default)
for k2,v in pairs(v2) do
if Config.UniqueCarperGarage and garageid == v.garage_id and garage_type == v.type and v.garage_id ~= 'private' and propertyspawn.x == nil
or not Config.UniqueCarperGarage and garageid ~= nil and garage_type == v.type and jobonly == false and not v.job and v.garage_id ~= 'private' and propertyspawn.x == nil
-- personal job garage
or not Config.UniqueCarperGarage and garageid ~= nil and garage_type == v.type and jobonly == PlayerData.job.name and garageid == v.garage_id and not string.find(v.garage_id, "impound") and v.garage_id ~= 'private' and propertyspawn.x == nil
-- public job garage
or v.garage_type == 'public' and not Config.UniqueCarperGarage and garageid ~= nil and garage_type == v.type and jobonly == PlayerData.job.name and garageid == v.garage_id and not string.find(v.garage_id, "impound") and v.garage_id ~= 'private' and propertyspawn.x == nil
--
or string.find(garageid, "impound") and string.find(v.garage_id, "impound") and garage_type == v.type and propertyspawn.x == nil
or propertyspawn.x ~= nil and Config.UniqueProperty and garage_type == v.type and jobonly == false and not v.job and v.garage_id == garageid
or propertyspawn.x ~= nil and not Config.UniqueProperty and garage_type == v.type and jobonly == false and not v.job and v.garage_id ~= 'private' then
Expand Down Expand Up @@ -2288,8 +2307,8 @@ function CreateGarageShell()
local count = 0
local model = GetHashKey('garage')
RequestModel(model)
while not HasModelLoaded(model) and count < 2000 do
count = count + 101
while not HasModelLoaded(model) do
RequestModel(model)
Citizen.Wait(10)
end
shell = CreateObject(model, garage_coords.x, garage_coords.y, garage_coords.z, false, false, false)
Expand Down Expand Up @@ -2482,8 +2501,9 @@ function GotoGarage(garageid, property, propertycoord, job)
local model = GetHashKey('garage')
local count = 0
RequestModel(model)
while not HasModelLoaded(model) and count < 2000 do
count = count + 101
while not HasModelLoaded(model) do
RequestModel(hash)
RequestModel(model)
Citizen.Wait(10)
end
shell = CreateObject(model, garage_coords.x, garage_coords.y-7.0, garage_coords.z, false, false, false)
Expand Down Expand Up @@ -2525,8 +2545,7 @@ function GotoGarage(garageid, property, propertycoord, job)
local count = 0
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 2000 do
count = count + 101
while not HasModelLoaded(hash) do
Citizen.Wait(10)
end
end
Expand Down Expand Up @@ -2588,6 +2607,7 @@ function GotoGarage(garageid, property, propertycoord, job)
end
Citizen.Wait(1000)
end
garage_public = false
end


Expand Down Expand Up @@ -2687,12 +2707,9 @@ function GarageVehicle()
local count = 0
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 10000 do
count = count + 10
while not HasModelLoaded(hash) do
RequestModel(hash)
Citizen.Wait(1)
if count > 9999 then
return
end
end
end
local indexnew = tonumber('1'..i2..'')
Expand Down Expand Up @@ -2800,12 +2817,9 @@ function GarageVehicle()
local count = 0
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 10000 do
count = count + 10
while not HasModelLoaded(hash) do
RequestModel(hash)
Citizen.Wait(1)
if count > 9999 then
return
end
end
end
local indexnew = tonumber('2'..i2..'')
Expand Down Expand Up @@ -2863,8 +2877,7 @@ AddEventHandler('renzu_garage:return', function(v,vehicle,property,actualShop,vp
local hash = tonumber(vp.model)
local count = 0
RequestModel(hash)
while not HasModelLoaded(hash) and count < 500 do
count = count + 1
while not HasModelLoaded(hash) do
Citizen.Wait(10)
RequestModel(hash)
end
Expand All @@ -2880,8 +2893,28 @@ AddEventHandler('renzu_garage:return', function(v,vehicle,property,actualShop,vp
end
TaskWarpPedIntoVehicle(PlayerPedId(), vehicle, -1)
veh = vehicle
ESX.TriggerServerCallback("renzu_garage:changestate",function(ret)
end,vp.plate, 0, gid, vp.model, vp)
ESX.TriggerServerCallback("renzu_garage:changestate",function(ret,garage_public)
if ret and garage_public then
local ent = Entity(veh).state
while ent.share == nil do Wait(100) end
ent.haskeys = false
ent.hotwired = false
ent.unlock = true
local share = ent.share or {}
local add = true
for k,v in pairs(share) do
if k == v.PlayerData.identifier then
add = false
end
end
if add then
share[PlayerData.identifier] = true
end
ent.share = share
ent:set('share', share, true)
TriggerServerEvent('statebugupdate','share',share, VehToNet(veh))
end
end,vp.plate, 0, gid, vp.model, vp, false, garage_public)
spawnedgarage = {}
TriggerEvent('renzu_popui:closeui')
if property then
Expand Down Expand Up @@ -2950,12 +2983,9 @@ AddEventHandler('renzu_garage:ingaragepublic', function(coords, distance, vehicl
local count = 0
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 1111 do
count = count + 10
while not HasModelLoaded(hash) do
RequestModel(hash)
Citizen.Wait(10)
if count > 9999 then
return
end
end
end
v = CreateVehicle(model, tempcoord[tid].spawn_x,tempcoord[tid].spawn_y,tempcoord[tid].spawn_z, tempcoord[tid].heading, 1, 1)
Expand All @@ -2967,8 +2997,29 @@ AddEventHandler('renzu_garage:ingaragepublic', function(coords, distance, vehicl
TaskWarpPedIntoVehicle(PlayerPedId(), v, -1)
veh = v
DoScreenFadeIn(333)
ESX.TriggerServerCallback("renzu_garage:changestate",function(ret)
end,vp.plate, 0, garageid, vp.model, vp)
ESX.TriggerServerCallback("renzu_garage:changestate",function(ret,garage_public)
if ret and garage_public then
local ent = Entity(veh).state
while ent.share == nil do Wait(100) end
ent.haskeys = false
ent.hotwired = false
ent.unlock = true
local share = ent.share or {}
local add = true
for k,v in pairs(share) do
if k == v.PlayerData.identifier then
add = false
end
end
if add then
share[PlayerData.identifier] = true
end
ent.share = share
ent:set('share', share, true)
TriggerServerEvent('statebugupdate','share',share, VehToNet(veh))
end
end,vp.plate, 0, garageid, vp.model, vp,false,garage_public)
garage_public = false
if sharedvehicle then
local ent = Entity(v).state
while ent.share == nil do Wait(100) end
Expand Down Expand Up @@ -3177,7 +3228,7 @@ AddEventHandler('renzu_garage:store', function(i)
end,vehicleProps.plate, 1, garageid, vehicleProps.model, vehicleProps)
end)

function Storevehicle(vehicle,impound, impound_data)
function Storevehicle(vehicle,impound, impound_data, public)
local vehicleProps = GetVehicleProperties(vehicle)
if garageid == nil then
garageid = 'A'
Expand All @@ -3193,7 +3244,7 @@ function Storevehicle(vehicle,impound, impound_data)
if ret or ent.share[PlayerData.identifier] then
DeleteEntity(vehicle)
end
end,vehicleProps.plate, 1, garageid, vehicleProps.model, vehicleProps, impound_data or {})
end,vehicleProps.plate, 1, garageid, vehicleProps.model, vehicleProps, impound_data or {}, public)
neargarage = false
end

Expand Down Expand Up @@ -3241,12 +3292,8 @@ function SpawnVehicleLocal(model, props)
FreezeEntityPosition(PlayerPedId(),true)
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 1111 do
count = count + 10
while not HasModelLoaded(hash) do
Citizen.Wait(10)
if count > 9999 then
return
end
end
end
LastVehicleFromGarage = CreateVehicle(hash, actualShop.garage_x,actualShop.garage_y,zaxis + 20, 42.0, 0, 1)
Expand All @@ -3270,12 +3317,8 @@ function SpawnVehicleLocal(model, props)
FreezeEntityPosition(PlayerPedId(),true)
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 1111 do
count = count + 10
while not HasModelLoaded(hash) do
Citizen.Wait(10)
if count > 9999 then
return
end
end
end
LastVehicleFromGarage = CreateVehicle(hash, actualShop.garage_x,actualShop.garage_y,zaxis + 20, 42.0, 0, 1)
Expand Down Expand Up @@ -3310,13 +3353,9 @@ function SpawnChopperLocal(model, props)
local count = 0
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 1111 do
while not HasModelLoaded(hash) do
RequestModel(hash)
count = count + 10
Citizen.Wait(10)
if count > 9999 then
return
end
end
end
LastVehicleFromGarage = CreateVehicle(hash, actualShop.x,actualShop.y,zaxis+0.3, 42.0, 0, 1)
Expand Down Expand Up @@ -3490,12 +3529,9 @@ RegisterNUICallback(
local count = 0
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 1111 do
while not HasModelLoaded(hash) do
count = count + 10
Citizen.Wait(1)
if count > 9999 then
return
end
end
end
local vehicle = CreateVehicle(tonumber(props.model), actualShop.spawn_x,actualShop.spawn_y,actualShop.spawn_z, actualShop.heading, 1, 1)
Expand All @@ -3518,8 +3554,29 @@ RegisterNUICallback(
while veh == nil do
Citizen.Wait(10)
end
ESX.TriggerServerCallback("renzu_garage:changestate",function(ret)
end,props.plate, 0, garageid, props.model, props)
ESX.TriggerServerCallback("renzu_garage:changestate",function(ret, garage_public)
if ret and garage_public then
local ent = Entity(veh).state
while ent.share == nil do Wait(100) end
ent.haskeys = false
ent.hotwired = false
ent.unlock = true
local share = ent.share or {}
local add = true
for k,v in pairs(share) do
if k == v.PlayerData.identifier then
add = false
end
end
if add then
share[PlayerData.identifier] = true
end
ent.share = share
ent:set('share', share, true)
TriggerServerEvent('statebugupdate','share',share, VehToNet(veh))
print("SHARED VEHICLE")
end
end,props.plate, 0, garageid, props.model, props,false,garage_public)
LastVehicleFromGarage = nil
TaskWarpPedIntoVehicle(PlayerPedId(), veh, -1)
CloseNui()
Expand Down Expand Up @@ -3612,12 +3669,8 @@ RegisterNUICallback(
local count = 0
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 1111 do
count = count + 10
while not HasModelLoaded(hash) do
Citizen.Wait(1)
if count > 9999 then
return
end
end
end
v = CreateVehicle(hash, actualShop.x,actualShop.y,actualShop.z, 256.0, 1, 1)
Expand Down Expand Up @@ -3690,12 +3743,9 @@ RegisterNUICallback(
local count = 0
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 1111 do
count = count + 10
while not HasModelLoaded(hash) do
RequestModel(hash)
Citizen.Wait(1)
if count > 9999 then
return
end
end
end
vehicle = CreateVehicle(tonumber(data.modelcar), actualShop.spawn_x,actualShop.spawn_y,actualShop.spawn_z, actualShop.heading, 1, 1)
Expand All @@ -3715,8 +3765,28 @@ RegisterNUICallback(
while veh == nil do
Citizen.Wait(1)
end
ESX.TriggerServerCallback("renzu_garage:changestate",function(ret)
end,props.plate, 0, garageid, props.model, props)
ESX.TriggerServerCallback("renzu_garage:changestate",function(ret,garage_public)
if ret and garage_public then
local ent = Entity(veh).state
while ent.share == nil do Wait(100) end
ent.haskeys = false
ent.hotwired = false
ent.unlock = true
local share = ent.share or {}
local add = true
for k,v in pairs(share) do
if k == v.PlayerData.identifier then
add = false
end
end
if add then
share[PlayerData.identifier] = true
end
ent.share = share
ent:set('share', share, true)
TriggerServerEvent('statebugupdate','share',share, VehToNet(veh))
end
end,props.plate, 0, garageid, props.model, props,false,garage_public)
LastVehicleFromGarage = nil
Wait(111)
CloseNui()
Expand Down Expand Up @@ -3818,6 +3888,7 @@ function CloseNui()
drawtext = false
indist = false
propertyspawn = {}
garage_public = false
end

function ReqAndDelete(object, detach)
Expand Down Expand Up @@ -4076,8 +4147,7 @@ CreateThread(function()
local count = 0
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 2000 do
count = count + 101
while not HasModelLoaded(hash) do
Citizen.Wait(10)
end
end
Expand Down Expand Up @@ -4125,8 +4195,8 @@ CreateThread(function()
while IsAnyVehicleNearPoint(parkcoord.x,parkcoord.y,parkcoord.z,1.1) do local nearveh = GetClosestVehicle(vector3(parkcoord.x,parkcoord.y,parkcoord.z), 2.000, 0, 70) ReqAndDelete(nearveh) Wait(10) end
if not HasModelLoaded(hash) then
RequestModel(hash)
while not HasModelLoaded(hash) and count < 111 do
count = count + 1
while not HasModelLoaded(hash) do
RequestModel(hash)
Citizen.Wait(1)
end
end
Expand Down
15 changes: 15 additions & 0 deletions conf/public_garage.lua
Expand Up @@ -176,6 +176,21 @@ garagecoord = {
[3] = {model = 'police3', name = 'Police 3', type = 'car', grade = 1, plateprefix = 'LSPD'}, -- minimum grade
},
},
{
garage = "Police Public Garage", -- public garage job
garage_type = 'public', -- public = every police job can acccess the garage vehicle list
job = "police",
Type = "car",
Dist = 10,
Blip = {color = 38, sprite = 662, scale = 0.6},
garage_x = 450.5574645996, -- 450.55746459961,-1025.3254394531,28.56488609314,52.594207763672
garage_y = -1025.3254394531,
garage_z = 28.56488609314,
spawn_x = 443.62295532227, -- 443.62295532227,-1019.6309814453,27.948703765869,91.976776123047
spawn_y = -1019.6309814453,
spawn_z = 27.948703765869,
heading = 91.976776123047,
},
--JOB GARAGE
{
garage = "Sheriff Garage", --PALETO
Expand Down
50 changes: 37 additions & 13 deletions server/server.lua
Expand Up @@ -242,13 +242,13 @@ function MysqlGarage(plugin,type,query,var)
end

RegisterServerEvent('renzu_garage:GetVehiclesTable')
AddEventHandler('renzu_garage:GetVehiclesTable', function(garageid)
AddEventHandler('renzu_garage:GetVehiclesTable', function(garageid,public)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local ply = Player(src).state
local identifier = ply.garagekey or xPlayer.identifier
local sharegarage = false
if ply.garagekey and garageid and sharedgarage[xPlayer.identifier] and sharedgarage[xPlayer.identifier][ply.garagekey] then
if not public and ply.garagekey and garageid and sharedgarage[xPlayer.identifier] and sharedgarage[xPlayer.identifier][ply.garagekey] then
for k,v in pairs(sharedgarage[xPlayer.identifier][ply.garagekey]) do
if garageid == v then
sharegarage = v
Expand All @@ -260,12 +260,15 @@ AddEventHandler('renzu_garage:GetVehiclesTable', function(garageid)
end
end
--local Owned_Vehicle = MySQL.Sync.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner', {['@owner'] = xPlayer.identifier})
if sharegarage then
if not public and sharegarage then
local Owned_Vehicle = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM owned_vehicles WHERE owner = @owner AND garage_id = @garage_id', {['@owner'] = identifier, ['@garage_id'] = sharegarage})
TriggerClientEvent("renzu_garage:receive_vehicles", src , Owned_Vehicle or {},vehicles or {})
else
elseif not public then
local Owned_Vehicle = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM owned_vehicles WHERE owner = @owner', {['@owner'] = identifier})
TriggerClientEvent("renzu_garage:receive_vehicles", src , Owned_Vehicle or {},vehicles or {})
elseif public then
local Owned_Vehicle = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM owned_vehicles WHERE garage_id = @garage_id', {['@garage_id'] = garageid})
TriggerClientEvent("renzu_garage:receive_vehicles", src , Owned_Vehicle or {},vehicles or {})
end
end)

Expand All @@ -283,6 +286,14 @@ AddEventHandler('renzu_garage:GetVehiclesTableImpound', function()
TriggerClientEvent("renzu_garage:receive_vehicles", src , Impounds,vehicles)
end)

ESX.RegisterServerCallback('renzu_garage:getjobgarages',function(source, cb, job)
local garage = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM jobgarages WHERE `job` = @job', {['@job'] = job})
if garage and garage[1] then
cb(garage[1])
end
cb(false)
end)

ESX.RegisterServerCallback('renzu_garage:getowner',function(source, cb, identifier, plate, garage)
local owner = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM users WHERE identifier = @identifier', {
['@identifier'] = identifier
Expand Down Expand Up @@ -1085,7 +1096,7 @@ AddEventHandler('renzu_garage:unpark', function(plate,state,model)
end
end)

ESX.RegisterServerCallback('renzu_garage:changestate', function (source, cb, plate,state,garage_id,model,props,impound_cdata)
ESX.RegisterServerCallback('renzu_garage:changestate', function (source, cb, plate,state,garage_id,model,props,impound_cdata, public)
if not Config.PlateSpace then
plate = string.gsub(tostring(plate), '^%s*(.-)%s*$', '%1'):upper()
else
Expand All @@ -1096,6 +1107,17 @@ ESX.RegisterServerCallback('renzu_garage:changestate', function (source, cb, pla
local xPlayer = ESX.GetPlayerFromId(source)
local ply = Player(source).state
local identifier = ply.garagekey or globalkeys[plate] and globalkeys[plate][xPlayer.identifier] and globalkeys[plate][xPlayer.identifier] or xPlayer.identifier
if public then
local r = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM owned_vehicles WHERE TRIM(UPPER(plate)) = @plate LIMIT 1', {
['@plate'] = plate
})
if r and r[1] then
identifier = r[1].owner
else
TriggerClientEvent('renzu_notify:Notify', source, 'info','Garage', 'Vehicle is not owned')
cb(false,public)
end
end
if xPlayer then
local result = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM owned_vehicles WHERE owner = @owner and TRIM(UPPER(plate)) = @plate LIMIT 1', {
['@owner'] = identifier,
Expand All @@ -1116,14 +1138,16 @@ ESX.RegisterServerCallback('renzu_garage:changestate', function (source, cb, pla
if result[1].vehicle ~= nil then
local veh = json.decode(result[1].vehicle)
if veh.model == model then
local result = MysqlGarage(Config.Mysql,'execute','UPDATE owned_vehicles SET `stored` = @stored, garage_id = @garage_id, vehicle = @vehicle, isparked = @isparked WHERE TRIM(UPPER(plate)) = @plate and owner = @owner', {
['vehicle'] = json.encode(props),
local var = {
['@vehicle'] = json.encode(props),
['@garage_id'] = garage_id,
['@plate'] = plate:upper(),
['@owner'] = identifier,
['@stored'] = state,
['@isparked'] = 0
})
['@isparked'] = 0,
['@job'] = state == 1 and public and xPlayer.job.name or state == 1 and result[1].job ~= nil and result[1].job or 'civ',
}
local result = MysqlGarage(Config.Mysql,'execute','UPDATE owned_vehicles SET `stored` = @stored, garage_id = @garage_id, vehicle = @vehicle, isparked = @isparked, `job` = @job WHERE TRIM(UPPER(plate)) = @plate and owner = @owner', var)
if updatepark then
Wait(300)
parkedvehicles = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM owned_vehicles WHERE isparked = 1', {}) or {}
Expand All @@ -1142,10 +1166,10 @@ ESX.RegisterServerCallback('renzu_garage:changestate', function (source, cb, pla
else
TriggerClientEvent('renzu_notify:Notify', source, 'success','Garage', 'You Successfully Take out the vehicle')
end
cb(true)
cb(true,public)
else
print('exploiting')
cb(false)
cb(false,public)
end
end
elseif JobImpounder[xPlayer.job.name] ~= nil and string.find(garage_id, "impound") or state ~= 1 and string.find(garage_id, "impound") and Impoundforall and JobImpounder[xPlayer.job.name] == nil then
Expand Down Expand Up @@ -1225,9 +1249,9 @@ ESX.RegisterServerCallback('renzu_garage:changestate', function (source, cb, pla
else
TriggerClientEvent('renzu_notify:Notify', source, 'success','Garage', 'You Release the Vehicle')
end
cb(true)
cb(true,public)
else
cb(false)
cb(false,public)
print('exploiting')
end
else
Expand Down