From 0d606bc859d54cd0b2086fddacd7e666fb1cd8b5 Mon Sep 17 00:00:00 2001 From: gononono64 <96976330+gononono64@users.noreply.github.com> Date: Mon, 19 May 2025 07:20:23 -0500 Subject: [PATCH] Entity fix and stash update Slimed OpenStash down to just an src and id instead of needing duplicate data. Was not sure if this affects newb so im throwing it in a pr. --- lib/entities/client/client_entity.lua | 6 +++--- modules/inventory/codem-inventory/server.lua | 19 +++++++++++++++++- modules/inventory/core_inventory/server.lua | 20 ++++++++++++++----- modules/inventory/jpr-inventory/server.lua | 17 ++++++++++++++-- modules/inventory/origen_inventory/server.lua | 15 +++++++++++++- modules/inventory/ox_inventory/server.lua | 19 ++++++++++++++---- modules/inventory/ps-inventory/server.lua | 11 ++++++++++ modules/inventory/qb-inventory/server.lua | 18 +++++++++++++++-- modules/inventory/qs-inventory/server.lua | 1 + modules/inventory/tgiann-inventory/server.lua | 1 + 10 files changed, 109 insertions(+), 18 deletions(-) diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index d3764ff..63c52af 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -20,7 +20,7 @@ local function SpawnEntity(entityData) local entity = nil local coords = entityData.coords - local rotation = entityData.rotation + local rotation = entityData.rotation or vector3(0.0, 0.0, 0.0) -- Default rotation if not provided if entityData.entityType == 'object' then entity = CreateObject(model, coords.x, coords.y, coords.z, false, false, false) @@ -40,7 +40,7 @@ local function SpawnEntity(entityData) SetModelAsNoLongerNeeded(model) SetEntityAsMissionEntity(entity, true, true) -- Keep entity from being deleted by game engine FreezeEntityPosition(entity, true) -- Optional freeze based on meta - if entityData.OnSpawn and type(entityData.OnSpawn) == 'function' then + if entityData.OnSpawn then entityData.OnSpawn(entityData) end -- print(string.format("[ClientEntity] Spawned %s entity %s (GameID: %s)", entityData.entityType, entityData.id, entity)) @@ -59,7 +59,7 @@ local function RemoveEntity(entityData) SetEntityAsMissionEntity(entityHandle, false, false) DeleteEntity(entityHandle) end - if entityData.OnRemove and type(entityData.OnRemove) == 'function' then + if entityData.OnRemove then entityData.OnRemove(entityData) end end diff --git a/modules/inventory/codem-inventory/server.lua b/modules/inventory/codem-inventory/server.lua index 0718c83..d0143ea 100644 --- a/modules/inventory/codem-inventory/server.lua +++ b/modules/inventory/codem-inventory/server.lua @@ -2,6 +2,7 @@ if GetResourceState('codem-inventory') ~= 'started' then return end Inventory = Inventory or {} +Inventory.Stashes = Inventory.Stashes or {} local codem = exports['codem-inventory'] @@ -104,10 +105,16 @@ end ---@param groups table ---@param coords table ---@return nil -Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) +Inventory.OpenStash = function(src, id) + local stash = Inventory.Stashes[id] + assert(stash, "Stash not found", id) + local label = stash.label + local slots = stash.slots + local weight = stash.weight TriggerClientEvent('community_bridge:client:codem-inventory:openStash', src, id, { label = label, slots = slots, weight = weight }) end + ---This will register a stash ---@param id number||string ---@param label string @@ -118,6 +125,16 @@ end ---@param coords table ---@return boolean Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + if Inventory.Stashes[id] then return true end + Inventory.Stashes[id] = { + id = id, + label = label, + slots = slots, + weight = weight, + owner = owner, + groups = groups, + coords = coords + } return true end diff --git a/modules/inventory/core_inventory/server.lua b/modules/inventory/core_inventory/server.lua index 43f1a25..163b821 100644 --- a/modules/inventory/core_inventory/server.lua +++ b/modules/inventory/core_inventory/server.lua @@ -2,7 +2,7 @@ if GetResourceState('core_inventory') ~= 'started' then return end Inventory = Inventory or {} - +Inventory.Stashes = Inventory.Stashes or {} local core = exports.core_inventory ---This will add an item, and return true or false based on success @@ -133,10 +133,10 @@ end ---@param groups table ---@param coords table ---@return nil -Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) - if not slots then slots = 30 end - local mathyShit = slots / 2 - core:openInventory(playerid, id, 'stash', mathyShit, mathyShit, true, nil, false) +Inventory.OpenStash = function(src, id) + local stash = Inventory.Stashes[id] + assert(stash, "Stash not found", id) + core:openInventory(src, id, 'stash', stash.slots, stash.weight, true, nil, false) end ---This will register a stash @@ -149,8 +149,18 @@ end ---@param coords table ---@return boolean Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + if Inventory.Stashes[id] then return true end if not slots then slots = 30 end local mathyShit = slots / 2 + Inventory.Stashes[id] = { + id = id, + label = label, + slots = mathyShit, + weight = mathyShit, + owner = owner, + groups = groups, + coords = coords + } core:openInventory(nil, id, 'stash', mathyShit, mathyShit, false, nil, false) return true end diff --git a/modules/inventory/jpr-inventory/server.lua b/modules/inventory/jpr-inventory/server.lua index 81f4dc0..725bd42 100644 --- a/modules/inventory/jpr-inventory/server.lua +++ b/modules/inventory/jpr-inventory/server.lua @@ -5,6 +5,7 @@ local jpr = exports['jpr-inventory'] local registeredShops = {} Inventory = Inventory or {} +Inventory.Stashes = Inventory.Stashes or {} ---This will add an item, and return true or false based on success ---@param src number @@ -70,8 +71,10 @@ end ---@param groups table ---@param coords table ---@return nil -Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) - TriggerClientEvent('community_bridge:client:jpr-inventory:openStash', src, id, { weight = weight, slots = slots }) +Inventory.OpenStash = function(src, id) + local stash = Inventory.Stashes[id] + assert(stash, "Stash not found", id) + TriggerClientEvent('community_bridge:client:jpr-inventory:openStash', src, id, { weight = stash.weight, slots = stash.slots }) end ---This will register a stash @@ -84,6 +87,16 @@ end ---@param coords table ---@return boolean Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + if Inventory.Stashes[id] then return true end + Inventory.Stashes[id] = { + id = id, + label = label, + slots = slots, + weight = weight, + owner = owner, + groups = groups, + coords = coords + } return true end diff --git a/modules/inventory/origen_inventory/server.lua b/modules/inventory/origen_inventory/server.lua index 19ec807..cb93f53 100644 --- a/modules/inventory/origen_inventory/server.lua +++ b/modules/inventory/origen_inventory/server.lua @@ -2,6 +2,7 @@ if GetResourceState('origen_inventory') ~= 'started' then return end Inventory = Inventory or {} +Inventory.Stashes = Inventory.Stashes or {} local origin = exports.origen_inventory @@ -107,7 +108,9 @@ end ---@param groups table ---@param coords table ---@return nil -Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) +Inventory.OpenStash = function(src, id) + local stash = Inventory.Stashes[id] + assert(stash, "Stash not found", id) return origin:OpenInventory(src, 'stash', id) end @@ -121,6 +124,16 @@ end ---@param coords table ---@return boolean Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + if Inventory.Stashes[id] then return true end + Inventory.Stashes[id] = { + id = id, + label = label, + slots = slots, + weight = weight, + owner = owner, + groups = groups, + coords = coords + } return origin:registerStash(id, label, slots, weight, owner, groups, coords) end diff --git a/modules/inventory/ox_inventory/server.lua b/modules/inventory/ox_inventory/server.lua index 6e3ec45..1ce1eed 100644 --- a/modules/inventory/ox_inventory/server.lua +++ b/modules/inventory/ox_inventory/server.lua @@ -5,7 +5,7 @@ local ox_inventory = exports.ox_inventory local registeredShops = {} Inventory = Inventory or {} - +Inventory.Stashes = Inventory.Stashes or {} ---This will add an item, and return true or false based on success ---@param src number ---@param item string @@ -94,8 +94,9 @@ end ---@param groups table ---@param coords table ---@return nil -Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) - TriggerClientEvent('ox_inventory:openInventory', src, 'stash', 'stash_' .. id) +Inventory.OpenStash = function(src, id) + assert(Inventory.Stashes[id], "Stash not found", id) + TriggerClientEvent('ox_inventory:openInventory', src, 'stash', id) end ---This will register a stash @@ -108,7 +109,17 @@ end ---@param coords table ---@return boolean Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) - return ox_inventory:RegisterStash(id, label, slots, weight, owner) + if Inventory.Stashes[id] then return true end + Inventory.Stashes[id] = { + id = id, + label = label, + slots = slots, + weight = weight, + owner = owner, + groups = groups, + coords = coords + } + return ox_inventory:RegisterStash(id, label, slots, weight, owner, groups) end ---This will return a boolean if the player has the item. diff --git a/modules/inventory/ps-inventory/server.lua b/modules/inventory/ps-inventory/server.lua index 2dc105c..3e854f9 100644 --- a/modules/inventory/ps-inventory/server.lua +++ b/modules/inventory/ps-inventory/server.lua @@ -4,6 +4,7 @@ local sloth = exports['ps-inventory'] local registeredShops = {} Inventory = Inventory or {} +Inventory.Stashes = Inventory.Stashes or {} ---This will add an item, and return true or false based on success ---@param src number @@ -106,6 +107,16 @@ end ---@param coords table ---@return boolean Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + if Inventory.Stashes[id] then return true end + Inventory.Stashes[id] = { + id = id, + label = label, + slots = slots, + weight = weight, + owner = owner, + groups = groups, + coords = coords + } return true end diff --git a/modules/inventory/qb-inventory/server.lua b/modules/inventory/qb-inventory/server.lua index 8df9850..6de16e3 100644 --- a/modules/inventory/qb-inventory/server.lua +++ b/modules/inventory/qb-inventory/server.lua @@ -3,6 +3,7 @@ if GetResourceState('qb-inventory') ~= 'started' then return end local qbInventory = exports['qb-inventory'] Inventory = Inventory or {} +Inventory.Stashes = Inventory.Stashes or {} local registeredShops = {} local v1ShopData = {} @@ -85,8 +86,11 @@ end ---@param groups table ---@param coords table ---@return nil -Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) - TriggerClientEvent('community_bridge:client:qb-inventory:openStash', src, id, { weight = weight, slots = slots }) +Inventory.OpenStash = function(src, id) + local stash = Inventory.Stashes[id] + assert(stash, "Stash not found", id) + + TriggerClientEvent('community_bridge:client:qb-inventory:openStash', src, id, { weight = stash.weight, slots = stash.slots}) end ---This will register a stash @@ -99,6 +103,16 @@ end ---@param coords table ---@return boolean Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + if Inventory.Stashes[id] then return true end + Inventory.Stashes[id] = { + id = id, + label = label, + slots = slots, + weight = weight, + owner = owner, + groups = groups, + coords = coords + } return true end diff --git a/modules/inventory/qs-inventory/server.lua b/modules/inventory/qs-inventory/server.lua index ddb2d3b..ed199f1 100644 --- a/modules/inventory/qs-inventory/server.lua +++ b/modules/inventory/qs-inventory/server.lua @@ -4,6 +4,7 @@ if GetResourceState('qs-inventory') ~= 'started' then return end local quasar = exports['qs-inventory'] Inventory = Inventory or {} +Inventory.Stashes = Inventory.Stashes or {} ---This will add an item, and return true or false based on success ---@param src number diff --git a/modules/inventory/tgiann-inventory/server.lua b/modules/inventory/tgiann-inventory/server.lua index f72cff6..ff33b96 100644 --- a/modules/inventory/tgiann-inventory/server.lua +++ b/modules/inventory/tgiann-inventory/server.lua @@ -4,6 +4,7 @@ if GetResourceState('tgiann-inventory') ~= 'started' then return end local tgiann = exports["tgiann-inventory"] Inventory = Inventory or {} +Inventory.Stashes = Inventory.Stashes or {} ---This will add an item, and return true or false based on success ---@param src number