Raised This Month: $32 Target: $400
 8% 

How to SetParent


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 


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 15:45.


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