Skip to content

Commit

Permalink
feat: armory
Browse files Browse the repository at this point in the history
* feat: armory

* Update main.lua

* fix: personal stashes

* fix: armory

* fix(config/shared): groups

* fix(client): some param name changes

* fix: all option params marked as optional
  • Loading branch information
mafewtm authored Sep 3, 2024
1 parent bc69192 commit acb3e8c
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 46 deletions.
92 changes: 64 additions & 28 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local config = require 'config.client'
local sharedConfig = require 'config.shared'
local vehicles = require 'client.vehicles'

---@param department BlipData
---@param department? BlipData
local function createBlip(department)
if not department then return end

Expand All @@ -16,8 +16,8 @@ local function createBlip(department)
EndTextCommandSetBlipName(blip)
end

---@param job string
---@param department ManagementData
---@param job? string
---@param department? ManagementData
local function createDuty(job, department)
if not job or not department then return end

Expand All @@ -42,8 +42,8 @@ local function createDuty(job, department)
end
end

---@param job string
---@param department DutyData
---@param job? string
---@param department? DutyData
local function createManagement(job, department)
if not job or not department then return end

Expand Down Expand Up @@ -73,29 +73,64 @@ local function createManagement(job, department)
end
end

---@param job string
---@param department PersonalStashData
local function createPersonalStash(job, department)
if not job or not department then return end
---@param job? string
---@param armories? ArmoryData
local function createArmory(job, armories)
if not job or not armories then return end

for i = 1, #armories do
local armory = armories[i]

for ii = 1, #armory.locations do
local location = armory.locations[ii]

exports.ox_target:addSphereZone({
coords = location,
radius = armory.radius or 1.5,
debug = config.debugPoly,
options = {
{
name = ('%s-Armory'):format(job),
icon = 'fa-solid fa-person-rifle',
label = locale('targets.armory'),
canInteract = function()
return QBX.PlayerData.job.onduty
end,
onSelect = function()
exports.ox_inventory:openInventory('shop', { type = armory.shopType, id = ii })
end,
groups = armory.groups,
distance = 1.5,
},
}
})
end
end
end

for i = 1, #department do
local stash = department[i]
local stashName = ('%s-%s-PersonalStash'):format(i, job)
---@param job? string
---@param stashes? PersonalStashData
local function createPersonalStash(job, stashes)
if not job or not stashes then return end

for i = 1, #stashes do
local stash = stashes[i]
local stashId = ('%s-PersonalStash'):format(job)

