From 2ec9932a551cc4d22ca2439834bfe1ce5aedb847 Mon Sep 17 00:00:00 2001 From: unknao Date: Sun, 28 Jul 2024 10:28:51 +0300 Subject: [PATCH 1/3] Add entity:parentToAttachment() --- .../core/custom/cl_prop.lua | 1 + .../core/custom/prop.lua | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua b/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua index 78868bfddf..67dd073aa6 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua @@ -51,6 +51,7 @@ E2Helper.Descriptions["setLocalAng(e:a)"] = "Set the rotation of an entity local E2Helper.Descriptions["rerotate(e:a)"] = "Deprecated. Kept for backwards-compatibility." E2Helper.Descriptions["parentTo(e:e)"] = "Parents one entity to another." E2Helper.Descriptions["parentTo(e:)"] = E2Helper.Descriptions["parentTo(e:e)"] +E2Helper.Descriptions["parentToAttachment(e:es)"] = "Parents one entity to anothers attachment." E2Helper.Descriptions["deparent(e:)"] = "Unparents an entity, so it moves freely again." E2Helper.Descriptions["propBreak(e:)"] = "Breaks/Explodes breakable/explodable props (Useful for Mines)." E2Helper.Descriptions["propCanCreate()"] = "Returns 1 when propSpawn() will successfully spawn a prop until the limit is reached." diff --git a/lua/entities/gmod_wire_expression2/core/custom/prop.lua b/lua/entities/gmod_wire_expression2/core/custom/prop.lua index 5131c5396d..207a726360 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/prop.lua @@ -197,7 +197,7 @@ local function boneVerify(self, bone) return ent, index end --- A way to statically blacklist a registered sent +-- A way to statically blacklist a registered sent local blacklistedSents = { --gmod_wire_foo = true, } @@ -1254,6 +1254,19 @@ e2function void entity:parentTo(entity target) this:SetParent(target) end +e2function void entity:parentToAttachment(entity target, string attachmentName) + if not ValidAction(self, this, "parent") then return self:throw("You do not have permission to parent to this prop!", nil) end + if not IsValid(target) then return self:throw("Target prop is invalid.", nil) end + if not isOwner(self, target) then return self:throw("You do not own the target prop!", nil) end + if not parent_antispam( this ) then return self:throw("You are parenting too fast!", nil) end + if this == target then return self:throw("You cannot parent a prop to itself") end + if not parent_check( self, this, target ) then return self:throw("Parenting chain of entities can't exceed 16 or crash may occur", nil) end + if attachmentName == nil then return self:throw("You cannot parent to nil attachment!", nil) end + + this:SetParent(target) + this:Fire("SetParentAttachmentMaintainOffset", attachmentName) +end + __e2setcost(5) e2function void entity:deparent() if not ValidAction(self, this, "deparent") then return end @@ -1534,7 +1547,7 @@ local function E2CollisionEventHandler() if IsValid(chip) then if not chip.error then for _,i in ipairs(ctx.data.E2QueuedCollisions) do - if i.cb then + if i.cb then -- Arguments for this were checked when we set it up, no need to typecheck i.cb:UnsafeCall({i.us,i.xcd.HitEntity,i.xcd}) if chip.error then break end @@ -1598,7 +1611,7 @@ e2function number trackCollision( entity ent, function cb ) local arg_sig = "(void)" if #cb.arg_sig > 0 then arg_sig = "("..cb.arg_sig..")" - end + end self:forceThrow("Collision callback expecting arguments (eexcd), got "..arg_sig) end startCollisionTracking(self,ent,entIndex,cb) From e9fe87098962c50f304f56dc673ad0f736858841 Mon Sep 17 00:00:00 2001 From: unknao Date: Tue, 24 Dec 2024 10:06:16 +0200 Subject: [PATCH 2/3] Fix design oversight on timerSetDelay. --- lua/entities/gmod_wire_expression2/core/timer.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/timer.lua b/lua/entities/gmod_wire_expression2/core/timer.lua index 831baa6541..8d861a77a2 100644 --- a/lua/entities/gmod_wire_expression2/core/timer.lua +++ b/lua/entities/gmod_wire_expression2/core/timer.lua @@ -58,7 +58,7 @@ local luaTimers = { delay = 1, repetitions = 1 } - } + } */ } @@ -244,8 +244,18 @@ e2function void timerSetDelay(string name, number delay) end local entIndex = self.entity:EntIndex() + local internalName = luaTimerGetInternalName(entIndex, name) luaTimers[entIndex][name].delay = delay - timer.Adjust(luaTimerGetInternalName(entIndex, name), delay, 0) + + if luaTimers[entIndex][name].repetitions > 0 then + local repsLeft = timer.RepsLeft(internalName) + if repsLeft == 0 then return end + + luaTimers[entIndex][name].repetitions = repsLeft + timer.Adjust(internalName, delay, repsLeft) + return + end + timer.Adjust(internalName, delay, 0) end e2function number timerSetReps(string name, number repetitions) From a722a5e74656d122b0bfa26cce08a3bb26048345 Mon Sep 17 00:00:00 2001 From: unknao Date: Wed, 25 Dec 2024 09:48:32 +0200 Subject: [PATCH 3/3] removed unnecessary logic --- lua/entities/gmod_wire_expression2/core/timer.lua | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/timer.lua b/lua/entities/gmod_wire_expression2/core/timer.lua index 8d861a77a2..ed042a72ef 100644 --- a/lua/entities/gmod_wire_expression2/core/timer.lua +++ b/lua/entities/gmod_wire_expression2/core/timer.lua @@ -244,18 +244,9 @@ e2function void timerSetDelay(string name, number delay) end local entIndex = self.entity:EntIndex() - local internalName = luaTimerGetInternalName(entIndex, name) luaTimers[entIndex][name].delay = delay - if luaTimers[entIndex][name].repetitions > 0 then - local repsLeft = timer.RepsLeft(internalName) - if repsLeft == 0 then return end - - luaTimers[entIndex][name].repetitions = repsLeft - timer.Adjust(internalName, delay, repsLeft) - return - end - timer.Adjust(internalName, delay, 0) + timer.Adjust(luaTimerGetInternalName(entIndex, name), delay) end e2function number timerSetReps(string name, number repetitions)