From ecb696d822c2343d0aef51862038ed67817c801f Mon Sep 17 00:00:00 2001 From: deltamolfar <72973198+deltamolfar@users.noreply.github.com> Date: Wed, 9 Apr 2025 18:46:18 +0300 Subject: [PATCH 1/6] Add prop-break related functions --- .../core/custom/cl_prop.lua | 2 ++ .../core/custom/prop.lua | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) 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 44c1c66702..59e52016fd 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua @@ -40,6 +40,8 @@ E2Helper.Descriptions["propSpawnEffect(n)"] = "Set to 1 to enable prop spawn eff E2Helper.Descriptions["propDelete(e:)"] = "Deletes the specified prop." E2Helper.Descriptions["propDelete(t:)"] = "Deletes all the props in the given table, returns the amount of props deleted." E2Helper.Descriptions["propDelete(r:)"] = "Deletes all the props in the given array, returns the amount of props deleted." +E2Helper.Descriptions["propMakeBreakable(e:n)"] = "Pass 0 to make it non-breakable, any other value to make it breakable. You can't make breakable props out of natively-unbreakable props." +E2Helper.Descriptions["propIsBreakable(e:)"] = "Returns 1, if the prop is breakable (including if prop has been previously marked as non-breakable by e:propMakeBreakable(n)), 0 otherwise." E2Helper.Descriptions["propFreeze(e:n)"] = "Passing 0 unfreezes the entity, everything else freezes it." E2Helper.Descriptions["propNotSolid(e:n)"] = "Passing 0 makes the entity solid, everything else makes it non-solid." E2Helper.Descriptions["propGravity(e:n)"] = "Passing 0 makes the entity weightless, everything else makes it weighty." diff --git a/lua/entities/gmod_wire_expression2/core/custom/prop.lua b/lua/entities/gmod_wire_expression2/core/custom/prop.lua index 04d0941093..bc1b045e1f 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/prop.lua @@ -714,6 +714,27 @@ e2function void entity:propBreak() this:Fire("break",1,0) end +local unbreakableEntities = {} + +hook.Add("EntityTakeDamage", "~~~wire.prop.unbreakable_think", function(ent, dmginfo) + if unbreakableEntities[target:EntIndex()] then dmginfo:ScaleDamage(0) end +end) + +hook.Add("EntityRemoved", "~~~wire.prop.clean_unbreakable_table", function(ent) + unbreakableEntities[ent:EntIndex()] = nil +end) + +e2function void entity:propMakeBreakable( number breakable ) + if not ValidAction(self, this, "break") then return end + unbreakableEntities[this:EntIndex()] = this:Health() > 0 and breakable == 0 and true or nil +end + +[nodiscard] +e2function number entity:propIsBreakable() + if not IsValid(this) then return self:throw("Invalid entity!", false) end + return this:Health() > 0 and not unbreakableEntities[this:EntIndex()] and 1 or 0 +end + E2Lib.registerConstant("ENTITY_DISSOLVE_NORMAL", 0) E2Lib.registerConstant("ENTITY_DISSOLVE_ELECTRICAL", 1) E2Lib.registerConstant("ENTITY_DISSOLVE_ELECTRICAL_LIGHT", 2) From 43ca543cdd9bf24bcbf4683b9162b1c64a22dd80 Mon Sep 17 00:00:00 2001 From: deltamolfar <72973198+deltamolfar@users.noreply.github.com> Date: Wed, 9 Apr 2025 22:35:36 +0300 Subject: [PATCH 2/6] Update lua/entities/gmod_wire_expression2/core/custom/prop.lua Co-authored-by: Astralcircle <142503363+Astralcircle@users.noreply.github.com> --- .../core/custom/prop.lua | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/custom/prop.lua b/lua/entities/gmod_wire_expression2/core/custom/prop.lua index bc1b045e1f..279552dfc6 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/prop.lua @@ -714,25 +714,21 @@ e2function void entity:propBreak() this:Fire("break",1,0) end -local unbreakableEntities = {} - -hook.Add("EntityTakeDamage", "~~~wire.prop.unbreakable_think", function(ent, dmginfo) - if unbreakableEntities[target:EntIndex()] then dmginfo:ScaleDamage(0) end -end) - -hook.Add("EntityRemoved", "~~~wire.prop.clean_unbreakable_table", function(ent) - unbreakableEntities[ent:EntIndex()] = nil +hook.Add("EntityTakeDamage", "WireUnbreakable", function(ent, dmginfo) + if ent.WireUnbreakable then + dmginfo:ScaleDamage(0) + end end) -e2function void entity:propMakeBreakable( number breakable ) +e2function void entity:propMakeBreakable(number breakable) if not ValidAction(self, this, "break") then return end - unbreakableEntities[this:EntIndex()] = this:Health() > 0 and breakable == 0 and true or nil + ent.WireUnbreakable = this:Health() > 0 and breakable == 0 and true or nil end [nodiscard] e2function number entity:propIsBreakable() - if not IsValid(this) then return self:throw("Invalid entity!", false) end - return this:Health() > 0 and not unbreakableEntities[this:EntIndex()] and 1 or 0 + if not IsValid(this) then return self:throw("Invalid entity!", 0) end + return this:Health() > 0 and not this.WireUnbreakable and 1 or 0 end E2Lib.registerConstant("ENTITY_DISSOLVE_NORMAL", 0) From 686dbfa0006c28aa70ffecc5db469f4cf2e4535c Mon Sep 17 00:00:00 2001 From: deltamolfar <72973198+deltamolfar@users.noreply.github.com> Date: Thu, 10 Apr 2025 11:41:24 +0300 Subject: [PATCH 3/6] Add cvar and prop_physics class check --- .../gmod_wire_expression2/core/custom/prop.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/custom/prop.lua b/lua/entities/gmod_wire_expression2/core/custom/prop.lua index 279552dfc6..93726eefb7 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/prop.lua @@ -11,6 +11,7 @@ local sbox_E2_PropCore = CreateConVar( "sbox_E2_PropCore", "2", FCVAR_ARCHIVE ) local sbox_E2_canMakeStatue = CreateConVar("sbox_E2_canMakeStatue", "1", FCVAR_ARCHIVE) local wire_expression2_propcore_sents_whitelist = CreateConVar("wire_expression2_propcore_sents_whitelist", 1, FCVAR_ARCHIVE, "If 1 - players can spawn sents only from the default sent list. If 0 - players can spawn sents from both the registered list and the entity tab.", 0, 1) local wire_expression2_propcore_sents_enabled = CreateConVar("wire_expression2_propcore_sents_enabled", 1, FCVAR_ARCHIVE, "If 1 - this allows sents to be spawned. (Doesn't affect the sentSpawn whitelist). If 0 - prevents sentSpawn from being used at all.", 0, 1) +local wire_expression2_propcore_canMakeUnbreakable = CreateConVar("wire_expression2_propcore_canMakeUnbreakable", 1, FCVAR_ARCHIVE, "If 1 - this allows props to be made unbreakable. If 0 - prevents propMakeUnbreakable from being used at all.", 0, 1) local isOwner = E2Lib.isOwner local GetBones = E2Lib.GetBones @@ -715,14 +716,22 @@ e2function void entity:propBreak() end hook.Add("EntityTakeDamage", "WireUnbreakable", function(ent, dmginfo) - if ent.WireUnbreakable then - dmginfo:ScaleDamage(0) - end + if ent.wire_unbreakable then dmginfo:ScaleDamage(0) end end) +[nodiscard] +e2function number entity:canMakeUnbreakable() + if not IsValid(this) then return self:throw("Invalid entity!", 0) end + if not wire_expression2_propcore_canMakeUnbreakable:GetBool() then return 0 end + return this:GetClass() == "prop_physics" and 1 or 0 +end + e2function void entity:propMakeBreakable(number breakable) + if not wire_expression2_propcore_canMakeUnbreakable:GetBool() then return self:throw("Making unbreakable is disabled by server! (wire_expression2_propcore_canMakeUnbreakable)", nil) end if not ValidAction(self, this, "break") then return end - ent.WireUnbreakable = this:Health() > 0 and breakable == 0 and true or nil + if this:GetClass() ~= "prop_physics" then return self:throw("This entity can not be made unbreakable!", nil) end + + this.wire_unbreakable = this:Health() > 0 and breakable == 0 and 1 or 0 end [nodiscard] From 3e6cdb2f4a3313b3f847bffe63e0205983e75fe2 Mon Sep 17 00:00:00 2001 From: deltamolfar <72973198+deltamolfar@users.noreply.github.com> Date: Sat, 26 Apr 2025 20:50:03 +0300 Subject: [PATCH 4/6] Update lua/entities/gmod_wire_expression2/core/custom/prop.lua Co-authored-by: Astralcircle <142503363+Astralcircle@users.noreply.github.com> --- lua/entities/gmod_wire_expression2/core/custom/prop.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/custom/prop.lua b/lua/entities/gmod_wire_expression2/core/custom/prop.lua index 93726eefb7..1da8651f40 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/prop.lua @@ -716,7 +716,7 @@ e2function void entity:propBreak() end hook.Add("EntityTakeDamage", "WireUnbreakable", function(ent, dmginfo) - if ent.wire_unbreakable then dmginfo:ScaleDamage(0) end + if ent.wire_unbreakable then return true end end) [nodiscard] From a0eabb1b46fe5868a39bcfb7b251145ce38f9b9e Mon Sep 17 00:00:00 2001 From: deltamolfar <72973198+deltamolfar@users.noreply.github.com> Date: Sat, 26 Apr 2025 20:50:12 +0300 Subject: [PATCH 5/6] Update lua/entities/gmod_wire_expression2/core/custom/prop.lua Co-authored-by: Astralcircle <142503363+Astralcircle@users.noreply.github.com> --- lua/entities/gmod_wire_expression2/core/custom/prop.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/custom/prop.lua b/lua/entities/gmod_wire_expression2/core/custom/prop.lua index 1da8651f40..67a9a982bb 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/prop.lua @@ -731,7 +731,7 @@ e2function void entity:propMakeBreakable(number breakable) if not ValidAction(self, this, "break") then return end if this:GetClass() ~= "prop_physics" then return self:throw("This entity can not be made unbreakable!", nil) end - this.wire_unbreakable = this:Health() > 0 and breakable == 0 and 1 or 0 + this.wire_unbreakable = this:Health() > 0 and breakable == 0 and true or nil end [nodiscard] From fe8c5237f7ef14ec4e5e9f664d3b575c8232ce0e Mon Sep 17 00:00:00 2001 From: deltamolfar <72973198+deltamolfar@users.noreply.github.com> Date: Sat, 26 Apr 2025 21:16:07 +0300 Subject: [PATCH 6/6] Fix description, change action name, add revert action on e2 removal --- .../gmod_wire_expression2/core/custom/prop.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/custom/prop.lua b/lua/entities/gmod_wire_expression2/core/custom/prop.lua index 67a9a982bb..4b5046e016 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/prop.lua @@ -11,7 +11,7 @@ local sbox_E2_PropCore = CreateConVar( "sbox_E2_PropCore", "2", FCVAR_ARCHIVE ) local sbox_E2_canMakeStatue = CreateConVar("sbox_E2_canMakeStatue", "1", FCVAR_ARCHIVE) local wire_expression2_propcore_sents_whitelist = CreateConVar("wire_expression2_propcore_sents_whitelist", 1, FCVAR_ARCHIVE, "If 1 - players can spawn sents only from the default sent list. If 0 - players can spawn sents from both the registered list and the entity tab.", 0, 1) local wire_expression2_propcore_sents_enabled = CreateConVar("wire_expression2_propcore_sents_enabled", 1, FCVAR_ARCHIVE, "If 1 - this allows sents to be spawned. (Doesn't affect the sentSpawn whitelist). If 0 - prevents sentSpawn from being used at all.", 0, 1) -local wire_expression2_propcore_canMakeUnbreakable = CreateConVar("wire_expression2_propcore_canMakeUnbreakable", 1, FCVAR_ARCHIVE, "If 1 - this allows props to be made unbreakable. If 0 - prevents propMakeUnbreakable from being used at all.", 0, 1) +local wire_expression2_propcore_canMakeUnbreakable = CreateConVar("wire_expression2_propcore_canMakeUnbreakable", 1, FCVAR_ARCHIVE, "If 1 - this allows props to be made unbreakable. If 0 - prevents propMakeBreakable from being used at all.", 0, 1) local isOwner = E2Lib.isOwner local GetBones = E2Lib.GetBones @@ -728,10 +728,22 @@ end e2function void entity:propMakeBreakable(number breakable) if not wire_expression2_propcore_canMakeUnbreakable:GetBool() then return self:throw("Making unbreakable is disabled by server! (wire_expression2_propcore_canMakeUnbreakable)", nil) end - if not ValidAction(self, this, "break") then return end + if not ValidAction(self, this, "makeUnbreakable") then return end if this:GetClass() ~= "prop_physics" then return self:throw("This entity can not be made unbreakable!", nil) end - this.wire_unbreakable = this:Health() > 0 and breakable == 0 and true or nil + local unbreakable = this:Health() > 0 and breakable == 0 and true or nil + if this.wire_unbreakable == unbreakable then return end + this.wire_unbreakable = unbreakable + + if unbreakable then + self.entity:CallOnRemove("wire_expression2_propcore_propMakeBreakable-" .. this:EntIndex(), + function( e ) + this.wire_unbreakable = nil + end + ) + else + self.entity:RemoveCallOnRemove("wire_expression2_propcore_propMakeBreakable-" .. this:EntIndex()) + end end [nodiscard]