From b2d0287e47b66270312590ac09e8ef4fab63582b Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Thu, 13 Nov 2025 17:48:02 +0300 Subject: [PATCH 01/13] First entities NULL fixes (stopped at HoloEntity) --- .../core/egpfunctions.lua | 20 ++++++------ .../gmod_wire_expression2/core/entity.lua | 7 ++--- .../gmod_wire_expression2/core/find.lua | 22 ++++++------- .../gmod_wire_expression2/core/hologram.lua | 31 ++++++++++--------- .../gmod_wire_expression2/core/ranger.lua | 2 +- .../gmod_wire_expression2/core/wirelink.lua | 2 +- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/egpfunctions.lua b/lua/entities/gmod_wire_expression2/core/egpfunctions.lua index 82e61c55ae..4d3ebb59f0 100644 --- a/lua/entities/gmod_wire_expression2/core/egpfunctions.lua +++ b/lua/entities/gmod_wire_expression2/core/egpfunctions.lua @@ -128,7 +128,7 @@ e2function egpobject wirelink:egpBox( number index, vector2 pos, vector2 size ) if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end local bool, obj = egp_create("Box", { index = index, w = size[1], h = size[2], x = pos[1], y = pos[2] }, this) if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end - return obj + return obj end -------------------------------------------------------- @@ -258,7 +258,7 @@ local function canCreateFont( ply, font, size ) size = size or 18 EGP.PlayerFontCount[ply:SteamID64()] = EGP.PlayerFontCount[ply:SteamID64()] or { fonts = {}, count = 0 } - local fontTable = EGP.PlayerFontCount[ply:SteamID64()] + local fontTable = EGP.PlayerFontCount[ply:SteamID64()] if fontTable.count >= 50 then return false end @@ -779,10 +779,14 @@ e2function void wirelink:egpParent( number index, entity parent ) end -- Returns the entity a tracker is parented to -e2function entity wirelink:egpTrackerParent( number index ) +e2function entity wirelink:egpTrackerParent(number index) local bool, k, v = hasObject(this, index) + if bool and v.NeedsConstantUpdate then - return (v.parententity and v.parententity:IsValid()) and v.parententity or nil + local parent = v.parententity + return IsValid(parent) and parent or NULL + else + return NULL end end @@ -1309,9 +1313,7 @@ end -- Returns the screen which the queue finished sending items for e2function entity egpQueueScreen() - if (EGP.RunByEGPQueue) then - return EGP.RunByEGPQueue_Ent - end + return EGP.RunByEGPQueue and EGP.RunByEGPQueue_Ent or NULL end -- Same as above, except returns wirelink @@ -1323,9 +1325,7 @@ end -- Returns the player which ordered the current items to be sent (This is usually yourself, but if you're sharing pp with someone it might be them. Good way to check if someone is fucking with your screens) e2function entity egpQueuePlayer() - if (EGP.RunByEGPQueue) then - return EGP.RunByEGPQueue_ply - end + return EGP.RunByEGPQueue and EGP.RunByEGPQueue_ply or NULL end -- Returns 1 if the current execution was caused by the EGP queue system and the player was the player whom ordered the item to be sent (This is usually yourself, but if you're sharing pp with someone it might be them.) diff --git a/lua/entities/gmod_wire_expression2/core/entity.lua b/lua/entities/gmod_wire_expression2/core/entity.lua index d5cf2b8632..2568208403 100644 --- a/lua/entities/gmod_wire_expression2/core/entity.lua +++ b/lua/entities/gmod_wire_expression2/core/entity.lua @@ -69,8 +69,7 @@ end --[[******************************************************************************]] e2function entity entity(id) - local ent = ents.GetByIndex(id) - return IsValid(ent) and ent or nil + return ents.GetByIndex(id) end e2function number entity:id() @@ -889,12 +888,12 @@ end) __e2setcost(5) e2function entity entity:driver() - if not IsValid(this) or not this:IsVehicle() then return self:throw("Invalid vehicle!", nil) end + if not IsValid(this) or not this:IsVehicle() then return self:throw("Invalid vehicle!", NULL) end return this:GetDriver() end e2function entity entity:passenger() - if not IsValid(this) or not this:IsVehicle() then return self:throw("Invalid vehicle!", nil) end + if not IsValid(this) or not this:IsVehicle() then return self:throw("Invalid vehicle!", NULL) end return this:GetPassenger(0) end diff --git a/lua/entities/gmod_wire_expression2/core/find.lua b/lua/entities/gmod_wire_expression2/core/find.lua index 8a2eddcd45..49776fd523 100644 --- a/lua/entities/gmod_wire_expression2/core/find.lua +++ b/lua/entities/gmod_wire_expression2/core/find.lua @@ -452,8 +452,8 @@ end --- Returns the player with the given name, this is an exception to the rule [nodiscard] e2function entity findPlayerByName(string name) - if query_blocked(self, 1) then return nil end - return findPlayer(name) + if query_blocked(self, 1) then return NULL end + return findPlayer(name) or NULL end --- Returns the player with the given SteamID @@ -519,7 +519,7 @@ end --- Exclude entities with this model (or partial model name) from future finds e2function void findExcludeModel(string model) - if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", nil) end + if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", nil) end self.data.find.bl_model[string.lower(model)] = true invalidate_filters(self) end @@ -800,26 +800,26 @@ end --- Returns the indexed entity from the previous find event (valid parameters are 1 to the number of entities found) [nodiscard] e2function entity findResult(index) - return self.data.findlist[index] + return self.data.findlist[index] or NULL end --- Returns the closest entity to the given point from the previous find event [nodiscard] e2function entity findClosest(vector position) - local closest = nil - local dist = math.huge + local closest, dist = NULL, math.huge self.prf = self.prf + #self.data.findlist * 10 - for _,ent in pairs(self.data.findlist) do + + for _, ent in pairs(self.data.findlist) do if IsValid(ent) then - local pos = ent:GetPos() - local xd, yd, zd = pos.x-position[1], pos.y-position[2], pos.z-position[3] - local curdist = xd*xd + yd*yd + zd*zd + local curdist = ent:GetPos():Distance(position) + if curdist < dist then closest = ent dist = curdist end end end + return closest end @@ -837,7 +837,7 @@ end --- Equivalent to findResult(1) [nodiscard] e2function entity find() - return self.data.findlist[1] + return self.data.findlist[1] or NULL end --[[************************************************************************]]-- diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index 685f07bc7e..fc95632f2a 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -594,7 +594,7 @@ local function CreateHolo(self, index, pos, scale, ang, color, model) end, self, index ) end - if not IsValid(prop) then return nil end + if not IsValid(prop) then return NULL end if color then WireLib.SetColor(Holo.ent, Color(color[1],color[2],color[3],color[4] or 255)) end @@ -664,7 +664,7 @@ end local function checkHoloCount(self) if PlayerAmount[self.uid] >= wire_holograms_max:GetInt() then - return self:throw("You've hit the maximum amount of holograms!", true) + return self:throw("You've hit the maximum amount of holograms!", NULL) end end @@ -718,8 +718,8 @@ e2function entity holoCreate(index, vector position, vector scale, angle ang, ve position = Vector(position[1], position[2], position[3]) ang = Angle(ang[1], ang[2], ang[3]) - local ret = CreateHolo(self, index, position, scale, ang, color) - if IsValid(ret) then return ret end + + return CreateHolo(self, index, position, scale, ang, color) end e2function entity holoCreate(index, vector position, vector scale, angle ang) @@ -728,10 +728,7 @@ e2function entity holoCreate(index, vector position, vector scale, angle ang) local Holo = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end - position = Vector(position[1], position[2], position[3]) - ang = Angle(ang[1], ang[2], ang[3]) - local ret = CreateHolo(self, index, position, scale, ang) - if IsValid(ret) then return ret end + return CreateHolo(self, index, position, scale, ang) end e2function entity holoCreate(index, vector position, vector scale) @@ -741,8 +738,8 @@ e2function entity holoCreate(index, vector position, vector scale) if not Holo and checkHoloCount(self) then return end position = Vector(position[1],position[2],position[3]) - local ret = CreateHolo(self, index, position, scale) - if IsValid(ret) then return ret end + + return CreateHolo(self, index, position, scale) end e2function entity holoCreate(index, vector position) @@ -752,8 +749,8 @@ e2function entity holoCreate(index, vector position) if not Holo and checkHoloCount(self) then return end position = Vector(position[1],position[2],position[3]) - local ret = CreateHolo(self, index, position) - if IsValid(ret) then return ret end + + return CreateHolo(self, index, position) end e2function entity holoCreate(index) @@ -762,8 +759,7 @@ e2function entity holoCreate(index) local Holo = CheckIndex(self, index, true) if not Holo and PlayerAmount[self.uid] >= wire_holograms_max:GetInt() then return end - local ret = CreateHolo(self, index) - if IsValid(ret) then return ret end + return CreateHolo(self, index) end __e2setcost(20) @@ -1328,7 +1324,12 @@ end __e2setcost(2) e2function entity holoEntity(index) local Holo = CheckIndex(self, index) - if Holo and IsValid(Holo.ent) then return Holo.ent end + + if Holo and Holo.ent then + return Holo.ent + else + return NULL + end end __e2setcost(30) diff --git a/lua/entities/gmod_wire_expression2/core/ranger.lua b/lua/entities/gmod_wire_expression2/core/ranger.lua index 451c94917a..527bce4a29 100644 --- a/lua/entities/gmod_wire_expression2/core/ranger.lua +++ b/lua/entities/gmod_wire_expression2/core/ranger.lua @@ -389,7 +389,7 @@ end --- Returns the entity of the input ranger data trace IF it hit an entity, else returns nil e2function entity ranger:entity() - if not this then return self:throw("Invalid ranger!", nil) end + if not this then return self:throw("Invalid ranger!", NULL) end return this.Entity end diff --git a/lua/entities/gmod_wire_expression2/core/wirelink.lua b/lua/entities/gmod_wire_expression2/core/wirelink.lua index 4dc41f4599..e24016ce3c 100644 --- a/lua/entities/gmod_wire_expression2/core/wirelink.lua +++ b/lua/entities/gmod_wire_expression2/core/wirelink.lua @@ -148,7 +148,7 @@ e2function number wirelink:isHiSpeed() end e2function entity wirelink:entity() - return this + return this or NULL end /******************************************************************************/ From e9eb04ea39ca6a9afa78b252c1da1e8a5e89c7f6 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 14 Nov 2025 15:52:35 +0300 Subject: [PATCH 02/13] Don't set entity default as nil (fixes gtable and array getters) --- lua/entities/gmod_wire_expression2/core/entity.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/entity.lua b/lua/entities/gmod_wire_expression2/core/entity.lua index 2568208403..3406443554 100644 --- a/lua/entities/gmod_wire_expression2/core/entity.lua +++ b/lua/entities/gmod_wire_expression2/core/entity.lua @@ -1,6 +1,6 @@ local wire_expression2_entity_trails_max = CreateConVar("wire_expression2_entity_trails_max", 30, FCVAR_ARCHIVE, "Max amount of trails a player can make. 0 - to disable trails. (Limit is shared between E2s of a player)", 0) -registerType("entity", "e", nil, +registerType("entity", "e", NULL, nil, function(self,output) return output or NULL end, nil, From bd6e0424493437edde0ef1c052a5a99f22ca3726 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 14 Nov 2025 16:31:39 +0300 Subject: [PATCH 03/13] Fix ioInputEntity return --- lua/entities/gmod_wire_expression2/core/selfaware.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/selfaware.lua b/lua/entities/gmod_wire_expression2/core/selfaware.lua index a4782e238d..0d3c3b0117 100644 --- a/lua/entities/gmod_wire_expression2/core/selfaware.lua +++ b/lua/entities/gmod_wire_expression2/core/selfaware.lua @@ -57,8 +57,14 @@ end -- Returns the entity the input is wired to [nodiscard] -e2function entity ioInputEntity( string input ) - if (self.entity.Inputs[input] and self.entity.Inputs[input].Src and IsValid(self.entity.Inputs[input].Src)) then return self.entity.Inputs[input].Src end +e2function entity ioInputEntity(string input) + local ioinput = self.entity.Inputs[input] + + if ioinput and ioinput.Src and IsValid(ioinput.Src) then + return ioinput.Src + else + return NULL + end end local fixDefault = E2Lib.fixDefault From 7df1cd9d8108044e14da44ee57eb2285597f5d27 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 14 Nov 2025 16:35:07 +0300 Subject: [PATCH 04/13] It looks like it was never supposed to return any entity --- lua/entities/gmod_wire_expression2/core/selfaware.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/selfaware.lua b/lua/entities/gmod_wire_expression2/core/selfaware.lua index 0d3c3b0117..0736c6163d 100644 --- a/lua/entities/gmod_wire_expression2/core/selfaware.lua +++ b/lua/entities/gmod_wire_expression2/core/selfaware.lua @@ -83,7 +83,7 @@ registerCallback("postinit",function() for k,v in pairs( wire_expression_types ) do local short = v[1] if not excluded_types[short] then - registerFunction("ioSetOutput","s"..short,""..short,function(self, args) + registerFunction("ioSetOutput","s"..short,"",function(self, args) local rv1, rv2 = args[1], args[2] if self.entity.Outputs[rv1] and self.entity.Outputs[rv1].Type == k then self.GlobalScope[rv1] = rv2 From 81ae76a617a4d3314b625243d04e84967b041a74 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 14 Nov 2025 16:42:58 +0300 Subject: [PATCH 05/13] Fix a bunch of functions isConstrainedTo(e:) isConstrainedTo(e:n) isConstrainedTo(e:s) isConstrainedTo(e:sn) isWeldedTo(e:) isWeldedTo(e:n) --- .../gmod_wire_expression2/core/constraint.lua | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/constraint.lua b/lua/entities/gmod_wire_expression2/core/constraint.lua index 995ff42041..9903c07c91 100644 --- a/lua/entities/gmod_wire_expression2/core/constraint.lua +++ b/lua/entities/gmod_wire_expression2/core/constraint.lua @@ -10,17 +10,6 @@ local function caps(text) return capstext end --- Returns con.Ent1 or con.Ent2, whichever is not equivalent to ent. Optionally subscripts con with num beforehand. -local function ent1or2(ent,con,num) - if not con then return nil end - if num then - con = con[num] - if not con then return nil end - end - if con.Ent1==ent then return con.Ent2 end - return con.Ent1 -end - --[[ -- buildFilters @@ -235,54 +224,65 @@ e2function number entity:isConstrained() return 1 end +-- Returns con.Ent1 or con.Ent2, whichever is not equivalent to ent. Optionally subscripts con with num beforehand. +local function ent1or2(ent, con, num) + if not con then return NULL end + + if num then + con = con[num] + if not con then return NULL end + end + + if con.Ent1 == ent then return con.Ent2 end + return con.Ent1 +end + --- Returns the first entity was welded to. e2function entity entity:isWeldedTo() - if not IsValid(this) then return self:throw("Invalid entity!", nil) end - if not constraint.HasConstraints(this) then return nil end + if not IsValid(this) then return self:throw("Invalid entity!", NULL) end + if not constraint.HasConstraints(this) then return NULL end - local filter = {Weld=true} -- create filter directly, no need to call buildFilter here, since it's static - return ent1or2(this,constraint_FindConstraint(this, filter)) + return ent1or2(this, constraint_FindConstraint(this, {Weld = true})) end --- Returns the th entity was welded to. e2function entity entity:isWeldedTo(index) - if not IsValid(this) then return self:throw("Invalid entity!", nil) end - if not constraint.HasConstraints(this) then return nil end + if not IsValid(this) then return self:throw("Invalid entity!", NULL) end + if not constraint.HasConstraints(this) then return NULL end - local filter = {Weld=true} -- create filter directly, no need to call buildFilter here, since it's static - return ent1or2(this,constraint_FindConstraints(this, filter), math.floor(index)) + return ent1or2(this, constraint_FindConstraints(this, {Weld = true}), math.floor(index)) end --- Returns the first entity was constrained to. e2function entity entity:isConstrainedTo() - if not IsValid(this) then return self:throw("Invalid entity!", nil) end - if not constraint.HasConstraints(this) then return nil end + if not IsValid(this) then return self:throw("Invalid entity!", NULL) end + if not constraint.HasConstraints(this) then return NULL end - return ent1or2(this,constraint_GetTable(this),1) + return ent1or2(this, constraint_GetTable(this), 1) end --- Returns the th entity was constrained to. e2function entity entity:isConstrainedTo(index) - if not IsValid(this) then return self:throw("Invalid entity!", nil) end - if not constraint.HasConstraints(this) then return nil end + if not IsValid(this) then return self:throw("Invalid entity!", NULL) end + if not constraint.HasConstraints(this) then return NULL end - return ent1or2(this,constraint_GetTable(this), math.floor(index)) + return ent1or2(this, constraint_GetTable(this), math.floor(index)) end --- Returns the first entity was constrained to with the given constraint type . e2function entity entity:isConstrainedTo(string constraintType) - if not IsValid(this) then return self:throw("Invalid entity!", nil) end - if not constraint.HasConstraints(this) then return nil end + if not IsValid(this) then return self:throw("Invalid entity!", NULL) end + if not constraint.HasConstraints(this) then return NULL end - return ent1or2(this,constraint_FindConstraint(this, buildFilter({constraintType}))) + return ent1or2(this, constraint_FindConstraint(this, buildFilter({constraintType}))) end --- Returns the th entity was constrained to with the given constraint type . e2function entity entity:isConstrainedTo(string constraintType, index) - if not IsValid(this) then return self:throw("Invalid entity!", nil) end - if not constraint.HasConstraints(this) then return nil end + if not IsValid(this) then return self:throw("Invalid entity!", NULL) end + if not constraint.HasConstraints(this) then return NULL end - return ent1or2(this,constraint_FindConstraints(this, buildFilter({constraintType})), math.floor(index)) + return ent1or2(this, constraint_FindConstraints(this, buildFilter({constraintType})), math.floor(index)) end --- Returns the '''entity''' is parented to. From fd153ea3c4b2a387ee36e30f1fae139f1fd06964 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 14 Nov 2025 16:48:22 +0300 Subject: [PATCH 06/13] More saveguard --- lua/entities/gmod_wire_expression2/core/constraint.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/constraint.lua b/lua/entities/gmod_wire_expression2/core/constraint.lua index 9903c07c91..1c4b85ad61 100644 --- a/lua/entities/gmod_wire_expression2/core/constraint.lua +++ b/lua/entities/gmod_wire_expression2/core/constraint.lua @@ -233,8 +233,10 @@ local function ent1or2(ent, con, num) if not con then return NULL end end - if con.Ent1 == ent then return con.Ent2 end - return con.Ent1 + local ent1 = con.Ent1 + if ent1 == ent then return con.Ent2 or NULL end + + return ent1 or NULL end --- Returns the first entity was welded to. From 1ca1d9c1a28ec48aacc6fbfbfbad8042d2cfedc6 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 14 Nov 2025 16:51:08 +0300 Subject: [PATCH 07/13] Fix keyClk --- lua/entities/gmod_wire_expression2/core/player.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index def8d1af31..1a18ea0580 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -431,7 +431,7 @@ __e2setcost(1) --- Returns user if the chip is being executed because of a key event. [nodiscard, deprecated = "Use the keyPressed event instead"] e2function entity keyClk() - if not self.data.runOnKeys then return nil end + if not self.data.runOnKeys then return NULL end return self.data.runOnKeys.runByKey end From 5ed76e34ab2687c98c3a6be31874a9ef32f88113 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 14 Nov 2025 17:51:15 +0300 Subject: [PATCH 08/13] Fix/optimize lastSpoke --- lua/entities/gmod_wire_expression2/core/chat.lua | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/chat.lua b/lua/entities/gmod_wire_expression2/core/chat.lua index 856bed65da..dd718b4070 100644 --- a/lua/entities/gmod_wire_expression2/core/chat.lua +++ b/lua/entities/gmod_wire_expression2/core/chat.lua @@ -4,7 +4,7 @@ local IsValid = IsValid local TextList = { - last = { "", 0, nil } + last = { "", 0, NULL } } local ChatAlert = {} @@ -20,7 +20,7 @@ end) hook.Add("PlayerSay","Exp2TextReceiving", function(ply, text, teamchat) chipHideChat, chipChatReplacement = nil, nil - + local entry = { text, CurTime(), ply, teamchat } TextList[ply:EntIndex()] = entry TextList.last = entry @@ -95,14 +95,7 @@ end --- Returns the last player to speak. [nodiscard, deprecated = "Use the chat event instead"] e2function entity lastSpoke() - local entry = TextList.last - if not entry then return nil end - - local ply = entry[3] - if not IsValid(ply) then return nil end - if not ply:IsPlayer() then return nil end - - return ply + return TextList.last[3] end --- Returns the last message in the chat log. From 72b5e09b979b5607302bb7c3e6be93194b5b772c Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 14 Nov 2025 17:53:04 +0300 Subject: [PATCH 09/13] Fix npcGetTarget --- lua/entities/gmod_wire_expression2/core/npc.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/npc.lua b/lua/entities/gmod_wire_expression2/core/npc.lua index 39f89fd271..71e1c2018b 100644 --- a/lua/entities/gmod_wire_expression2/core/npc.lua +++ b/lua/entities/gmod_wire_expression2/core/npc.lua @@ -83,9 +83,9 @@ e2function void entity:npcStop() end e2function entity entity:npcGetTarget() - if not validNPC(this) then return self:throw("Entity e: is not a valid NPC!", nil) end - if not isOwner(self, this) then return self:throw("You do not own this NPC!", nil) end - return this:GetEnemy() + if not validNPC(this) then return self:throw("Entity e: is not a valid NPC!", NULL) end + if not isOwner(self, this) then return self:throw("You do not own this NPC!", NULL) end + return this:GetEnemy() or NULL end e2function void entity:npcSetTarget(entity ent) From e6b025b86cfb5dc7c49ee6e56cc3c17b5f6c5b27 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 14 Nov 2025 17:56:37 +0300 Subject: [PATCH 10/13] More fixes --- lua/entities/gmod_wire_expression2/core/constraint.lua | 2 +- lua/entities/gmod_wire_expression2/core/entity.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/constraint.lua b/lua/entities/gmod_wire_expression2/core/constraint.lua index 1c4b85ad61..3eeb0c7828 100644 --- a/lua/entities/gmod_wire_expression2/core/constraint.lua +++ b/lua/entities/gmod_wire_expression2/core/constraint.lua @@ -289,7 +289,7 @@ end --- Returns the '''entity''' is parented to. e2function entity entity:parent() - if not IsValid(this) then return nil end + if not IsValid(this) then return self:throw("Invalid entity!", NULL) end return this:GetParent() end diff --git a/lua/entities/gmod_wire_expression2/core/entity.lua b/lua/entities/gmod_wire_expression2/core/entity.lua index 3406443554..ef6c0583ce 100644 --- a/lua/entities/gmod_wire_expression2/core/entity.lua +++ b/lua/entities/gmod_wire_expression2/core/entity.lua @@ -121,8 +121,8 @@ e2function string entity:model() end e2function entity entity:owner() - if not IsValid(this) then return self:throw("Invalid entity!", nil) end - return getOwner(self, this) + if not IsValid(this) then return self:throw("Invalid entity!", NULL) end + return getOwner(self, this) or NULL end __e2setcost(100) From 8e012282557d01cbd964a2eb9cc7fc753aa0d2cd Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 14 Nov 2025 18:11:15 +0300 Subject: [PATCH 11/13] Fix signalSender --- lua/entities/gmod_wire_expression2/core/signal.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/signal.lua b/lua/entities/gmod_wire_expression2/core/signal.lua index 88d8c05962..3a337a18e3 100644 --- a/lua/entities/gmod_wire_expression2/core/signal.lua +++ b/lua/entities/gmod_wire_expression2/core/signal.lua @@ -183,7 +183,7 @@ end --- Returns the entity of the chip that sent the signal. e2function entity signalSender() - if not self.data.currentSignal then return nil end + if not self.data.currentSignal then return NULL end return self.data.currentSignal[4] end From 26a0a3c6acb884e7b642502a69c6960255fc4c7c Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Sat, 15 Nov 2025 12:18:01 +0300 Subject: [PATCH 12/13] Simplify Co-authored-by: Denneisk <20892685+Denneisk@users.noreply.github.com> --- lua/entities/gmod_wire_expression2/core/hologram.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index fc95632f2a..4cf0eb9834 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -1325,11 +1325,7 @@ __e2setcost(2) e2function entity holoEntity(index) local Holo = CheckIndex(self, index) - if Holo and Holo.ent then - return Holo.ent - else - return NULL - end + return Holo and Holo.ent or NULL end __e2setcost(30) From 4f4e3610ac331a92d14a9e7dda6017b543109711 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Sat, 15 Nov 2025 14:23:32 +0300 Subject: [PATCH 13/13] Simplify more --- lua/entities/gmod_wire_expression2/core/selfaware.lua | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/selfaware.lua b/lua/entities/gmod_wire_expression2/core/selfaware.lua index 0736c6163d..a38bdb71ad 100644 --- a/lua/entities/gmod_wire_expression2/core/selfaware.lua +++ b/lua/entities/gmod_wire_expression2/core/selfaware.lua @@ -59,12 +59,7 @@ end [nodiscard] e2function entity ioInputEntity(string input) local ioinput = self.entity.Inputs[input] - - if ioinput and ioinput.Src and IsValid(ioinput.Src) then - return ioinput.Src - else - return NULL - end + return ioinput and IsValid(ioinput.Src) and ioinput.Src or NULL end local fixDefault = E2Lib.fixDefault