diff --git a/gamemode/engine/core/client/cl_character_net.lua b/gamemode/engine/core/client/cl_character_net.lua index fde5ee1..c4f263d 100644 --- a/gamemode/engine/core/client/cl_character_net.lua +++ b/gamemode/engine/core/client/cl_character_net.lua @@ -81,6 +81,22 @@ function Quantum.Client.InventoryNet.EatItem( index ) net.WriteInt( index, Quantum.calculateNeededBits( Quantum.Inventory.Size ) ) net.SendToServer() + end + end +end + +function Quantum.Client.InventoryNet.EquipItem( index ) + local item = Quantum.Client.Inventory[index] + local itemTbl = Quantum.Item.Get( item[1] ) + if( itemTbl != nil && item[2] > 0 ) then + if( itemTbl.equipslot != nil ) then + + net.Start( "quantum_item_action" ) + print("####", Quantum.IntCode.EQUIP_ITEM) + Quantum.WriteIntcode( Quantum.IntCode.EQUIP_ITEM ) + net.WriteInt( index, Quantum.calculateNeededBits( Quantum.Inventory.Size ) ) + net.SendToServer() + end end end \ No newline at end of file diff --git a/gamemode/engine/derma/lib/cl_menu_iteminfo.lua b/gamemode/engine/derma/lib/cl_menu_iteminfo.lua index 05a0075..a503e5a 100644 --- a/gamemode/engine/derma/lib/cl_menu_iteminfo.lua +++ b/gamemode/engine/derma/lib/cl_menu_iteminfo.lua @@ -181,7 +181,8 @@ function iteminfo.giveoptions( p, page ) page.equippanels[item.equipslot].SetItem( item.id ) -- set its item - ---- EQUIP NET HERE ---- + ---- EQUIP NET ---- + Quantum.Client.InventoryNet.EquipItem( index ) end ypos = ypos + op.equip.h + yspacing diff --git a/gamemode/engine/lib/server/sv_inventory.lua b/gamemode/engine/lib/server/sv_inventory.lua index 988fd82..ec5af6b 100644 --- a/gamemode/engine/lib/server/sv_inventory.lua +++ b/gamemode/engine/lib/server/sv_inventory.lua @@ -27,19 +27,20 @@ end function Quantum.Server.Inventory.EquipItem( pl, itemindex ) local char = Quantum.Server.Char.GetCurrentCharacter( pl ) - local slotitem = Quantum.Server.Inventory.GetSlotItem( char, index ) + local slotitem = Quantum.Server.Inventory.GetSlotItem( char, itemindex ) local itemTbl = Quantum.Item.Get( slotitem[1] ) 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]) .. ")" ) return else - if( Quantum.EquipSlots[equipslot] != nil ) then + if( table.KeyFromValue( Quantum.EquipSlots, equipslot ) != nil ) then - char.equipped[equipslot] = slotitem[1] -- set it in the table + char.equipped[equipslot] = { slotitem[1], itemindex } -- set it in the table if( itemTbl.equipeffect != nil ) then Quantum.Effect.Give( pl, itemTbl.equipeffect ) -- give the player the effect end diff --git a/gamemode/engine/lib/server/sv_networking.lua b/gamemode/engine/lib/server/sv_networking.lua index 45d7527..c67f265 100644 --- a/gamemode/engine/lib/server/sv_networking.lua +++ b/gamemode/engine/lib/server/sv_networking.lua @@ -147,7 +147,7 @@ end local intcodeFunctions = { [Quantum.IntCode.SET_ITEM] = function( pl, index, itemid, amount ) -- if the client is trying to set an item then kick the player Quantum.Warn( "Player [" .. pl:Nick() .. " | " .. pl:SteamID() .. "] tried to use a blacklisted Intcode function called from the client!" ) - pl:Kick( "[Quantum Security] Tried to use a invalid Intcode function. Nice try." ) + --pl:Kick( "[Quantum Security] Tried to use a invalid Intcode function. Nice try." ) end, [Quantum.IntCode.DROP_ITEM] = function( pl, index, itemid, amount ) Quantum.Server.Inventory.DropItem( pl, index, amount ) @@ -157,6 +157,9 @@ local intcodeFunctions = { end, [Quantum.IntCode.EAT_ITEM] = function( pl, index, itemid, amount ) Quantum.Server.Inventory.EatItem( pl, index ) + end, + [Quantum.IntCode.EQUIP_ITEM] = function( pl, index, itemid, amount ) + Quantum.Server.Inventory.EquipItem( pl, index ) end } @@ -166,6 +169,7 @@ net.Receive( "quantum_item_action", function( len, pl ) local itemid = net.ReadString() local amount = net.ReadInt( Quantum.calculateNeededBits( Quantum.Inventory.MaxStackSize ) ) + print( "####", intcode, index, itemid, amount ) intcodeFunctions[intcode]( pl, index, itemid, amount ) end) diff --git a/gamemode/engine/vars/sh_vars.lua b/gamemode/engine/vars/sh_vars.lua index f04c2e9..b316400 100644 --- a/gamemode/engine/vars/sh_vars.lua +++ b/gamemode/engine/vars/sh_vars.lua @@ -42,9 +42,12 @@ Quantum.IntCode = { EQUIP_ITEM = 4, DESTROY_ITEM = 5, -- to be added UPDATE = 6, - BIT_SIZE = 3 + BIT_SIZE = 4 } function Quantum.calculateNeededBits( n ) return math.ceil( math.log( n, 2 ) ) end -function Quantum.WriteIntcode( intcode ) net.WriteInt( intcode, Quantum.IntCode.BIT_SIZE ) end \ No newline at end of file +function Quantum.WriteIntcode( intcode ) + print( intcode ) + net.WriteInt( intcode, Quantum.IntCode.BIT_SIZE ) +end \ No newline at end of file