From f8d417575406e2d2464b1f2ba156d4550e7c511d Mon Sep 17 00:00:00 2001 From: AlmTech Date: Sun, 15 Sep 2019 18:52:17 +0200 Subject: [PATCH] Networking keybinds & networked functions --- gamemode/engine/core/sh_player_binds.lua | 21 ++++++++++++++++++++ gamemode/engine/derma/cl_character.lua | 2 +- gamemode/engine/lib/server/sv_networking.lua | 18 ++++++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 gamemode/engine/core/sh_player_binds.lua diff --git a/gamemode/engine/core/sh_player_binds.lua b/gamemode/engine/core/sh_player_binds.lua new file mode 100644 index 0000000..a2a138c --- /dev/null +++ b/gamemode/engine/core/sh_player_binds.lua @@ -0,0 +1,21 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + + +if SERVER then + + local keyfuncs = { + [IN_USE] = function( pl ) + pl:ChatPrint( "Use bind test" ) + end + } + + function GM:KeyRelease( ply, key ) + if( keyfuncs[key] ) then keyfuncs[key]( pl ) end + end + +end \ No newline at end of file diff --git a/gamemode/engine/derma/cl_character.lua b/gamemode/engine/derma/cl_character.lua index c4ad9d4..e674201 100644 --- a/gamemode/engine/derma/cl_character.lua +++ b/gamemode/engine/derma/cl_character.lua @@ -18,7 +18,7 @@ local function char_derma() txt:SetPos( 100, 100 ) local b = vgui.Create( "DButton" ) - b:SetText( "Create char" ) + b:SetText( "Create Char" ) b:SizeToContents() b.DoClick = function() net.Start( "quantum_menu_button_net" ) diff --git a/gamemode/engine/lib/server/sv_networking.lua b/gamemode/engine/lib/server/sv_networking.lua index 589f7a3..468458c 100644 --- a/gamemode/engine/lib/server/sv_networking.lua +++ b/gamemode/engine/lib/server/sv_networking.lua @@ -49,8 +49,24 @@ local function SendDatatableToClient( client, dt, type ) net.Send( client ) end +local funcs = { + ["createChar"] = true +} + +local netfuncs = { + createChar = function( pl, args ) + Quantum.Server.Char.Load( pl, 1, args ) + end +} + +local function runNetFunc( pl, func, args ) + if( funcs[func] ) then + netfuncs[func]( pl, args ) + end +end net.Receive( "quantum_menu_button_net", function( len, pl ) local funcid = net.ReadString() - local args = net.ReadTable() + local args = net.ReadTable() + runNetFunc( pl, funcid, args ) end)