View Single Post
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