From 457d6cb56eec85a730948d4ec13ab492ccdd993a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=8Ckami=20Adam=20Sila=20Kann?= <17802255+WolfKann@users.noreply.github.com> Date: Sat, 6 Apr 2024 01:19:45 -0400 Subject: [PATCH 1/7] Update event.lua for develop This adds Is_No_Targeted, Is_No_Draw, and also adds variables to detect Int/Float/Bool/String NetVars, while also adding an advanced version in the rare chance two netvar types share a name. --- lua/pac3/core/client/parts/event.lua | 93 ++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/lua/pac3/core/client/parts/event.lua b/lua/pac3/core/client/parts/event.lua index 79945b4bf..a30738025 100644 --- a/lua/pac3/core/client/parts/event.lua +++ b/lua/pac3/core/client/parts/event.lua @@ -723,6 +723,99 @@ PART.OldEvents = { end, }, + + is_no_draw = { + callback = function(self, ent) + ent = try_viewmodel(ent) + return ent:GetNoDraw() + end, + }, + + is_no_target = { + callback = function(self, ent) + ent = try_viewmodel(ent) + return ent:IsFlagSet( FL_NOTARGET ) + end, + }, + + + // This is a function to grab any and all network variables and try to run them with the correct type, as it's possible to have GetNWInt("Pac", 1) and "GetNWString("Pac" ValueHere") + // This code is designed to try and run things correctly and detect specific types of Network Variables, Since GetNWVar does not have the varable display in the table, but GetNW2var does. + // It's also useful if a player doesn't know what the displayed function is as a Networked Variable. + + get_networked = { + arguments = {{name = "string"}, {result = "string"}}, + userdata = {{enums = function() + local base_tbl = LocalPlayer():GetNWVarTable() + local enum_tbl = {} + for k,v in pairs(base_tbl) do + enum_tbl[k] = k + end + return enum_tbl + end}}, + + callback = function(self, ent, name, result) + ent = try_viewmodel(ent) + + if ent:GetNWString(tostring(name)) == tostring(result) then + return ent:GetNWString(tostring(name)) == tostring(result) + elseif ent:GetNWInt(tostring(name)) == result then + return self:NumberOperator(ent:GetNWInt(tostring(name), result)) + elseif ent:GetNWBool(tostring(name)) == tobool(result) then + return ent:GetNWBool(tostring(name)) == tobool(result) + elseif ent:GetNWFloat(tostring(name)) == result then + return self:NumberOperator(ent:GetNWFloat(tostring(name), result)) + end + return false + end, + }, + + //These are left in so that if a player knows what a variable is as a network, they can manually and directly get it + //In the rare event the operation above has two of the same named variabels (which is rare and stupid, but can happen, so it's better to nip it in the butt instead of trying to argue over it.) + + get_networked_string = { + arguments = {{name = "string"}, {result = "string"}}, + userdata = {{enums = function() + local base_tbl = LocalPlayer():GetNWVarTable() + local enum_tbl = {} + for k,v in pairs(base_tbl) do + if isstring(v) then + enum_tbl[k] = k + end + end + return enum_tbl + end}}, + callback = function(self, ent, name, result) + ent = try_viewmodel(ent) + return ent:GetNWString(tostring(name)) == tostring(result) + end, + }, + + get_networked_int = { + arguments = {{name = "string"}, {num = "number"}}, + callback = function(self, ent, name, num) + ent = try_viewmodel(ent) + return self:NumberOperator(ent:GetNWInt(tostring(name), num)) + end, + }, + + get_networked_bool = { + arguments = {{name = "string"}, {bool = "string"}}, + callback = function(self, ent, name, bool) + ent = try_viewmodel(ent) + return ent:GetNWBool(tostring(name)) == tobool(bool) + end, + }, + + get_networked_float = { + arguments = {{name = "string"}, {float = "number"}}, + callback = function(self, ent, name, float) + ent = try_viewmodel(ent) + return self:NumberOperator(ent:GetNWFloat(tostring(name), float)) + end, + }, + + client_spawned = { operator_type = "number", preferred_operator = "below", tutorial_explanation = "client_spawned supposedly activates for some time after you spawn", From 530ca57ca5c12fafad6e6c9152ef09c2aa4973da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=8Ckami=20Adam=20Sila=20Kann?= <17802255+WolfKann@users.noreply.github.com> Date: Sat, 6 Apr 2024 03:30:32 -0400 Subject: [PATCH 2/7] Update event.lua Fixed Code from Pingu7867's Suggestions --- lua/pac3/core/client/parts/event.lua | 65 ++++++++++++++++++---------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/lua/pac3/core/client/parts/event.lua b/lua/pac3/core/client/parts/event.lua index a30738025..155b53a02 100644 --- a/lua/pac3/core/client/parts/event.lua +++ b/lua/pac3/core/client/parts/event.lua @@ -746,27 +746,20 @@ PART.OldEvents = { get_networked = { arguments = {{name = "string"}, {result = "string"}}, userdata = {{enums = function() - local base_tbl = LocalPlayer():GetNWVarTable() - local enum_tbl = {} - for k,v in pairs(base_tbl) do - enum_tbl[k] = k - end - return enum_tbl + return LocalPlayer():GetNWVarTable() end}}, callback = function(self, ent, name, result) - ent = try_viewmodel(ent) - - if ent:GetNWString(tostring(name)) == tostring(result) then - return ent:GetNWString(tostring(name)) == tostring(result) - elseif ent:GetNWInt(tostring(name)) == result then - return self:NumberOperator(ent:GetNWInt(tostring(name), result)) - elseif ent:GetNWBool(tostring(name)) == tobool(result) then - return ent:GetNWBool(tostring(name)) == tobool(result) - elseif ent:GetNWFloat(tostring(name)) == result then - return self:NumberOperator(ent:GetNWFloat(tostring(name), result)) - end - return false + ent = try_viewmodel(ent) + local anyvar = ent:GetNWVarTable()[name] + + if isstring(anyvar) then + return self:StringOperator(anyvar, result) + elseif isnumber(anyvar) then + return self:NumberOperator(anyvar, tonumber(result) or 0) + elseif isbool(anyvar) then + return anyvar == tobool(result) + end end, }, @@ -787,20 +780,39 @@ PART.OldEvents = { end}}, callback = function(self, ent, name, result) ent = try_viewmodel(ent) - return ent:GetNWString(tostring(name)) == tostring(result) + return StringOperator(ent:GetNWString(tostring(name)), tostring(result)) end, }, get_networked_int = { - arguments = {{name = "string"}, {num = "number"}}, + arguments = {{name = "string"}, {num = "number"}}, + userdata = {{enums = function() + local base_tbl = LocalPlayer():GetNWVarTable() + local enum_tbl = {} + for k,v in pairs(base_tbl) do + if isnumber(v) then + enum_tbl[k] = k + end + end + return enum_tbl + end}}, callback = function(self, ent, name, num) ent = try_viewmodel(ent) - return self:NumberOperator(ent:GetNWInt(tostring(name), num)) + return self:NumberOperator(ent:GetNWInt(tostring(name)), tonumber(num)) end, }, get_networked_bool = { arguments = {{name = "string"}, {bool = "string"}}, + local base_tbl = LocalPlayer():GetNWVarTable() + local enum_tbl = {} + for k,v in pairs(base_tbl) do + if isbool(v) then + enum_tbl[k] = k + end + end + return enum_tbl + end}}, callback = function(self, ent, name, bool) ent = try_viewmodel(ent) return ent:GetNWBool(tostring(name)) == tobool(bool) @@ -809,9 +821,18 @@ PART.OldEvents = { get_networked_float = { arguments = {{name = "string"}, {float = "number"}}, + local base_tbl = LocalPlayer():GetNWVarTable() + local enum_tbl = {} + for k,v in pairs(base_tbl) do + if isnumber(v) then + enum_tbl[k] = k + end + end + return enum_tbl + end}}, callback = function(self, ent, name, float) ent = try_viewmodel(ent) - return self:NumberOperator(ent:GetNWFloat(tostring(name), float)) + return self:NumberOperator(ent:GetNWFloat(tostring(name)), tonumber(float)) end, }, From 3f5676a02e99a680e5f983c467b1b97aab741d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=8Ckami=20Adam=20Sila=20Kann?= <17802255+WolfKann@users.noreply.github.com> Date: Sat, 6 Apr 2024 03:35:56 -0400 Subject: [PATCH 3/7] Update event.lua Forgot Userdata prefix --- lua/pac3/core/client/parts/event.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/pac3/core/client/parts/event.lua b/lua/pac3/core/client/parts/event.lua index 155b53a02..884f9ef7f 100644 --- a/lua/pac3/core/client/parts/event.lua +++ b/lua/pac3/core/client/parts/event.lua @@ -804,6 +804,7 @@ PART.OldEvents = { get_networked_bool = { arguments = {{name = "string"}, {bool = "string"}}, + userdata = {{enums = function() local base_tbl = LocalPlayer():GetNWVarTable() local enum_tbl = {} for k,v in pairs(base_tbl) do @@ -821,6 +822,7 @@ PART.OldEvents = { get_networked_float = { arguments = {{name = "string"}, {float = "number"}}, + userdata = {{enums = function() local base_tbl = LocalPlayer():GetNWVarTable() local enum_tbl = {} for k,v in pairs(base_tbl) do From 946d82c86f978df4a5a8af4b981e5000ab87926c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=8Ckami=20Adam=20Sila=20Kann?= <17802255+WolfKann@users.noreply.github.com> Date: Sat, 6 Apr 2024 03:41:10 -0400 Subject: [PATCH 4/7] Update event.lua fixed StringOperator (I really need to proof read better, but it's 3:40 AM and I haven't slept yet.) --- lua/pac3/core/client/parts/event.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/pac3/core/client/parts/event.lua b/lua/pac3/core/client/parts/event.lua index 884f9ef7f..fbe73ab7d 100644 --- a/lua/pac3/core/client/parts/event.lua +++ b/lua/pac3/core/client/parts/event.lua @@ -780,7 +780,7 @@ PART.OldEvents = { end}}, callback = function(self, ent, name, result) ent = try_viewmodel(ent) - return StringOperator(ent:GetNWString(tostring(name)), tostring(result)) + return self:StringOperator(ent:GetNWString(tostring(name)), tostring(result)) end, }, From e26d73152cc1af54fadfb87428faa045a957cc35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=8Ckami=20Adam=20Sila=20Kann?= <17802255+WolfKann@users.noreply.github.com> Date: Sat, 6 Apr 2024 18:32:55 -0400 Subject: [PATCH 5/7] Update event.lua Changed // to -- --- lua/pac3/core/client/parts/event.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lua/pac3/core/client/parts/event.lua b/lua/pac3/core/client/parts/event.lua index fbe73ab7d..2ac7dd522 100644 --- a/lua/pac3/core/client/parts/event.lua +++ b/lua/pac3/core/client/parts/event.lua @@ -739,9 +739,9 @@ PART.OldEvents = { }, - // This is a function to grab any and all network variables and try to run them with the correct type, as it's possible to have GetNWInt("Pac", 1) and "GetNWString("Pac" ValueHere") - // This code is designed to try and run things correctly and detect specific types of Network Variables, Since GetNWVar does not have the varable display in the table, but GetNW2var does. - // It's also useful if a player doesn't know what the displayed function is as a Networked Variable. + -- This is a function to grab any and all network variables and try to run them with the correct type, as it's possible to have GetNWInt("Pac", 1) and "GetNWString("Pac" ValueHere") + -- This code is designed to try and run things correctly and detect specific types of Network Variables, Since GetNWVar does not have the varable display in the table, but GetNW2var does. + -- It's also useful if a player doesn't know what the displayed function is as a Networked Variable. get_networked = { arguments = {{name = "string"}, {result = "string"}}, @@ -763,8 +763,8 @@ PART.OldEvents = { end, }, - //These are left in so that if a player knows what a variable is as a network, they can manually and directly get it - //In the rare event the operation above has two of the same named variabels (which is rare and stupid, but can happen, so it's better to nip it in the butt instead of trying to argue over it.) + -- These are left in so that if a player knows what a variable is as a network, they can manually and directly get it + -- Only for the rare event the operation above has two of the same named variabels, or is using only numbers, or bools (which is rare and stupid, but can happen, so it's better to nip it in the butt instead of trying to argue over it.) get_networked_string = { arguments = {{name = "string"}, {result = "string"}}, From b84b83ec4bd367d2063a0400e399a3bb3eb596d7 Mon Sep 17 00:00:00 2001 From: pingu7867 Date: Sun, 7 Apr 2024 14:09:02 -0400 Subject: [PATCH 6/7] move NW var events to separate table subject to convar also fix main get_networked enum builder to provide key-key pairs instead of key-values. the name list should give keys. the value is tested in result --- lua/pac3/core/client/parts/event.lua | 247 ++++++++++++++++----------- 1 file changed, 144 insertions(+), 103 deletions(-) diff --git a/lua/pac3/core/client/parts/event.lua b/lua/pac3/core/client/parts/event.lua index 2ac7dd522..1f3daa1bb 100644 --- a/lua/pac3/core/client/parts/event.lua +++ b/lua/pac3/core/client/parts/event.lua @@ -723,14 +723,13 @@ PART.OldEvents = { end, }, - is_no_draw = { callback = function(self, ent) ent = try_viewmodel(ent) return ent:GetNoDraw() end, }, - + is_no_target = { callback = function(self, ent) ent = try_viewmodel(ent) @@ -738,107 +737,6 @@ PART.OldEvents = { end, }, - - -- This is a function to grab any and all network variables and try to run them with the correct type, as it's possible to have GetNWInt("Pac", 1) and "GetNWString("Pac" ValueHere") - -- This code is designed to try and run things correctly and detect specific types of Network Variables, Since GetNWVar does not have the varable display in the table, but GetNW2var does. - -- It's also useful if a player doesn't know what the displayed function is as a Networked Variable. - - get_networked = { - arguments = {{name = "string"}, {result = "string"}}, - userdata = {{enums = function() - return LocalPlayer():GetNWVarTable() - end}}, - - callback = function(self, ent, name, result) - ent = try_viewmodel(ent) - local anyvar = ent:GetNWVarTable()[name] - - if isstring(anyvar) then - return self:StringOperator(anyvar, result) - elseif isnumber(anyvar) then - return self:NumberOperator(anyvar, tonumber(result) or 0) - elseif isbool(anyvar) then - return anyvar == tobool(result) - end - end, - }, - - -- These are left in so that if a player knows what a variable is as a network, they can manually and directly get it - -- Only for the rare event the operation above has two of the same named variabels, or is using only numbers, or bools (which is rare and stupid, but can happen, so it's better to nip it in the butt instead of trying to argue over it.) - - get_networked_string = { - arguments = {{name = "string"}, {result = "string"}}, - userdata = {{enums = function() - local base_tbl = LocalPlayer():GetNWVarTable() - local enum_tbl = {} - for k,v in pairs(base_tbl) do - if isstring(v) then - enum_tbl[k] = k - end - end - return enum_tbl - end}}, - callback = function(self, ent, name, result) - ent = try_viewmodel(ent) - return self:StringOperator(ent:GetNWString(tostring(name)), tostring(result)) - end, - }, - - get_networked_int = { - arguments = {{name = "string"}, {num = "number"}}, - userdata = {{enums = function() - local base_tbl = LocalPlayer():GetNWVarTable() - local enum_tbl = {} - for k,v in pairs(base_tbl) do - if isnumber(v) then - enum_tbl[k] = k - end - end - return enum_tbl - end}}, - callback = function(self, ent, name, num) - ent = try_viewmodel(ent) - return self:NumberOperator(ent:GetNWInt(tostring(name)), tonumber(num)) - end, - }, - - get_networked_bool = { - arguments = {{name = "string"}, {bool = "string"}}, - userdata = {{enums = function() - local base_tbl = LocalPlayer():GetNWVarTable() - local enum_tbl = {} - for k,v in pairs(base_tbl) do - if isbool(v) then - enum_tbl[k] = k - end - end - return enum_tbl - end}}, - callback = function(self, ent, name, bool) - ent = try_viewmodel(ent) - return ent:GetNWBool(tostring(name)) == tobool(bool) - end, - }, - - get_networked_float = { - arguments = {{name = "string"}, {float = "number"}}, - userdata = {{enums = function() - local base_tbl = LocalPlayer():GetNWVarTable() - local enum_tbl = {} - for k,v in pairs(base_tbl) do - if isnumber(v) then - enum_tbl[k] = k - end - end - return enum_tbl - end}}, - callback = function(self, ent, name, float) - ent = try_viewmodel(ent) - return self:NumberOperator(ent:GetNWFloat(tostring(name)), tonumber(float)) - end, - }, - - client_spawned = { operator_type = "number", preferred_operator = "below", tutorial_explanation = "client_spawned supposedly activates for some time after you spawn", @@ -3047,6 +2945,149 @@ do end end +--spicy events +do + + local spicy_events = { + + -- This is a function to grab any and all network variables and try to run them with the correct type, as it's possible to have GetNWInt("Pac", 1) and "GetNWString("Pac" ValueHere") + -- This code is designed to try and run things correctly and detect specific types of Network Variables, Since GetNWVar does not have the varable display in the table, but GetNW2var does. + -- It's also useful if a player doesn't know what the displayed function is as a Networked Variable. + + get_networked = { + arguments = {{name = "string"}, {result = "string"}}, + userdata = {{enums = function() + local base_tbl = LocalPlayer():GetNWVarTable() + local enum_tbl = {} + for k,v in pairs(base_tbl) do + enum_tbl[k] = k + end + return enum_tbl + end}}, + + callback = function(self, ent, name, result) + print(ent) + ent = try_viewmodel(ent) + print(ent) + local anyvar = ent:GetNWVarTable()[name] + + if isstring(anyvar) then + return self:StringOperator(anyvar, result) + elseif isnumber(anyvar) then + return self:NumberOperator(anyvar, tonumber(result) or 0) + elseif isbool(anyvar) then + return anyvar == tobool(result) + end + end, + }, + --These are left in so that if a player knows what a variable is as a network, they can manually and directly get it + --In the rare event the operation above has two of the same named variabels (which is rare and stupid, but can happen, so it's better to nip it in the butt instead of trying to argue over it.) + + get_networked_string = { + arguments = {{name = "string"}, {result = "string"}}, + userdata = {{enums = function() + local base_tbl = LocalPlayer():GetNWVarTable() + local enum_tbl = {} + for k,v in pairs(base_tbl) do + if isstring(v) then + enum_tbl[k] = k + end + end + return enum_tbl + end}}, + callback = function(self, ent, name, result) + ent = try_viewmodel(ent) + return self:StringOperator(ent:GetNWString(tostring(name)), tostring(result)) + end, + }, + + get_networked_int = { + arguments = {{name = "string"}, {num = "number"}}, + userdata = {{enums = function() + local base_tbl = LocalPlayer():GetNWVarTable() + local enum_tbl = {} + for k,v in pairs(base_tbl) do + if isnumber(v) then + enum_tbl[k] = k + end + end + return enum_tbl + end}}, + callback = function(self, ent, name, num) + ent = try_viewmodel(ent) + return self:NumberOperator(ent:GetNWInt(tostring(name)), tonumber(num)) + end, + }, + + get_networked_bool = { + arguments = {{name = "string"}, {bool = "string"}}, + userdata = {{enums = function() + local base_tbl = LocalPlayer():GetNWVarTable() + local enum_tbl = {} + for k,v in pairs(base_tbl) do + if isbool(v) then + enum_tbl[k] = k + end + end + return enum_tbl + end}}, + callback = function(self, ent, name, bool) + ent = try_viewmodel(ent) + return ent:GetNWBool(tostring(name)) == tobool(bool) + end, + }, + + get_networked_float = { + arguments = {{name = "string"}, {float = "number"}}, + userdata = {{enums = function() + local base_tbl = LocalPlayer():GetNWVarTable() + local enum_tbl = {} + for k,v in pairs(base_tbl) do + if isnumber(v) then + enum_tbl[k] = k + end + end + return enum_tbl + end}}, + callback = function(self, ent, name, float) + ent = try_viewmodel(ent) + return self:NumberOperator(ent:GetNWFloat(tostring(name)), tonumber(float)) + end, + }, + } + + if GetConVar("pac_sv_danger_mode"):GetBool() then + for classname, data in pairs(spicy_events) do + local arguments = data.arguments + local think = data.callback + local eventObject = pac.CreateEvent(classname) + + if arguments then + for i, data2 in ipairs(arguments) do + local key, Type = next(data2) + eventObject:AppendArgument(key, Type, data.userdata and data.userdata[i] or nil) + end + end + + eventObject.extra_nice_name = data.nice + + local operator_type = data.operator_type + local preferred_operator = data.preferred_operator + local tutorial_explanation = data.tutorial_explanation + eventObject.operator_type = operator_type + eventObject.preferred_operator = preferred_operator + eventObject.tutorial_explanation = tutorial_explanation + + function eventObject:Think(event, ent, ...) + return think(event, ent, ...) + end + + pac.RegisterEvent(eventObject) + end + end + +end + function PART:GetParentEx() local parent = self:GetTargetPart() From fc5ea62e5603be0514c68efde2ae10a26b3de098 Mon Sep 17 00:00:00 2001 From: pingu7867 Date: Sun, 7 Apr 2024 14:13:24 -0400 Subject: [PATCH 7/7] add pac_sv_danger_mode convar for minor features that can be construed as having an impact on gameplay when implementing these controls, expand the list as needed instead of making ultraspecific convars --- lua/pac3/core/server/event.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lua/pac3/core/server/event.lua b/lua/pac3/core/server/event.lua index ba156128a..fd739c85c 100644 --- a/lua/pac3/core/server/event.lua +++ b/lua/pac3/core/server/event.lua @@ -3,6 +3,13 @@ util.AddNetworkString("pac_proxy") util.AddNetworkString("pac_event") util.AddNetworkString("pac_event_set_sequence") +local master_default = "0" + +if string.find(engine.ActiveGamemode(), "sandbox") and game.SinglePlayer() then + master_default = "1" +end +CreateConVar("pac_sv_danger_mode", master_default, {FCVAR_ARCHIVE, FCVAR_REPLICATED, FCVAR_NOTIFY}, "Enables the following features (provisory list):\nget NW var events\nnearest_life aimparts and bones") + net.Receive("pac_event_set_sequence", function(len, ply) local event = net.ReadString() local num = net.ReadUInt(8)