From c4bc255cc3c4c39daf0a4add1ce43eabb503851a Mon Sep 17 00:00:00 2001 From: shadow7483147 Date: Tue, 27 Aug 2019 08:43:09 -0500 Subject: [PATCH 01/11] Sun functions Adds functions for finding the sun's vector direction, the env_sun entity itself and the ability to retrieve the keyvalue table of an entity. Kinda doing this blind because I can't figure out how to add custom functions to the workshop version without creating a new extension entirely. --- .../gmod_wire_expression2/core/entity.lua | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lua/entities/gmod_wire_expression2/core/entity.lua b/lua/entities/gmod_wire_expression2/core/entity.lua index 72764e0fd5..7408ec0c0c 100644 --- a/lua/entities/gmod_wire_expression2/core/entity.lua +++ b/lua/entities/gmod_wire_expression2/core/entity.lua @@ -125,6 +125,19 @@ e2function entity entity:owner() return getOwner(self, this) end +e2function table entity:keyvalues() + if not IsValid(this) then return nil end + return this:GetKeyValues() +end + +__e2setcost(50) -- taken from find functions + +e2function entity sun() + return ents.FindByClass( "env_sun" )[1] or nil +end + +__e2setcost(5) -- temporary + /******************************************************************************/ // Functions getting vector e2function vector entity:pos() @@ -171,6 +184,15 @@ e2function vector entity:angVelVector() return phys:GetAngleVelocity() end +__e2setcost(50) -- taken from find functions + +--- Specific to env_sun because Source is dum. Use this to trace towards the sun or something. +e2function vector sunDirection() + local sun = ents.FindByClass( "env_sun" )[1] + local sundir = sun:GetKeyValues()["sun_dir"] + return { sundir[1] , sundir[2], sundir[3] } +end + /******************************************************************************/ // Functions using vector getting vector From 3ecae1877b99da0bfd5732fd51ec4930868b7890 Mon Sep 17 00:00:00 2001 From: shadow7483147 Date: Tue, 27 Aug 2019 08:52:10 -0500 Subject: [PATCH 02/11] Update e2descriptions.lua --- lua/wire/client/e2descriptions.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index 776a1df5c7..a64b5f782d 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -179,8 +179,11 @@ E2Helper.Descriptions["owner()"] = "Gets the owner of the expression ( same as e E2Helper.Descriptions["id(e:)"] = "Gets the numeric id of an entity" E2Helper.Descriptions["noentity()"] = "Returns an invalid entity" E2Helper.Descriptions["world()"] = "Returns the world entity" +E2Helper.Descriptions["sun()"] = "Returns the world's env_sun entity" +E2Helper.Descriptions["sunDirection()"] = "Returns the vector direction that points towards the sun" E2Helper.Descriptions["type(e:)"] = "Gets the class of an entity" E2Helper.Descriptions["model(e:)"] = "Gets the model of an entity" +E2Helper.Descriptions["keyvalues(e:)"] = "Returns the keyvalue table of an entity" E2Helper.Descriptions["owner(e:)"] = "Gets the owner of an entity" E2Helper.Descriptions["name(e:)"] = "Gets the name of a player" E2Helper.Descriptions["steamID(e:)"] = "Gets the steam ID of the player" From ad481ff566c57d06555ee3b4f7f5a2b5437ecc43 Mon Sep 17 00:00:00 2001 From: shadow7483147 Date: Tue, 27 Aug 2019 09:16:00 -0500 Subject: [PATCH 03/11] Update entity.lua --- lua/entities/gmod_wire_expression2/core/entity.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/entity.lua b/lua/entities/gmod_wire_expression2/core/entity.lua index 7408ec0c0c..8b1d1094a0 100644 --- a/lua/entities/gmod_wire_expression2/core/entity.lua +++ b/lua/entities/gmod_wire_expression2/core/entity.lua @@ -125,11 +125,6 @@ e2function entity entity:owner() return getOwner(self, this) end -e2function table entity:keyvalues() - if not IsValid(this) then return nil end - return this:GetKeyValues() -end - __e2setcost(50) -- taken from find functions e2function entity sun() From 072a7f90d4ac3780f6a5cc71d6acd46fd6623e2e Mon Sep 17 00:00:00 2001 From: shadow7483147 Date: Tue, 27 Aug 2019 09:16:34 -0500 Subject: [PATCH 04/11] Update e2descriptions.lua --- lua/wire/client/e2descriptions.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index a64b5f782d..07f2434920 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -183,7 +183,6 @@ E2Helper.Descriptions["sun()"] = "Returns the world's env_sun entity" E2Helper.Descriptions["sunDirection()"] = "Returns the vector direction that points towards the sun" E2Helper.Descriptions["type(e:)"] = "Gets the class of an entity" E2Helper.Descriptions["model(e:)"] = "Gets the model of an entity" -E2Helper.Descriptions["keyvalues(e:)"] = "Returns the keyvalue table of an entity" E2Helper.Descriptions["owner(e:)"] = "Gets the owner of an entity" E2Helper.Descriptions["name(e:)"] = "Gets the name of a player" E2Helper.Descriptions["steamID(e:)"] = "Gets the steam ID of the player" From ab10ba02704397d3b39f1d0b3529ecbfc8365f7b Mon Sep 17 00:00:00 2001 From: shadow7483147 Date: Tue, 27 Aug 2019 13:11:29 -0500 Subject: [PATCH 05/11] Fixed E:keyvalues(), removed sun() --- .../gmod_wire_expression2/core/entity.lua | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/entity.lua b/lua/entities/gmod_wire_expression2/core/entity.lua index 7408ec0c0c..c94c8fc160 100644 --- a/lua/entities/gmod_wire_expression2/core/entity.lua +++ b/lua/entities/gmod_wire_expression2/core/entity.lua @@ -22,6 +22,8 @@ local validPhysics = E2Lib.validPhysics local getOwner = E2Lib.getOwner local isOwner = E2Lib.isOwner +local sun = ents.FindByClass( "env_sun" )[1] + registerCallback("e2lib_replace_function", function(funcname, func, oldfunc) if funcname == "isOwner" then isOwner = func @@ -125,15 +127,20 @@ e2function entity entity:owner() return getOwner(self, this) end +__e2setcost(20) + e2function table entity:keyvalues() if not IsValid(this) then return nil end - return this:GetKeyValues() -end - -__e2setcost(50) -- taken from find functions - -e2function entity sun() - return ents.FindByClass( "env_sun" )[1] or nil + local keyvalues = this:GetKeyValues() + local ret = {n={},ntypes={},s={},stypes={},size=0} -- default table + local size = 0 + for k,v in pairs( keyvalues ) do + size = size + 1 + ret.s[k] = v + ret.stypes[k] = string.lower(type(v)[1]) -- i swear there's a more elegant solution to this but whatever. + end + ret.size = size + return ret end __e2setcost(5) -- temporary @@ -188,9 +195,7 @@ __e2setcost(50) -- taken from find functions --- Specific to env_sun because Source is dum. Use this to trace towards the sun or something. e2function vector sunDirection() - local sun = ents.FindByClass( "env_sun" )[1] - local sundir = sun:GetKeyValues()["sun_dir"] - return { sundir[1] , sundir[2], sundir[3] } + return sun:GetKeyValues()["sun_dir"] end /******************************************************************************/ From c6e1d25adb8becd3726573850e8614f44461fd74 Mon Sep 17 00:00:00 2001 From: shadow7483147 Date: Tue, 27 Aug 2019 13:14:59 -0500 Subject: [PATCH 06/11] Update entity.lua --- lua/entities/gmod_wire_expression2/core/entity.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/entity.lua b/lua/entities/gmod_wire_expression2/core/entity.lua index c94c8fc160..cb296558bf 100644 --- a/lua/entities/gmod_wire_expression2/core/entity.lua +++ b/lua/entities/gmod_wire_expression2/core/entity.lua @@ -191,8 +191,6 @@ e2function vector entity:angVelVector() return phys:GetAngleVelocity() end -__e2setcost(50) -- taken from find functions - --- Specific to env_sun because Source is dum. Use this to trace towards the sun or something. e2function vector sunDirection() return sun:GetKeyValues()["sun_dir"] From be77905858ae0d8b1a9d494f906aaa7de80ddd0c Mon Sep 17 00:00:00 2001 From: shadow7483147 Date: Tue, 27 Aug 2019 13:15:58 -0500 Subject: [PATCH 07/11] Update e2descriptions.lua --- lua/wire/client/e2descriptions.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index a64b5f782d..5f3b634e5f 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -179,7 +179,6 @@ E2Helper.Descriptions["owner()"] = "Gets the owner of the expression ( same as e E2Helper.Descriptions["id(e:)"] = "Gets the numeric id of an entity" E2Helper.Descriptions["noentity()"] = "Returns an invalid entity" E2Helper.Descriptions["world()"] = "Returns the world entity" -E2Helper.Descriptions["sun()"] = "Returns the world's env_sun entity" E2Helper.Descriptions["sunDirection()"] = "Returns the vector direction that points towards the sun" E2Helper.Descriptions["type(e:)"] = "Gets the class of an entity" E2Helper.Descriptions["model(e:)"] = "Gets the model of an entity" From 29b75eba71fad8e489513cde00b4b3af30fe6b95 Mon Sep 17 00:00:00 2001 From: shadow7483147 Date: Tue, 27 Aug 2019 13:23:17 -0500 Subject: [PATCH 08/11] checks if sun entity exists --- lua/entities/gmod_wire_expression2/core/entity.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/entities/gmod_wire_expression2/core/entity.lua b/lua/entities/gmod_wire_expression2/core/entity.lua index cb296558bf..1678daeb94 100644 --- a/lua/entities/gmod_wire_expression2/core/entity.lua +++ b/lua/entities/gmod_wire_expression2/core/entity.lua @@ -193,6 +193,7 @@ end --- Specific to env_sun because Source is dum. Use this to trace towards the sun or something. e2function vector sunDirection() + if not isValid(sun) then return { 0, 0, 0 } end return sun:GetKeyValues()["sun_dir"] end From 80346089bf7b78a7756a96e90eed6bf74d6be892 Mon Sep 17 00:00:00 2001 From: shadow7483147 Date: Tue, 27 Aug 2019 13:40:24 -0500 Subject: [PATCH 09/11] moronically returning nil as a table fixed --- lua/entities/gmod_wire_expression2/core/entity.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/entity.lua b/lua/entities/gmod_wire_expression2/core/entity.lua index 1678daeb94..21d3809e11 100644 --- a/lua/entities/gmod_wire_expression2/core/entity.lua +++ b/lua/entities/gmod_wire_expression2/core/entity.lua @@ -130,9 +130,9 @@ end __e2setcost(20) e2function table entity:keyvalues() - if not IsValid(this) then return nil end - local keyvalues = this:GetKeyValues() local ret = {n={},ntypes={},s={},stypes={},size=0} -- default table + if not IsValid(this) then return ret end + local keyvalues = this:GetKeyValues() local size = 0 for k,v in pairs( keyvalues ) do size = size + 1 From 4601f5ff53932b43c24c16a6ebeac212c31a795d Mon Sep 17 00:00:00 2001 From: shadow7483147 Date: Tue, 27 Aug 2019 14:05:10 -0500 Subject: [PATCH 10/11] readded keyvalues to the e2 descriptions for real this time --- lua/wire/client/e2descriptions.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index 95002975ce..5f3b634e5f 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -182,6 +182,7 @@ E2Helper.Descriptions["world()"] = "Returns the world entity" E2Helper.Descriptions["sunDirection()"] = "Returns the vector direction that points towards the sun" E2Helper.Descriptions["type(e:)"] = "Gets the class of an entity" E2Helper.Descriptions["model(e:)"] = "Gets the model of an entity" +E2Helper.Descriptions["keyvalues(e:)"] = "Returns the keyvalue table of an entity" E2Helper.Descriptions["owner(e:)"] = "Gets the owner of an entity" E2Helper.Descriptions["name(e:)"] = "Gets the name of a player" E2Helper.Descriptions["steamID(e:)"] = "Gets the steam ID of the player" From 277ca0a44c2aa59ad96c71360b98c2f8c65fa407 Mon Sep 17 00:00:00 2001 From: shadow7483147 Date: Tue, 27 Aug 2019 15:47:21 -0500 Subject: [PATCH 11/11] Update entity.lua --- lua/entities/gmod_wire_expression2/core/entity.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/entity.lua b/lua/entities/gmod_wire_expression2/core/entity.lua index 21d3809e11..bb9704328f 100644 --- a/lua/entities/gmod_wire_expression2/core/entity.lua +++ b/lua/entities/gmod_wire_expression2/core/entity.lua @@ -22,7 +22,14 @@ local validPhysics = E2Lib.validPhysics local getOwner = E2Lib.getOwner local isOwner = E2Lib.isOwner -local sun = ents.FindByClass( "env_sun" )[1] +local sun = ents.FindByClass("env_sun")[1] -- used for sunDirection() + +hook.Add("InitPostEntity","sunent",function() + sun = ents.FindByClass("env_sun")[1] + timer.Simple(0,function() -- make sure we have a sun first + hook.Remove("InitPostEntity","sunent") + end ) -- then remove this. we don't need it anymore. +end ) registerCallback("e2lib_replace_function", function(funcname, func, oldfunc) if funcname == "isOwner" then @@ -194,7 +201,7 @@ end --- Specific to env_sun because Source is dum. Use this to trace towards the sun or something. e2function vector sunDirection() if not isValid(sun) then return { 0, 0, 0 } end - return sun:GetKeyValues()["sun_dir"] + return sun:GetKeyValues().sun_dir end /******************************************************************************/