Skip to content

Commit

Permalink
refactor: make Shop and Armory work
Browse files Browse the repository at this point in the history
* refactor: remove stash and armory

* feat: make stashes/armory work

* fix: linting

* refactor: use locale
  • Loading branch information
solareon authored Jan 28, 2024
1 parent 05dcbcc commit 6c82b9c
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 73 deletions.
74 changes: 63 additions & 11 deletions client/job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,17 @@ RegisterNetEvent('hospital:client:TreatWounds', function()
end)

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

---Opens the hospital armory.
local function openArmory()
if QBX.PlayerData.job.onduty then
TriggerServerEvent('inventory:server:OpenInventory', 'shop', 'hospital', config.items)
end
---@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.
Expand Down Expand Up @@ -330,14 +330,14 @@ if config.useTarget then
for i = 1, #sharedConfig.locations.stash do
exports.ox_target:addBoxZone({
name = 'stash' .. i,
coords = sharedConfig.locations.stash[i],
coords = sharedConfig.locations.stash[i].location,
size = vec3(1, 1, 2),
rotation = -20,
debug = config.debugPoly,
options = {
{
type = 'client',
onSelect = openStash,
onSelect = openStash(i),
icon = 'fa fa-clipboard',
label = locale('text.pstash'),
distance = 2,
Expand All @@ -349,14 +349,14 @@ if config.useTarget then
for i = 1, #sharedConfig.locations.armory do
exports.ox_target:addBoxZone({
name = 'armory' .. i,
coords = sharedConfig.locations.armory[i],
coords = sharedConfig.locations.armory[i].locations,
size = vec3(1, 1, 2),
rotation = -20,
debug = config.debugPoly,
options = {
{
type = 'client',
onSelect = openArmory,
onSelect = openArmory(i),
icon = 'fa fa-clipboard',
label = locale('text.armory'),
distance = 1.5,
Expand Down Expand Up @@ -482,6 +482,58 @@ else
})
end

for i = 1, #sharedConfig.locations.stash do
local function enteredStashZone()
if QBX.PlayerData.job.onduty then
lib.showTextUI(locale('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].location,
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(locale('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[1],
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(locale('text.elevator_main'))
Expand Down
55 changes: 0 additions & 55 deletions config/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,59 +87,4 @@ return {
livery = 1,
},
},

items = { -- Items found in the ambulance shop
label = Lang:t('info.safe'),
slots = 30,
items = {
{
name = 'radio',
price = 0,
amount = 50,
info = {},
type = 'item',
slot = 1,
},
{
name = 'bandage',
price = 0,
amount = 50,
info = {},
type = 'item',
slot = 2,
},
{
name = 'painkillers',
price = 0,
amount = 50,
info = {},
type = 'item',
slot = 3,
},
{
name = 'firstaid',
price = 0,
amount = 50,
info = {},
type = 'item',
slot = 4,
},
{
name = 'weapon_flashlight',
price = 0,
amount = 50,
info = {},
type = 'item',
slot = 5,
},
{
name = 'weapon_fireextinguisher',
price = 0,
amount = 50,
info = {},
type = 'item',
slot = 6,
},
},
},
}
37 changes: 30 additions & 7 deletions config/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,46 @@ 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 = locale('text.armory'),
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) -- Only a single location is supported.
}
}
},
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 = locale('text.pstash'),
weight = 100000,
slots = 30,
groups = { ambulance = 0 },
owner = true, -- Set to false for group stash
location = vector3(309.78, -596.6, 43.29)
}
},

---@class Bed
---@field coords vector4
---@field model number

---@type table<string, {coords: vector3, checkIn?: vector3, beds: Bed[]}>
hospitals = {
pillbox = {
Expand Down Expand Up @@ -67,7 +90,7 @@ return {
},
},
},

stations = {
{label = locale('info.pb_hospital'), coords = vec4(304.27, -600.33, 43.28, 272.249)},
}
Expand Down
19 changes: 19 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local sharedConfig = require 'config.shared'
---@alias source number

lib.callback.register('qbx_ambulancejob:server:getPlayerStatus', function(_, targetSrc)
Expand All @@ -15,6 +16,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 +165,9 @@ RegisterNetEvent('qbx_medical:server:playerDied', function()
local src = source
alertAmbulance(src, locale('info.civ_died'))
end)

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

0 comments on commit 6c82b9c

Please sign in to comment.