Skip to content

Commit

Permalink
feat: make stashes/armory work
Browse files Browse the repository at this point in the history
  • Loading branch information
solareon committed Jan 25, 2024
1 parent 2438b03 commit 356e4d4
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 5 deletions.
104 changes: 104 additions & 0 deletions client/job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,20 @@ RegisterNetEvent('hospital:client:TreatWounds', function()
end
end)

---Opens the hospital stash.
---@param stashNumber integer id of stash to open
local function openStash(stashNumber)
if not QBX.PlayerData.job.onduty then return end
exports.ox_inventory:openInventory('stash', sharedConfig.locations.stash[stashNumber].name)
end

---Opens the hospital armory.
---@param stashNumber integer id of armory to open
local function openArmory(stashNumber)
if not QBX.PlayerData.job.onduty then return end
exports.ox_inventory:openInventory('shop', { type = sharedConfig.locations.armory[stashNumber].shopName })
end

---While in the garage pressing a key triggers storing the current vehicle or opening spawn menu.
---@param vehicles AuthorizedVehicles
---@param vehiclePlatePrefix string
Expand Down Expand Up @@ -313,6 +327,44 @@ if config.useTarget then
}
})
end
for i = 1, #sharedConfig.locations.stash do
exports.ox_target:addBoxZone({
name = 'stash' .. i,
coords = sharedConfig.locations.stash[i],
size = vec3(1, 1, 2),
rotation = -20,
debug = config.debugPoly,
options = {
{
type = 'client',
onSelect = openStash(i),
icon = 'fa fa-clipboard',
label = Lang:t('text.pstash'),
distance = 2,
groups = 'ambulance',
}
}
})
end
for i = 1, #sharedConfig.locations.armory do
exports.ox_target:addBoxZone({
name = 'armory' .. i,
coords = sharedConfig.locations.armory[i],
size = vec3(1, 1, 2),
rotation = -20,
debug = config.debugPoly,
options = {
{
type = 'client',
onSelect = openArmory(i),
icon = 'fa fa-clipboard',
label = Lang:t('text.armory'),
distance = 1.5,
groups = 'ambulance',
}
}
})
end
exports.ox_target:addBoxZone({
name = 'roof1',
coords = sharedConfig.locations.roof[1],
Expand Down Expand Up @@ -378,6 +430,58 @@ else
})
end

for i = 1, #sharedConfig.locations.stash do
local function enteredStashZone()
if QBX.PlayerData.job.onduty then
lib.showTextUI(Lang:t('text.pstash_button'))
end
end

local function outStashZone()
lib.hideTextUI()
end

local function insideStashZone()
OnKeyPress(openStash(i))
end

lib.zones.box({
coords = sharedConfig.locations.stash[i],
size = vec3(1, 1, 2),
rotation = -20,
debug = config.debugPoly,
onEnter = enteredStashZone,
onExit = outStashZone,
inside = insideStashZone,
})
end

for i = 1, #sharedConfig.locations.armory do
local function enteredArmoryZone()
if QBX.PlayerData.job.onduty then
lib.showTextUI(Lang:t('text.armory_button'))
end
end

local function outArmoryZone()
lib.hideTextUI()
end

local function insideArmoryZone()
OnKeyPress(openArmory(i))
end

lib.zones.box({
coords = sharedConfig.locations.armory[i].locations,
size = vec3(1, 1, 2),
rotation = -20,
debug = config.debugPoly,
onEnter = enteredArmoryZone,
onExit = outArmoryZone,
inside = insideArmoryZone,
})
end

local function enteredRoofZone()
if QBX.PlayerData.job.onduty then
lib.showTextUI(Lang:t('text.elevator_main'))
Expand Down
35 changes: 30 additions & 5 deletions config/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,44 @@ return {
vec4(351.58, -587.45, 74.16, 160.5),
vec4(-475.43, 5988.353, 31.716, 31.34),
},
armory = { -- Currently not in use, use ox_inventory/data/shops.lua instead
--vec3(0.0, 0.0, 0.0),
armory = {
{
shopName = 'ambulanceShop',
name = 'Ambulance Shop',
groups = { ambulance = 0 },
inventory = {
{ name = 'radio', price = 0 },
{ name = 'bandage', price = 0 },
{ name = 'painkillers', price = 0 },
{ name = 'firstaid', price = 0 },
{ name = 'weapon_flashlight', price = 0 },
{ name = 'weapon_fireextinguisher', price = 0 },
},
locations = {
vector3(309.93, -602.94, 43.29),
}
}
},
roof = {
vec3(338.54, -583.88, 74.17),
},
main = {
vec3(298.62, -599.66, 43.29),
},
stash = { -- Currently not in use, use ox_inventory/data/stashes.lua instead
--vec3(0.0, 0.0, 0.0),
stash = {
{
name = 'ambulanceStash',
label = 'Ambulance Stash',
weight = 100000,
slots = 30,
groups = { ambulance = 0 },
owner = false, -- Set to true for per player lockers
location = {
vector3(309.78, -596.6, 43.29),
}
}
},

---@class Bed
---@field coords vector4
---@field model number
Expand Down
20 changes: 20 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local config = require 'config.server'
local sharedConfig = require 'config.shared'
---@alias source number

lib.callback.register('qbx_ambulancejob:server:getPlayerStatus', function(_, targetSrc)
Expand All @@ -15,6 +17,18 @@ local function alertAmbulance(src, text)
end
end

local function registerArmory()
for _, armory in pairs(sharedConfig.locations.armory) do
exports.ox_inventory:RegisterShop(armory.name, armory)
end
end

local function registerStashes()
for _, stash in pairs(sharedConfig.locations.stash) do
exports.ox_inventory:RegisterStash(stash.name, stash.label, stash.slots, stash.weight, stash.owner, stash.groups, stash.location)
end
end

RegisterNetEvent('hospital:server:ambulanceAlert', function()
if GetInvokingResource() then return end
local src = source
Expand Down Expand Up @@ -152,3 +166,9 @@ RegisterNetEvent('qbx_medical:server:playerDied', function()
local src = source
alertAmbulance(src, Lang:t('info.civ_died'))
end)

AddEventHandler('onServerResourceStart', function(resource)
if resource ~= 'ox_inventory' then return end
registerArmory()
registerStashes()
end)

0 comments on commit 356e4d4

Please sign in to comment.