I see all sorts of ugly stuff like setting the targetname of players to something temporarily.
It's really simple.
PHP Code:
stock SetParentEx(iParent, iChild)
{
SetVariantString("!activator");
AcceptEntityInput(iChild, "SetParent", iParent, iChild);
}
// player "eyes" "righteye" "lefteye" "partyhat" "head" "flag"
// weapon "muzzle" "eject_brass"
stock SetParent(iParent, iChild, const String:szAttachment[] = "", Float:vOffsets[3] = {0.0,0.0,0.0})
{
SetVariantString("!activator");
AcceptEntityInput(iChild, "SetParent", iParent, iChild);
if (szAttachment[0] != '\0') // Use at least a 0.01 second delay between SetParent and SetParentAttachment inputs.
{
SetVariantString(szAttachment); // "head"
if (!AreVectorsEqual(vOffsets, Float:{0.0,0.0,0.0})) // NULL_VECTOR
{
decl Float:vPos[3];
GetEntPropVector(iParent, Prop_Send, "m_vecOrigin", vPos);
AddVectors(vPos, vOffsets, vPos);
TeleportEntity(iChild, vPos, NULL_VECTOR, NULL_VECTOR);
AcceptEntityInput(iChild, "SetParentAttachmentMaintainOffset", iParent, iChild);
}
else
{
AcceptEntityInput(iChild, "SetParentAttachment", iParent, iChild);
}
}
}
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.
__________________