From d27a24ef08a68330a3277f50cff5b687534f32df Mon Sep 17 00:00:00 2001 From: AlmTech Software Date: Mon, 6 Jan 2020 18:54:11 +0100 Subject: [PATCH] Fixed equipped item now showing --- gamemode/engine/derma/menus/menu_charinfo.lua | 9 +++++++-- gamemode/engine/lib/server/sv_inventory.lua | 13 ++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/gamemode/engine/derma/menus/menu_charinfo.lua b/gamemode/engine/derma/menus/menu_charinfo.lua index 0c62dd3..1739653 100644 --- a/gamemode/engine/derma/menus/menu_charinfo.lua +++ b/gamemode/engine/derma/menus/menu_charinfo.lua @@ -107,6 +107,11 @@ local function createEquipSlotPanel( equiptype, x, y, scale, parent ) return p end +local function getItemInSlot( pos ) + local inv = Quantum.Client.Inventory || {} + return inv[pos][1] +end + function menu.open( dt ) local items = Quantum.Client.Inventory local equipped = Quantum.Client.Equipped @@ -199,8 +204,8 @@ function menu.open( dt ) local slotXpos = char.x + char.w*0.75 + padding*4 f.equippanels[Quantum.EquipSlots.Head] = createEquipSlotPanel( Quantum.EquipSlots.Head, slotXpos, char.y + char.h/5, slotScale, f ) -- create the panel - f.equippanels[Quantum.EquipSlots.Head].SetItem( equipped[ Quantum.EquipSlots.Head ] ) -- give its current item - + f.equippanels[Quantum.EquipSlots.Head].SetItem( getItemInSlot(equipped[ Quantum.EquipSlots.Head ]) ) -- give its current item + print( "EQUIPED: ", getItemInSlot(equipped[ Quantum.EquipSlots.Head ]) ) ---- Inventory panel ---- local inv = vgui.Create( "DPanel", f ) -- section for all of the item panels diff --git a/gamemode/engine/lib/server/sv_inventory.lua b/gamemode/engine/lib/server/sv_inventory.lua index 02c8fbb..3eb64a0 100644 --- a/gamemode/engine/lib/server/sv_inventory.lua +++ b/gamemode/engine/lib/server/sv_inventory.lua @@ -32,7 +32,6 @@ function Quantum.Server.Inventory.EquipItem( pl, itemindex ) if( itemTbl != nil ) then local equipslot = itemTbl.equipslot - PrintTable( itemTbl ) if( equipslot == nil ) then Quantum.Error( tostring(pl) .. " tried to equip an non-equippable item: (" .. tostring(itemTbl[1]) .. ")" ) @@ -40,11 +39,11 @@ function Quantum.Server.Inventory.EquipItem( pl, itemindex ) else if( table.KeyFromValue( Quantum.EquipSlots, equipslot ) != nil ) then - char.equipped[equipslot] = { slotitem[1], itemindex } -- set it in the table + char.equipped[equipslot] = itemindex -- set it in the table if( itemTbl.equipeffect != nil ) then Quantum.Effect.Give( pl, itemTbl.equipeffect ) -- give the player the effect end - Quantum.Debug( tostring(pl) .. " equipped item (" .. tostring(slotitem[1]) .. ")" ) + Quantum.Debug( tostring(pl) .. " equipped item (" .. tostring(slotitem[1]) .. ") - (" .. tostring(itemindex) .. ")" ) -- NETWORKING -- Quantum.Net.Inventory.Update( pl ) -- update the client @@ -58,14 +57,18 @@ end function Quantum.Server.Inventory.UnEquipItem( pl, equipslot ) local char = Quantum.Server.Char.GetCurrentCharacter( pl ) - if( char.equipped[equipslot] != nil && char.equipped[equipslot] != -1 ) then - local itemTbl = Quantum.Item.Get( char.equipped[equipslot] ) + if( char.equipped[equipslot] != nil ) then + local slotItem = Quantum.Server.Inventory.GetSlotItem( char, char.equipped[equipslot] ) + local itemTbl = Quantum.Item.Get( slotItem ) if( itemTbl.equipeffect != nil ) then -- remove the items effect Quantum.Effect.Remove( pl, itemTbl.equipeffect ) end + Quantum.Debug( tostring(pl) .. " unequipped item (" .. tostring( itemTbl.id ) .. ") - (" .. tostring( char.equipped[equipslot] ) .. ")" ) char.equipped[equipslot] = nil + + Quantum.Net.Inventory.Update( pl ) -- update the client end end