AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   How to SetParent (https://forums.alliedmods.net/showthread.php?t=261708)

Chdata 04-19-2015 02:39

How to SetParent
 
I see all sorts of ugly stuff like setting the targetname of players to something temporarily.

It's really simple.

PHP Code:

stock SetParentEx(iParentiChild)
{
    
SetVariantString("!activator");
    
AcceptEntityInput(iChild"SetParent"iParentiChild);
}

// player "eyes" "righteye" "lefteye" "partyhat" "head" "flag"
// weapon "muzzle" "eject_brass"
stock SetParent(iParentiChild, const String:szAttachment[] = ""Float:vOffsets[3] = {0.0,0.0,0.0})
{
    
SetVariantString("!activator");
    
AcceptEntityInput(iChild"SetParent"iParentiChild);

    if (
szAttachment[0] != '\0'// Use at least a 0.01 second delay between SetParent and SetParentAttachment inputs.
    
{
        
SetVariantString(szAttachment); // "head"

        
if (!AreVectorsEqual(vOffsetsFloat:{0.0,0.0,0.0})) // NULL_VECTOR
        
{
            
decl Float:vPos[3];
            
GetEntPropVector(iParentProp_Send"m_vecOrigin"vPos);
            
AddVectors(vPosvOffsetsvPos);
            
TeleportEntity(iChildvPosNULL_VECTORNULL_VECTOR);
            
AcceptEntityInput(iChild"SetParentAttachmentMaintainOffset"iParentiChild);
        }
        else
        {
            
AcceptEntityInput(iChild"SetParentAttachment"iParentiChild);
        }
    }
}

stock bool:AreVectorsEqual(Float:vVec1[3], Float:vVec2[3])
{
    return (
vVec1[0] == vVec2[0] && vVec1[1] == vVec2[1] && vVec1[2] == vVec2[2]);


iChild is the entity that will be made to follow wherever iParent moves.

friagram 04-19-2015 07:41

Re: Parenting things
 
According to the sdk docs, calling setparentattachment will teleport the entity tot he attachmentpoint, without need for setting origins, however, you can't do it on the same frame as setparent.

Dr. Greg House 04-19-2015 08:45

Re: Parenting things
 
Quote:

Originally Posted by friagram (Post 2287884)
According to the sdk docs, calling setparentattachment will teleport the entity tot he attachmentpoint, without need for setting origins, however, you can't do it on the same frame as setparent.

Try me.

friagram 04-19-2015 08:52

Re: How to SetParent
 
https://developer.valvesoftware.com/...rentAttachment

Chdata 04-19-2015 09:39

Re: How to SetParent
 
Ah so SetParentAttachment parents to an attachmentpoint, but from that point it follows the entity's origin, and MaintainOffset makes it follow the attachment point?

And in either case it teleports it to the attachment point?

actually wat

Dr. Greg House 04-19-2015 10:57

Re: How to SetParent
 
Quote:

Originally Posted by friagram (Post 2287912)

I read the article. I also did it without the delay and it works. Now shoot me.

friagram 04-22-2015 02:26

Re: How to SetParent
 
You can do it with no delay, but you have to set up the origins manually if you do so..
Like if you make entity 1 and entity 2 and parent, both are at the origin, so it works because they have the same coordinates, then you can teleport it.

However, if the entity is already created, and you do setparent and serparentattachmentmaintainoffset at the same time, it ma have undesired results.

Dr. Greg House 04-22-2015 06:53

Re: How to SetParent
 
Quote:

Originally Posted by friagram (Post 2288905)
However, if the entity is already created, and you do setparent and serparentattachmentmaintainoffset at the same time, it ma have undesired results.

Never had those, and I use these on multiple occasions.
Lesson learned: Never fully trust a (actually barely updated) wiki and do your own homework on occasion.
It is also highly possible it is outdated information and this changed around the release of tf2 etc., or branches used by valve have specific changes there.

Drixevel 04-22-2015 12:39

Re: How to SetParent
 
Lots of violence in one thread. :c (#offtopic)

friagram 04-23-2015 00:32

Re: How to SetParent
 
http://hittingthewall.paulglover.net.../11/oneup6.png
Because one-upmanship


All times are GMT -4. The time now is 02:20.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.