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..4b5046e016 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 propMakeBreakable from being used at all.", 0, 1) local isOwner = E2Lib.isOwner local GetBones = E2Lib.GetBones @@ -714,6 +715,43 @@ e2function void entity:propBreak() this:Fire("break",1,0) end +hook.Add("EntityTakeDamage", "WireUnbreakable", function(ent, dmginfo) + if ent.wire_unbreakable then return true 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, "makeUnbreakable") then return end + if this:GetClass() ~= "prop_physics" then return self:throw("This entity can not be made unbreakable!", nil) end + + 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] +e2function number entity:propIsBreakable() + 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) E2Lib.registerConstant("ENTITY_DISSOLVE_ELECTRICAL", 1) E2Lib.registerConstant("ENTITY_DISSOLVE_ELECTRICAL_LIGHT", 2)