Monthly Target: $400 Donations: $228
 56% 

How to SetParent


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 04-19-2015 , 02:39   How to SetParent
Reply With Quote #1

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.
__________________

Last edited by Chdata; 04-19-2015 at 07:49.
Chdata is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 04-19-2015 , 07:41   Re: Parenting things
Reply With Quote #2

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.
__________________
Profile - Steam Group - Plugins - Blog - Donate
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 04-19-2015 , 08:45   Re: Parenting things
Reply With Quote #3

Quote:
Originally Posted by friagram View Post
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.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 04-19-2015 , 08:52   Re: How to SetParent
Reply With Quote #4

https://developer.valvesoftware.com/...rentAttachment
__________________
Profile - Steam Group - Plugins - Blog - Donate
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 04-19-2015 , 09:39   Re: How to SetParent
Reply With Quote #5

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
__________________

Last edited by Chdata; 04-19-2015 at 09:44.
Chdata is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 04-19-2015 , 10:57   Re: How to SetParent
Reply With Quote #6

Quote:
Originally Posted by friagram View Post
I read the article. I also did it without the delay and it works. Now shoot me.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 04-22-2015 , 02:26   Re: How to SetParent
Reply With Quote #7

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.
__________________
Profile - Steam Group - Plugins - Blog - Donate
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 04-22-2015 , 06:53   Re: How to SetParent
Reply With Quote #8

Quote:
Originally Posted by friagram View Post
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.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
redwerewolf
r3dw3r3w0lf
Join Date: Sep 2009
Old 04-22-2015 , 12:39   Re: How to SetParent
Reply With Quote #9

Lots of violence in one thread. :c (#offtopic)
__________________
Taking private requests: http://steamcommunity.com/id/Drixevel/
redwerewolf is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 04-23-2015 , 00:32   Re: How to SetParent
Reply With Quote #10


Because one-upmanship
__________________
Profile - Steam Group - Plugins - Blog - Donate
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:46.


Powered by vBulletin®
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Theme made by Freecode