Skip to content

Commit

Permalink
Easier config for items/vehicles
Browse files Browse the repository at this point in the history
  • Loading branch information
GhzGarage committed Oct 23, 2023
1 parent f61ae8a commit 6284fdd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 76 deletions.
37 changes: 35 additions & 2 deletions client/job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ function TakeOutVehicle(vehicleInfo)
end, vehicleInfo, coords, true)
end

local function getAuthorizedVehicles(grade)
local accessibleVehicles = {}
for availableGrade, vehicles in pairs(Config.AuthorizedVehicles) do
if grade >= availableGrade then
for vehicleName, vehicleLabel in pairs(vehicles) do
accessibleVehicles[vehicleName] = vehicleLabel
end
end
end
return accessibleVehicles
end

function MenuGarage()
local vehicleMenu = {
{
Expand All @@ -49,7 +61,7 @@ function MenuGarage()
}
}

local authorizedVehicles = Config.AuthorizedVehicles[QBCore.Functions.GetPlayerData().job.grade.level]
local authorizedVehicles = getAuthorizedVehicles(QBCore.Functions.GetPlayerData().job.grade.level)
for veh, label in pairs(authorizedVehicles) do
vehicleMenu[#vehicleMenu + 1] = {
header = label,
Expand Down Expand Up @@ -310,7 +322,28 @@ end)

RegisterNetEvent('qb-ambulancejob:armory', function()
if onDuty then
TriggerServerEvent("inventory:server:OpenInventory", "shop", "hospital", Config.Items)
local authorizedItemsList = {}
local playerGrade = PlayerJob.grade.level
for grade = 0, playerGrade do
if Config.Items[grade] then
for _, item in ipairs(Config.Items[grade]) do
authorizedItemsList[#authorizedItemsList+1] = {
name = item.name,
price = item.price,
amount = item.amount,
info = item.info,
type = item.type,
slot = #authorizedItemsList + 1
}
end
end
end
local authorizedItems = {
label = Lang:t('info.safe'),
slots = #authorizedItemsList,
items = authorizedItemsList
}
TriggerServerEvent("inventory:server:OpenInventory", "shop", "hospital", authorizedItems)
end
end)

Expand Down
86 changes: 12 additions & 74 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Config.Locations = { -- Edit the various interaction points for players or creat
[6] = {coords = vector4(360.32, -587.19, 43.02, 152.08), taken = false, model = -1091386327},
[7] = {coords = vector4(349.82, -583.33, 43.02, 152.08), taken = false, model = -1091386327},
[8] = {coords = vector4(326.98, -576.17, 43.02, 152.08), taken = false, model = -1091386327},
--- paleto
--- paleto
[9] = {coords = vector4(-252.43, 6312.25, 32.34, 313.48), taken = false, model = 2117668672},
[10] = {coords = vector4(-247.04, 6317.95, 32.34, 134.64), taken = false, model = 2117668672},
[11] = {coords = vector4(-255.98, 6315.67, 32.34, 313.91), taken = false, model = 2117668672},
Expand All @@ -90,82 +90,20 @@ Config.Locations = { -- Edit the various interaction points for players or creat
}
}

Config.AuthorizedVehicles = { -- Vehicles players can use based on their ambulance job grade level
-- Grade 0
Config.AuthorizedVehicles = { -- Grade is key, don't add same vehicle in multiple grades. Higher rank can see lower
[0] = {
["ambulance"] = "Ambulance",
},
-- Grade 1
[1] = {
["ambulance"] = "Ambulance",

},
-- Grade 2
[2] = {
["ambulance"] = "Ambulance",
},
-- Grade 3
[3] = {
["ambulance"] = "Ambulance",
},
-- Grade 4
[4] = {
["ambulance"] = "Ambulance",
}
["ambulance"] = "Ambulance"
}
}

Config.Items = { -- Items found in the ambulance shop for players with the ambulance job to purchase
label = Lang:t('info.safe'),
slots = 30,
items = {
[1] = {
name = "radio",
price = 0,
amount = 50,
info = {},
type = "item",
slot = 1,
},
[2] = {
name = "bandage",
price = 0,
amount = 50,
info = {},
type = "item",
slot = 2,
},
[3] = {
name = "painkillers",
price = 0,
amount = 50,
info = {},
type = "item",
slot = 3,
},
[4] = {
name = "firstaid",
price = 0,
amount = 50,
info = {},
type = "item",
slot = 4,
},
[5] = {
name = "weapon_flashlight",
price = 0,
amount = 50,
info = {},
type = "item",
slot = 5,
},
[6] = {
name = "weapon_fireextinguisher",
price = 0,
amount = 50,
info = {},
type = "item",
slot = 6,
},
Config.Items = { -- Grade is key, don't add same item in multiple grades. Higher rank can see lower
[0] = {
{name = "radio", price = 0, amount = 50, info = {}, type = "item"},
{name = "bandage", price = 0, amount = 50, info = {}, type = "item"},
{name = "painkillers", price = 0, amount = 50, info = {}, type = "item"},
{name = "firstaid", price = 0, amount = 50, info = {}, type = "item"},
{name = "weapon_flashlight", price = 0, amount = 50, info = {}, type = "item"},
{name = "weapon_fireextinguisher", price = 0, amount = 50, info = {}, type = "item"},
}
}

Expand Down

0 comments on commit 6284fdd

Please sign in to comment.