Skip to content

Commit 9a37581

Browse files
authored
Add getCollisionGroup and setCollisionGroup (#2750)
* Add getCollisionGroup and setCollisionGroup * mark getCollisionGroup as nodiscard * Move noCollideAll * Add description
1 parent b43c615 commit 9a37581

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

lua/entities/gmod_wire_expression2/core/custom/constraintcore.lua

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,6 @@ e2function void noCollide(entity ent1, entity ent2)
659659
noCollideCreate(self, ent1, ent2)
660660
end
661661

662-
e2function void entity:noCollideAll(state)
663-
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
664-
if not isOwner(self, this) then return self:throw("You do not own this prop!", nil) end
665-
666-
this:SetCollisionGroup(state == 0 and COLLISION_GROUP_NONE or COLLISION_GROUP_WORLD)
667-
end
668-
669662
--- Nocollides <ent> to entities/players, just like Right Click of No-Collide Stool
670663
[deprecated]
671664
e2function void noCollideAll(entity ent, state)

lua/entities/gmod_wire_expression2/core/entity.lua

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,50 @@ e2function void entity:extinguish()
10091009
this:Extinguish()
10101010
end
10111011

1012+
E2Lib.registerConstant("COLLISION_GROUP_NONE", COLLISION_GROUP_NONE)
1013+
E2Lib.registerConstant("COLLISION_GROUP_DEBRIS", COLLISION_GROUP_DEBRIS)
1014+
E2Lib.registerConstant("COLLISION_GROUP_DEBRIS_TRIGGER", COLLISION_GROUP_DEBRIS_TRIGGER)
1015+
E2Lib.registerConstant("COLLISION_GROUP_INTERACTIVE_DEBRIS", COLLISION_GROUP_INTERACTIVE_DEBRIS)
1016+
E2Lib.registerConstant("COLLISION_GROUP_INTERACTIVE", COLLISION_GROUP_INTERACTIVE)
1017+
E2Lib.registerConstant("COLLISION_GROUP_PLAYER", COLLISION_GROUP_PLAYER)
1018+
E2Lib.registerConstant("COLLISION_GROUP_BREAKABLE_GLASS", COLLISION_GROUP_BREAKABLE_GLASS)
1019+
E2Lib.registerConstant("COLLISION_GROUP_VEHICLE", COLLISION_GROUP_VEHICLE)
1020+
E2Lib.registerConstant("COLLISION_GROUP_PLAYER_MOVEMENT", COLLISION_GROUP_PLAYER_MOVEMENT)
1021+
E2Lib.registerConstant("COLLISION_GROUP_NPC", COLLISION_GROUP_NPC)
1022+
E2Lib.registerConstant("COLLISION_GROUP_IN_VEHICLE", COLLISION_GROUP_IN_VEHICLE)
1023+
E2Lib.registerConstant("COLLISION_GROUP_WEAPON", COLLISION_GROUP_WEAPON)
1024+
E2Lib.registerConstant("COLLISION_GROUP_VEHICLE_CLIP", COLLISION_GROUP_VEHICLE_CLIP)
1025+
E2Lib.registerConstant("COLLISION_GROUP_PROJECTILE", COLLISION_GROUP_PROJECTILE)
1026+
E2Lib.registerConstant("COLLISION_GROUP_DOOR_BLOCKER", COLLISION_GROUP_DOOR_BLOCKER)
1027+
E2Lib.registerConstant("COLLISION_GROUP_PASSABLE_DOOR", COLLISION_GROUP_PASSABLE_DOOR)
1028+
E2Lib.registerConstant("COLLISION_GROUP_DISSOLVING", COLLISION_GROUP_DISSOLVING)
1029+
E2Lib.registerConstant("COLLISION_GROUP_PUSHAWAY", COLLISION_GROUP_PUSHAWAY)
1030+
E2Lib.registerConstant("COLLISION_GROUP_NPC_ACTOR", COLLISION_GROUP_NPC_ACTOR)
1031+
E2Lib.registerConstant("COLLISION_GROUP_NPC_SCRIPTED", COLLISION_GROUP_NPC_SCRIPTED)
1032+
E2Lib.registerConstant("COLLISION_GROUP_WORLD", COLLISION_GROUP_WORLD)
1033+
1034+
[nodiscard]
1035+
e2function number entity:getCollisionGroup()
1036+
if not IsValid(this) then return self:throw("Invalid entity!", -1) end
1037+
return this:GetCollisionGroup()
1038+
end
1039+
1040+
e2function void entity:setCollisionGroup(number group)
1041+
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
1042+
if group < 0 or group > 20 then return self:throw("Invalid collision group", nil) end
1043+
if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end
1044+
if this:IsPlayer() then return self:throw("You cannot set the collision group of a player!", nil) end
1045+
1046+
this:SetCollisionGroup(group)
1047+
end
1048+
1049+
e2function void entity:noCollideAll(number state)
1050+
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
1051+
if not isOwner(self, this) then return self:throw("You do not own this prop!", nil) end
1052+
1053+
this:SetCollisionGroup(state == 0 and COLLISION_GROUP_NONE or COLLISION_GROUP_WORLD)
1054+
end
1055+
10121056
hook.Add("OnEntityCreated", "E2_entityCreated", function(ent)
10131057
if not IsValid(ent) then return end -- Engine is precaching a model or bad addon
10141058

lua/wire/client/e2descriptions.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ E2Helper.Descriptions["ignite(e:)"] = "Ignites an entity for 360 seconds (same a
371371
E2Helper.Descriptions["ignite(e:n)"] = "Ignites an entity for the given length in seconds. Requires wire_expression2_entity_ignite_enabled"
372372
E2Helper.Descriptions["ignite(e:nn)"] = "Creates a fire at an entity with given radius and length in seconds. Requires wire_expression2_entity_ignite_enabled"
373373
E2Helper.Descriptions["extinguish(e:)"] = "Extinguishes an entity granted you have permission. Does not work inside of entityDamage event if the attacker is the fire itself"
374+
E2Helper.Descriptions["getCollisionGroup(e:)"] = "Returns the collision group of the entity"
375+
E2Helper.Descriptions["setCollisionGroup(e:n)"] = "Sets the collision group of the entity. Does not work on players. Use one of the _COLLISION_GROUP constants"
376+
E2Helper.Descriptions["noCollideAll"] = "Nocollides an entity to all entities/players, just like the tool's right-click"
374377

375378
-- Attachment
376379
E2Helper.Descriptions["lookupAttachment(e:s)"] = "Returns Es attachment ID associated with attachmentName"

0 commit comments

Comments
 (0)