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 entity:parentToAttachment() #3110

Merged
merged 1 commit into from
Aug 8, 2024
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
1 change: 1 addition & 0 deletions lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ E2Helper.Descriptions["setLocalAng(e:a)"] = "Set the rotation of an entity local
E2Helper.Descriptions["rerotate(e:a)"] = "Deprecated. Kept for backwards-compatibility."
E2Helper.Descriptions["parentTo(e:e)"] = "Parents one entity to another."
E2Helper.Descriptions["parentTo(e:)"] = E2Helper.Descriptions["parentTo(e:e)"]
E2Helper.Descriptions["parentToAttachment(e:es)"] = "Parents one entity to anothers attachment."
E2Helper.Descriptions["deparent(e:)"] = "Unparents an entity, so it moves freely again."
E2Helper.Descriptions["propBreak(e:)"] = "Breaks/Explodes breakable/explodable props (Useful for Mines)."
E2Helper.Descriptions["propCanCreate()"] = "Returns 1 when propSpawn() will successfully spawn a prop until the limit is reached."
Expand Down
19 changes: 16 additions & 3 deletions lua/entities/gmod_wire_expression2/core/custom/prop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ local function boneVerify(self, bone)
return ent, index
end

-- A way to statically blacklist a registered sent
-- A way to statically blacklist a registered sent
local blacklistedSents = {
--gmod_wire_foo = true,
}
Expand Down Expand Up @@ -1254,6 +1254,19 @@ e2function void entity:parentTo(entity target)
this:SetParent(target)
end

e2function void entity:parentToAttachment(entity target, string attachmentName)
if not ValidAction(self, this, "parent") then return self:throw("You do not have permission to parent to this prop!", nil) end
if not IsValid(target) then return self:throw("Target prop is invalid.", nil) end
if not isOwner(self, target) then return self:throw("You do not own the target prop!", nil) end
if not parent_antispam( this ) then return self:throw("You are parenting too fast!", nil) end
if this == target then return self:throw("You cannot parent a prop to itself") end
if not parent_check( self, this, target ) then return self:throw("Parenting chain of entities can't exceed 16 or crash may occur", nil) end
if attachmentName == nil then return self:throw("You cannot parent to nil attachment!", nil) end

this:SetParent(target)
this:Fire("SetParentAttachmentMaintainOffset", attachmentName)
end

__e2setcost(5)
e2function void entity:deparent()
if not ValidAction(self, this, "deparent") then return end
Expand Down Expand Up @@ -1534,7 +1547,7 @@ local function E2CollisionEventHandler()
if IsValid(chip) then
if not chip.error then
for _,i in ipairs(ctx.data.E2QueuedCollisions) do
if i.cb then
if i.cb then
-- Arguments for this were checked when we set it up, no need to typecheck
i.cb:UnsafeCall({i.us,i.xcd.HitEntity,i.xcd})
if chip.error then break end
Expand Down Expand Up @@ -1598,7 +1611,7 @@ e2function number trackCollision( entity ent, function cb )
local arg_sig = "(void)"
if #cb.arg_sig > 0 then
arg_sig = "("..cb.arg_sig..")"
end
end
self:forceThrow("Collision callback expecting arguments (eexcd), got "..arg_sig)
end
startCollisionTracking(self,ent,entIndex,cb)
Expand Down
Loading