From e7041e6f13c3da86bb99cdb426cc9ba35f0447ad Mon Sep 17 00:00:00 2001 From: AlmTech Software Date: Wed, 1 Jan 2020 22:03:59 +0100 Subject: [PATCH] Began work on Dynamic Networking with Intcode --- gamemode/engine/core/client/cl_inventory_net.lua | 6 ++++++ gamemode/engine/lib/server/sv_networking.lua | 13 +++++++++++++ gamemode/settings/sh_items.lua | 2 +- gamemode/shared.lua | 11 +++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gamemode/engine/core/client/cl_inventory_net.lua diff --git a/gamemode/engine/core/client/cl_inventory_net.lua b/gamemode/engine/core/client/cl_inventory_net.lua new file mode 100644 index 0000000..77fd27b --- /dev/null +++ b/gamemode/engine/core/client/cl_inventory_net.lua @@ -0,0 +1,6 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ \ No newline at end of file diff --git a/gamemode/engine/lib/server/sv_networking.lua b/gamemode/engine/lib/server/sv_networking.lua index 1ac8baa..5373bf4 100644 --- a/gamemode/engine/lib/server/sv_networking.lua +++ b/gamemode/engine/lib/server/sv_networking.lua @@ -8,6 +8,7 @@ Quantum.Net = {} util.AddNetworkString( "quantum_menu_net" ) util.AddNetworkString( "quantum_menu_button_net" ) +util.AddNetworkString( "quantum_item_action" ) local function checkCacheTable( ply, cache_id, dt ) Quantum.Debug( "Checking cache tables (" .. tostring(ply) .. " | " .. tostring(cache_id) .. " | " .. tostring(dt) .. ")" ) @@ -114,3 +115,15 @@ net.Receive( "quantum_menu_button_net", function( len, pl ) local args = net.ReadTable() runNetFunc( pl, funcid, args ) end) + + +Quantum.Net.Inventory = {} + +local function WriteIntcode( intcode ) net.WriteInt( intcode, Quantum.IntCode.BIT_SIZE ) end + +function Quantum.Net.Inventory.SendItem( pl, index, itemid, amount ) -- sends a item to the client with amount of it, this is a DYNAMIC networking solution + net.Start( "quantum_item_action" ) + WriteIntcode( Quantum.IntCode.SEND_ITEM ) + net.WriteInt( index, 8 ) + net.Send( pl ) +end \ No newline at end of file diff --git a/gamemode/settings/sh_items.lua b/gamemode/settings/sh_items.lua index d63e4d1..65ec8cc 100644 --- a/gamemode/settings/sh_items.lua +++ b/gamemode/settings/sh_items.lua @@ -11,7 +11,7 @@ Quantum.Item.Create( "test", { model = "models/props_phx/gears/bevel12.mdl", soulbound = true, equipable = false, - rarity = Quantum.Rarity.Legendary, + rarity = Quantum.Rarity.Rare, usefunction = function() print( "Test!" ) end, consumefunction = function() print( "Test 2!" ) end } ) diff --git a/gamemode/shared.lua b/gamemode/shared.lua index f3a1ed1..7e504eb 100644 --- a/gamemode/shared.lua +++ b/gamemode/shared.lua @@ -18,3 +18,14 @@ Quantum.EmptyFunction = function() end include( "engine/sh_debug.lua" ) -- add the debug functions and stuff include( "settings/sh_settings.lua" ) + + +Quantum.IntCode = { + SEND_ITEM = 0, + DROP_ITEM = 1, + USE_ITEM = 2, + EAT_ITEM = 3, + EQUIP_ITEM = 4, + DESTROY_ITEM = 5, + BIT_SIZE = 3 +}