Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(client/server): default_vehicles
  • Loading branch information
renzuzu committed Aug 10, 2021
1 parent 64e1248 commit 62ee43c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
40 changes: 38 additions & 2 deletions renzu_garage/client/client.lua
Expand Up @@ -378,7 +378,7 @@ AddEventHandler('opengarage', function()
if jobgarage then
garagejob = v.job
end
OpenGarage(v.garage,v.Type,garagejob or false)
OpenGarage(v.garage,v.Type,garagejob or false,v.default_vehicle or {})
break
end
end
Expand Down Expand Up @@ -809,7 +809,42 @@ AddEventHandler('renzu_garage:getchopper', function(job, available)
fetchdone = true
end)

function OpenGarage(id,garage_type,jobonly)
function CreateDefault(default,jobonly,garage_type,id)
for k,v in pairs(default) do
if v.grade <= PlayerData.job.grade then
local vehicleModel = GetHashKey(v.model)
local pmult, tmult, handling, brake = 1000,800,GetPerformanceStats(vehicleModel).handling,GetPerformanceStats(vehicleModel).brakes
if v.type == 'boat' or v.type == 'plane' then
pmult,tmult,handling, brake = 10,8,GetPerformanceStats(vehicleModel).handling * 0.1, GetPerformanceStats(vehicleModel).brakes * 0.1
end
local VTable = {
brand = GetVehicleClassnamemodel(tonumber(vehicleModel)),
name = v.name: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 = v.model,
model2 = tonumber(vehicleModel),
plate = Config.DefaultPlate,
props = json.encode({model = vehicleModel, plate = Config.DefaultPlate}),
fuel = 100,
bodyhealth = 1000,
enginehealth = 1000,
garage_id = id,
impound = 0,
stored = 1,
identifier = jobonly,
type = garage_type,
job = jobonly,
}
table.insert(OwnedVehicles['garage'], VTable)
end
end
end

function OpenGarage(id,garage_type,jobonly,default)
inGarage = true
local ped = PlayerPedId()
if not Config.Quickpick and garage_type == 'car' then
Expand All @@ -821,6 +856,7 @@ function OpenGarage(id,garage_type,jobonly)
local vehtable = {}
vehtable[id] = {}
local cars = 0
CreateDefault(default,jobonly,garage_type,id)
for k,v2 in pairs(OwnedVehicles) do
for k2,v in pairs(v2) do
if Config.UniqueCarperGarage and id == v.garage_id and garage_type == v.type or not Config.UniqueCarperGarage and id ~= nil and garage_type == v.type and jobonly == false and not v.job or not Config.UniqueCarperGarage and id ~= nil and garage_type == v.type and jobonly == PlayerData.job.name and id == v.garage_id and v.garage_id ~= 'impound' or id == 'impound' and v.garage_id == 'impound' and garage_type == v.type then
Expand Down
8 changes: 7 additions & 1 deletion renzu_garage/config.lua
Expand Up @@ -12,6 +12,7 @@ Config.Realistic_Parking = true
Config.ParkButton = 38 -- E
Config.EnableReturnVehicle = true -- enable / disable return vehicle feature
Config.ReturnPayment = 1000
Config.DefaultPlate = 'ROLEPLAY' -- default plate being used to default_vehicles args
garagecoord = {
{
garage = "A", --LEGION
Expand Down Expand Up @@ -183,7 +184,12 @@ garagecoord = {
spawn_x = 432.20071411133,
spawn_y = -1015.4301757813,
spawn_z = 28.840564727783,
heading = 85.93824005127
heading = 85.93824005127,
default_vehicle = { -- the vehicle listed here is like a goverment property and can be used for patrol etc.
[1] = {model = 'police', name = 'Police', type = 'car', grade = 1}, -- minimum grade
[2] = {model = 'police2', name = 'Police 2', type = 'car', grade = 1}, -- minimum grade
[3] = {model = 'police3', name = 'Police 3', type = 'car', grade = 1}, -- minimum grade
},
},
{
garage = "Sheriff Garage", --PALETO
Expand Down
2 changes: 1 addition & 1 deletion renzu_garage/fxmanifest.lua
Expand Up @@ -3,7 +3,7 @@ games {'common'}
ui_page 'html/index.html'

server_scripts {
'@mysql-async/lib/MySQL.lua',
'@mysql-async/lib/MySQL.lua',
'config.lua',
'server/server.lua'
}
Expand Down
19 changes: 12 additions & 7 deletions renzu_garage/server/server.lua
Expand Up @@ -170,13 +170,18 @@ ESX.RegisterServerCallback('renzu_garage:isvehicleingarage', function (source, c
else
plate = plate:upper()
end
local result = MysqlGarage(Config.Mysql,'fetchAll','SELECT `stored` ,impound FROM owned_vehicles WHERE UPPER(plate) = @plate', {
['@plate'] = plate
})
local stored = result[1].stored
local impound = result[1].impound
print(stored,impound)
cb(stored,impound)
if plate == Config.DefaultPlate then
cb(true,0)
else
local result = MysqlGarage(Config.Mysql,'fetchAll','SELECT `stored` ,impound FROM owned_vehicles WHERE UPPER(plate) = @plate', {
['@plate'] = plate
})
if result and result[1].stored ~= nil then
local stored = result[1].stored
local impound = result[1].impound
cb(stored,impound)
end
end
end)

RegisterServerEvent('renzu_garage:GetParkedVehicles')
Expand Down

0 comments on commit 62ee43c

Please sign in to comment.