exports.ox_target:addSphereZone({
coords = stash.coords,
radius = stash.radius or 1.5,
debug = config.debugPoly,
options = {
{
name = stashName,
name = stashId,
icon = 'fa-solid fa-box-archive',
label = locale('targets.personal_stash'),
canInteract = function()
return QBX.PlayerData.job.onduty
end,
onSelect = function()
exports.ox_inventory:openInventory('stash', stashName)
exports.ox_inventory:openInventory('stash', stashId)
end,
groups = stash.groups,
distance = 1.5,
Expand All @@ -105,8 +140,8 @@ local function createPersonalStash(job, department)
end
end

---@param job string
---@param department EvidenceData
---@param job? string
---@param department? EvidenceData
local function createEvidence(job, department)
if not job or not department then return end

Expand Down Expand Up @@ -136,13 +171,13 @@ local function createEvidence(job, department)
end
end

---@param job string
---@param department VehicleData
local function createGarage(job, department)
if not job or not department then return end
---@param job? string
---@param garages? VehicleData
local function createGarage(job, garages)
if not job or not garages then return end

for i = 1, #department do
local garage = department[i]
for i = 1, #garages do
local garage = garages[i]

exports.ox_target:addSphereZone({
coords = garage.coords,
Expand Down Expand Up @@ -180,13 +215,13 @@ local function createGarage(job, department)
end
end

---@param job string
---@param department VehicleData
local function createHelipad(job, department)
if not job or not department then return end
---@param job? string
---@param helipads? VehicleData
local function createHelipad(job, helipads)
if not job or not helipads then return end

for i = 1, #department do
local helipad = department[i]
for i = 1, #helipads do
local helipad = helipads[i]

exports.ox_target:addSphereZone({
coords = helipad.coords,
Expand Down Expand Up @@ -353,6 +388,7 @@ CreateThread(function()
createBlip(data.blip)
createDuty(job, data.duty)
createManagement(job, data.management)
createArmory(job, data.armory)
createPersonalStash(job, data.personalStash)
createEvidence(job, data.evidence)
createGarage(job, data.garage)
Expand Down
51 changes: 42 additions & 9 deletions config/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,67 @@ return {
scale = 0.8,
color = 29
},
duty = {
{
coords = vec3(440.085, -974.924, 30.689),
radius = 1.5,
groups = { police = 0 }
},
},
management = {
{
coords = vec3(447.04, -974.01, 30.44),
radius = 1.5,
groups = { 'police' }
groups = { police = 0 }
}
},
duty = {
armory = {
{
coords = vec3(440.085, -974.924, 30.689),
shopType = 'PoliceArmory',
name = 'Armory',
radius = 1.5,
groups = { 'police' }
},
groups = { police = 0 },
inventory = {
{ name = 'weapon_stungun', price = 100, metadata = { registered = true, serial = 'LEO' } },
{ name = 'weapon_pistol', price = 500, metadata = { registered = true, serial = 'LEO' } },
{ name = 'weapon_nightstick', price = 50, metadata = { registered = true, serial = 'LEO' } },
{ name = 'weapon_flashlight', price = 50, metadata = { registered = true, serial = 'LEO' } },
{ name = 'weapon_smg', price = 900, metadata = { registered = true, serial = 'LEO' }, grade = 1 },
{ name = 'weapon_carbinerifle', price = 1000, metadata = { registered = true, serial = 'LEO' }, grade = 3 },

{ name = 'ammo-9', price = 10 },
{ name = 'ammo-rifle', price = 30, grade = 3 },

{ name = 'at_flashlight', price = 75 },
{ name = 'at_clip_extended_pistol', price = 200 },
{ name = 'at_clip_extended_rifle', price = 300, grade = 3 },

{ name = 'armour', price = 500 },
{ name = 'radio', price = 50 },
{ name = 'handcuffs', price = 50 },
{ name = 'bandage', price = 50 },
{ name = 'empty_evidence_bag', price = 10 },
},
locations = {
vec3(462.23, -981.12, 30.68),
}
}
},
personalStash = {
{
label = 'Personal Stash',
coords = vec3(453.075, -980.124, 30.889),
radius = 1.5,
slots = 100,
weight = 100000,
groups = { 'police' }
groups = { police = 0 }
},
},
evidence = {
{
coords = vec3(442.1722, -996.067, 30.689),
radius = 1.5,
groups = { 'police' }
groups = { police = 0 }
},
},
garage = {
Expand All @@ -52,7 +85,7 @@ return {
{ name = 'police4', grade = 0 },
{ name = 'polgauntlet', grade = 0 },
},
groups = { 'police' }
groups = { police = 0 }
},
},
helipad = {
Expand All @@ -63,7 +96,7 @@ return {
catalogue = {
{ name = 'polmav', grade = 0 },
},
groups = { 'police' }
groups = { police = 0 }
}
}
},
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"targets": {
"duty": "Clock In/Out",
"boss_menu": "Open Job Management",
"armory": "Open Armory",
"personal_stash": "Open Personal Stash",
"evidence_drawers": "Open Evidence Drawers",
"garage": "Open Garage",
Expand Down
28 changes: 20 additions & 8 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
local sharedConfig = require 'config.shared'

---@param job string
---@param personalStash PersonalStashData
local function registerPersonalStash(job, personalStash)
if not job or not personalStash then return end
---@param job? string
---@param department? PersonalStashData
local function registerPersonalStash(job, department)
if not job or not department then return end

for i = 1, #personalStash do
local stash = personalStash[i]
local stashName = ('%s-%s-PersonalStash'):format(i, job)
for i = 1, #department do
local stash = department[i]
local stashId = ('%s-PersonalStash'):format(job)

exports.ox_inventory:RegisterStash(stashName, 'Personal Stash', stash.slots or 100, stash.weight or 100000, true, stash.groups)
exports.ox_inventory:RegisterStash(stashId, stash.label, stash.slots or 100, stash.weight or 100000, true, stash.groups, stash.coords)
end
end

---@param department? ArmoryData
local function registerArmory(department)
if not department then return end

for i = 1, #department do
local armory = department[i]

exports.ox_inventory:RegisterShop(armory.shopType, armory)
end
end

Expand Down Expand Up @@ -37,6 +48,7 @@ AddEventHandler('onServerResourceStart', function(resource)
if resource ~= cache.resource then return end

for job, data in pairs(sharedConfig.departments) do
registerArmory(data.armory)
registerPersonalStash(job, data.personalStash)
end
end)
22 changes: 21 additions & 1 deletion types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,22 @@
---@field groups table
---@field radius? number radius of the zone. default is 1.5

---@class ArmoryInventoryItem
---@field name string
---@field price number
---@field metadata? table<string, any>
---@field grade? number

---@class ArmoryData
---@field shopType string
---@field name string
---@field groups table
---@field inventory ArmoryInventoryItem[]
---@field locations table
---@field radius? number radius of the zone. default is 1.5

---@class PersonalStashData
---@field label string
---@field coords vector3
---@field groups table
---@field radius? number radius of the zone. default is 1.5
Expand All @@ -29,17 +44,22 @@
---@field groups table
---@field radius? number radius of the zone. default is 1.5

---@class CatalogueItem
---@field name string
---@field grade number

---@class VehicleData
---@field coords vector3
---@field spawn vector4
---@field radius number
---@field catalogue table
---@field catalogue CatalogueItem[]
---@field groups table

---@class DepartmentData
---@field blip BlipData
---@field duty DutyData[]
---@field management ManagementData[]
---@field armory ArmoryData[]
---@field personalStash PersonalStashData[]
---@field evidence EvidenceData[]
---@field garage VehicleData[]
Expand Down

0 comments on commit acb3e8c

Please sign in to comment.