Skip to content

Commit cef7a6c

Browse files
Add prop-break related functions (#3300)
* Add prop-break related functions * Update lua/entities/gmod_wire_expression2/core/custom/prop.lua Co-authored-by: Astralcircle <142503363+Astralcircle@users.noreply.github.com> * Add cvar and prop_physics class check * Update lua/entities/gmod_wire_expression2/core/custom/prop.lua Co-authored-by: Astralcircle <142503363+Astralcircle@users.noreply.github.com> * Update lua/entities/gmod_wire_expression2/core/custom/prop.lua Co-authored-by: Astralcircle <142503363+Astralcircle@users.noreply.github.com> * Fix description, change action name, add revert action on e2 removal --------- Co-authored-by: Astralcircle <142503363+Astralcircle@users.noreply.github.com>
1 parent a1efac1 commit cef7a6c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ E2Helper.Descriptions["propSpawnEffect(n)"] = "Set to 1 to enable prop spawn eff
4040
E2Helper.Descriptions["propDelete(e:)"] = "Deletes the specified prop."
4141
E2Helper.Descriptions["propDelete(t:)"] = "Deletes all the props in the given table, returns the amount of props deleted."
4242
E2Helper.Descriptions["propDelete(r:)"] = "Deletes all the props in the given array, returns the amount of props deleted."
43+
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."
44+
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."
4345
E2Helper.Descriptions["propFreeze(e:n)"] = "Passing 0 unfreezes the entity, everything else freezes it."
4446
E2Helper.Descriptions["propNotSolid(e:n)"] = "Passing 0 makes the entity solid, everything else makes it non-solid."
4547
E2Helper.Descriptions["propGravity(e:n)"] = "Passing 0 makes the entity weightless, everything else makes it weighty."

lua/entities/gmod_wire_expression2/core/custom/prop.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local sbox_E2_PropCore = CreateConVar( "sbox_E2_PropCore", "2", FCVAR_ARCHIVE )
1111
local sbox_E2_canMakeStatue = CreateConVar("sbox_E2_canMakeStatue", "1", FCVAR_ARCHIVE)
1212
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)
1313
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)
14+
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)
1415

1516
local isOwner = E2Lib.isOwner
1617
local GetBones = E2Lib.GetBones
@@ -714,6 +715,43 @@ e2function void entity:propBreak()
714715
this:Fire("break",1,0)
715716
end
716717

718+
hook.Add("EntityTakeDamage", "WireUnbreakable", function(ent, dmginfo)
719+
if ent.wire_unbreakable then return true end
720+
end)
721+
722+
[nodiscard]
723+
e2function number entity:canMakeUnbreakable()
724+
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
725+
if not wire_expression2_propcore_canMakeUnbreakable:GetBool() then return 0 end
726+
return this:GetClass() == "prop_physics" and 1 or 0
727+
end
728+
729+
e2function void entity:propMakeBreakable(number breakable)
730+
if not wire_expression2_propcore_canMakeUnbreakable:GetBool() then return self:throw("Making unbreakable is disabled by server! (wire_expression2_propcore_canMakeUnbreakable)", nil) end
731+
if not ValidAction(self, this, "makeUnbreakable") then return end
732+
if this:GetClass() ~= "prop_physics" then return self:throw("This entity can not be made unbreakable!", nil) end
733+
734+
local unbreakable = this:Health() > 0 and breakable == 0 and true or nil
735+
if this.wire_unbreakable == unbreakable then return end
736+
this.wire_unbreakable = unbreakable
737+
738+
if unbreakable then
739+
self.entity:CallOnRemove("wire_expression2_propcore_propMakeBreakable-" .. this:EntIndex(),
740+
function( e )
741+
this.wire_unbreakable = nil
742+
end
743+
)
744+
else
745+
self.entity:RemoveCallOnRemove("wire_expression2_propcore_propMakeBreakable-" .. this:EntIndex())
746+
end
747+
end
748+
749+
[nodiscard]
750+
e2function number entity:propIsBreakable()
751+
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
752+
return this:Health() > 0 and not this.WireUnbreakable and 1 or 0
753+
end
754+
717755
E2Lib.registerConstant("ENTITY_DISSOLVE_NORMAL", 0)
718756
E2Lib.registerConstant("ENTITY_DISSOLVE_ELECTRICAL", 1)
719757
E2Lib.registerConstant("ENTITY_DISSOLVE_ELECTRICAL_LIGHT", 2)

0 commit comments

Comments
 (0)