Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getCollisionGroup and setCollisionGroup #2750

Merged
merged 4 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -659,13 +659,6 @@
noCollideCreate(self, ent1, ent2)
end

e2function void entity:noCollideAll(state)
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
if not isOwner(self, this) then return self:throw("You do not own this prop!", nil) end

this:SetCollisionGroup(state == 0 and COLLISION_GROUP_NONE or COLLISION_GROUP_WORLD)
end

--- Nocollides <ent> to entities/players, just like Right Click of No-Collide Stool
[deprecated]
e2function void noCollideAll(entity ent, state)
Expand Down
44 changes: 44 additions & 0 deletions lua/entities/gmod_wire_expression2/core/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@
return tostring(ent)
end

e2function string entity:toString() = e2function string toString(entity ent)

Check warning on line 838 in lua/entities/gmod_wire_expression2/core/entity.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace

E2Lib.registerEvent("playerLeftVehicle", {
{ "Player", "e" },
Expand Down Expand Up @@ -1009,6 +1009,50 @@
this:Extinguish()
end

E2Lib.registerConstant("COLLISION_GROUP_NONE", COLLISION_GROUP_NONE)
E2Lib.registerConstant("COLLISION_GROUP_DEBRIS", COLLISION_GROUP_DEBRIS)
E2Lib.registerConstant("COLLISION_GROUP_DEBRIS_TRIGGER", COLLISION_GROUP_DEBRIS_TRIGGER)
E2Lib.registerConstant("COLLISION_GROUP_INTERACTIVE_DEBRIS", COLLISION_GROUP_INTERACTIVE_DEBRIS)
E2Lib.registerConstant("COLLISION_GROUP_INTERACTIVE", COLLISION_GROUP_INTERACTIVE)
E2Lib.registerConstant("COLLISION_GROUP_PLAYER", COLLISION_GROUP_PLAYER)
E2Lib.registerConstant("COLLISION_GROUP_BREAKABLE_GLASS", COLLISION_GROUP_BREAKABLE_GLASS)
E2Lib.registerConstant("COLLISION_GROUP_VEHICLE", COLLISION_GROUP_VEHICLE)
E2Lib.registerConstant("COLLISION_GROUP_PLAYER_MOVEMENT", COLLISION_GROUP_PLAYER_MOVEMENT)
E2Lib.registerConstant("COLLISION_GROUP_NPC", COLLISION_GROUP_NPC)
E2Lib.registerConstant("COLLISION_GROUP_IN_VEHICLE", COLLISION_GROUP_IN_VEHICLE)
E2Lib.registerConstant("COLLISION_GROUP_WEAPON", COLLISION_GROUP_WEAPON)
E2Lib.registerConstant("COLLISION_GROUP_VEHICLE_CLIP", COLLISION_GROUP_VEHICLE_CLIP)
E2Lib.registerConstant("COLLISION_GROUP_PROJECTILE", COLLISION_GROUP_PROJECTILE)
E2Lib.registerConstant("COLLISION_GROUP_DOOR_BLOCKER", COLLISION_GROUP_DOOR_BLOCKER)
E2Lib.registerConstant("COLLISION_GROUP_PASSABLE_DOOR", COLLISION_GROUP_PASSABLE_DOOR)
E2Lib.registerConstant("COLLISION_GROUP_DISSOLVING", COLLISION_GROUP_DISSOLVING)
E2Lib.registerConstant("COLLISION_GROUP_PUSHAWAY", COLLISION_GROUP_PUSHAWAY)
E2Lib.registerConstant("COLLISION_GROUP_NPC_ACTOR", COLLISION_GROUP_NPC_ACTOR)
E2Lib.registerConstant("COLLISION_GROUP_NPC_SCRIPTED", COLLISION_GROUP_NPC_SCRIPTED)
E2Lib.registerConstant("COLLISION_GROUP_WORLD", COLLISION_GROUP_WORLD)

[nodiscard]
e2function number entity:getCollisionGroup()
if not IsValid(this) then return self:throw("Invalid entity!", -1) end
return this:GetCollisionGroup()
end

e2function void entity:setCollisionGroup(number group)
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
if group < 0 or group > 20 then return self:throw("Invalid collision group", nil) end
if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end
if this:IsPlayer() then return self:throw("You cannot set the collision group of a player!", nil) end

this:SetCollisionGroup(group)
end

e2function void entity:noCollideAll(number state)
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
if not isOwner(self, this) then return self:throw("You do not own this prop!", nil) end

this:SetCollisionGroup(state == 0 and COLLISION_GROUP_NONE or COLLISION_GROUP_WORLD)
end

hook.Add("OnEntityCreated", "E2_entityCreated", function(ent)
if not IsValid(ent) then return end -- Engine is precaching a model or bad addon

Expand Down
3 changes: 3 additions & 0 deletions lua/wire/client/e2descriptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ E2Helper.Descriptions["ignite(e:)"] = "Ignites an entity for 360 seconds (same a
E2Helper.Descriptions["ignite(e:n)"] = "Ignites an entity for the given length in seconds. Requires wire_expression2_entity_ignite_enabled"
E2Helper.Descriptions["ignite(e:nn)"] = "Creates a fire at an entity with given radius and length in seconds. Requires wire_expression2_entity_ignite_enabled"
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"
E2Helper.Descriptions["getCollisionGroup(e:)"] = "Returns the collision group of the entity"
E2Helper.Descriptions["setCollisionGroup(e:n)"] = "Sets the collision group of the entity. Does not work on players. Use one of the _COLLISION_GROUP constants"
E2Helper.Descriptions["noCollideAll"] = "Nocollides an entity to all entities/players, just like the tool's right-click"

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