Added equip networking & fixed UI

master
AlmTech Software 5 years ago
parent 41d3b4aabc
commit 1c72d96e28
  1. 16
      gamemode/engine/core/client/cl_character_net.lua
  2. 3
      gamemode/engine/derma/lib/cl_menu_iteminfo.lua
  3. 7
      gamemode/engine/lib/server/sv_inventory.lua
  4. 6
      gamemode/engine/lib/server/sv_networking.lua
  5. 7
      gamemode/engine/vars/sh_vars.lua

@ -81,6 +81,22 @@ function Quantum.Client.InventoryNet.EatItem( index )
net.WriteInt( index, Quantum.calculateNeededBits( Quantum.Inventory.Size ) ) net.WriteInt( index, Quantum.calculateNeededBits( Quantum.Inventory.Size ) )
net.SendToServer() 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 end
end end

@ -181,7 +181,8 @@ function iteminfo.giveoptions( p, page )
page.equippanels[item.equipslot].SetItem( item.id ) -- set its item page.equippanels[item.equipslot].SetItem( item.id ) -- set its item
---- EQUIP NET HERE ---- ---- EQUIP NET ----
Quantum.Client.InventoryNet.EquipItem( index )
end end
ypos = ypos + op.equip.h + yspacing ypos = ypos + op.equip.h + yspacing

@ -27,19 +27,20 @@ end
function Quantum.Server.Inventory.EquipItem( pl, itemindex ) function Quantum.Server.Inventory.EquipItem( pl, itemindex )
local char = Quantum.Server.Char.GetCurrentCharacter( pl ) 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] ) local itemTbl = Quantum.Item.Get( slotitem[1] )
if( itemTbl != nil ) then if( itemTbl != nil ) then
local equipslot = itemTbl.equipslot local equipslot = itemTbl.equipslot
PrintTable( itemTbl )
if( equipslot == nil ) then if( equipslot == nil ) then
Quantum.Error( tostring(pl) .. " tried to equip an non-equippable item: (" .. tostring(itemTbl[1]) .. ")" ) Quantum.Error( tostring(pl) .. " tried to equip an non-equippable item: (" .. tostring(itemTbl[1]) .. ")" )
return return
else 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 if( itemTbl.equipeffect != nil ) then
Quantum.Effect.Give( pl, itemTbl.equipeffect ) -- give the player the effect Quantum.Effect.Give( pl, itemTbl.equipeffect ) -- give the player the effect
end end

@ -147,7 +147,7 @@ end
local intcodeFunctions = { 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.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!" ) 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, end,
[Quantum.IntCode.DROP_ITEM] = function( pl, index, itemid, amount ) [Quantum.IntCode.DROP_ITEM] = function( pl, index, itemid, amount )
Quantum.Server.Inventory.DropItem( pl, index, amount ) Quantum.Server.Inventory.DropItem( pl, index, amount )
@ -157,6 +157,9 @@ local intcodeFunctions = {
end, end,
[Quantum.IntCode.EAT_ITEM] = function( pl, index, itemid, amount ) [Quantum.IntCode.EAT_ITEM] = function( pl, index, itemid, amount )
Quantum.Server.Inventory.EatItem( pl, index ) Quantum.Server.Inventory.EatItem( pl, index )
end,
[Quantum.IntCode.EQUIP_ITEM] = function( pl, index, itemid, amount )
Quantum.Server.Inventory.EquipItem( pl, index )
end end
} }
@ -166,6 +169,7 @@ net.Receive( "quantum_item_action", function( len, pl )
local itemid = net.ReadString() local itemid = net.ReadString()
local amount = net.ReadInt( Quantum.calculateNeededBits( Quantum.Inventory.MaxStackSize ) ) local amount = net.ReadInt( Quantum.calculateNeededBits( Quantum.Inventory.MaxStackSize ) )
print( "####", intcode, index, itemid, amount )
intcodeFunctions[intcode]( pl, index, itemid, amount ) intcodeFunctions[intcode]( pl, index, itemid, amount )
end) end)

@ -42,9 +42,12 @@ Quantum.IntCode = {
EQUIP_ITEM = 4, EQUIP_ITEM = 4,
DESTROY_ITEM = 5, -- to be added DESTROY_ITEM = 5, -- to be added
UPDATE = 6, UPDATE = 6,
BIT_SIZE = 3 BIT_SIZE = 4
} }
function Quantum.calculateNeededBits( n ) return math.ceil( math.log( n, 2 ) ) end function Quantum.calculateNeededBits( n ) return math.ceil( math.log( n, 2 ) ) end
function Quantum.WriteIntcode( intcode ) net.WriteInt( intcode, Quantum.IntCode.BIT_SIZE ) end function Quantum.WriteIntcode( intcode )
print( intcode )
net.WriteInt( intcode, Quantum.IntCode.BIT_SIZE )
end
Loading…
Cancel
Save