Junior Member
|
11-12-2014
, 06:14
Re: TF2 Sprite
|
#4
|
I found some stock functionsin zombie fortress doing that, I don't know if this method still works though, anyways, here you go :
Code:
stock fxCreateSprite(
const String:strSprite[],
target,
&entSpr,
&entAnc)
{
//
// Create a networked sprite attached to a player's head.
// This is done by parenting a sprite to a false 'anchor' prop, and then
// parenting the anchor to a target. While the anchor will not be visible,
// the sprite will be. Furthermore, since the sprite is parented to a
// networked entity, an extension like SDKHooks can be used to selectively
// display the sprite to an arbitrary set of clients.
//
entSpr = CreateEntityByName("env_sprite");
if(IsValidEntity(entSpr))
{
entAnc = CreateEntityByName("prop_physics_multiplayer");
if(IsValidEntity(entAnc))
{
decl String:strSprTargetname[32];
decl String:strAncTargetname[32];
decl String:strTgtTargetname[32];
Format(strSprTargetname, sizeof(strSprTargetname), "zfspr%i", entSpr);
Format(strAncTargetname, sizeof(strAncTargetname), "zfanc%i", entAnc);
Format(strTgtTargetname, sizeof(strTgtTargetname), "zftgt%i", target);
// Retrieve target's position
decl Float:posTgt[3];
GetEntPropVector(target, Prop_Send, "m_vecOrigin", posTgt);
posTgt[2] += 12.0;
// Configure target.
DispatchKeyValue(target, "targetname", strTgtTargetname);
// Configure and spawn anchor.
DispatchKeyValue(entAnc, "targetname", strAncTargetname);
DispatchKeyValue(entAnc, "parentname", strTgtTargetname);
SetEntityMoveType(entAnc, MOVETYPE_NOCLIP);
SetEntityModel(entAnc, ZFMDL_PRESENT[0]);
SetEntityRenderMode(entAnc, RENDER_TRANSCOLOR);
SetEntityRenderColor(entAnc, 0, 0, 0, 0);
DispatchSpawn(entAnc);
// Configure and spawn sprite.
DispatchKeyValue(entSpr, "targetname", strSprTargetname);
DispatchKeyValue(entSpr, "parentname", strAncTargetname);
DispatchKeyValue(entSpr, "model", strSprite);
DispatchKeyValue(entSpr, "classname", "env_sprite");
DispatchKeyValue(entSpr, "spawnflags", "1");
DispatchKeyValue(entSpr, "scale", "0.1");
DispatchKeyValue(entSpr, "rendermode", "1");
DispatchKeyValue(entSpr, "rendercolor", "255 255 255");
DispatchSpawn(entSpr);
// Teleport sprite and anchor to target.
TeleportEntity(entSpr, posTgt, NULL_VECTOR, NULL_VECTOR);
TeleportEntity(entAnc, posTgt, NULL_VECTOR, NULL_VECTOR);
// Parent sprite to anchor.
SetVariantString(strAncTargetname);
AcceptEntityInput(entSpr, "SetParent", entSpr, entSpr, 0);
// Parent anchor to target.
AcceptEntityInput(entAnc, "DisableMotion");
AcceptEntityInput(entAnc, "DisableShadow");
SetVariantString(strTgtTargetname);
AcceptEntityInput(entAnc, "SetParent", entAnc, entAnc, 0);
SetVariantString("head");
AcceptEntityInput(entAnc, "SetParentAttachmentMaintainOffset", entAnc, entAnc, 0);
}
else
{
LogError("[ZF] fxCreateSprite(entAnc) (%s, %d) failed.", strSprite, target);
}
}
else
{
LogError("[ZF] fxCreateSprite(entSpr) (%s, %d) failed.", strSprite, target);
}
}
stock fxDeleteSprite(entSpr, entAnc)
{
if(fxIsSpriteValid(entSpr, entAnc))
{
AcceptEntityInput(entSpr, "Kill");
AcceptEntityInput(entAnc, "Kill");
}
}
stock fxShowSprite(entSpr, entAnc)
{
if(fxIsSpriteValid(entSpr, entAnc))
AcceptEntityInput(entSpr, "ShowSprite");
}
stock fxHideSprite(entSpr, entAnc)
{
if(fxIsSpriteValid(entSpr, entAnc))
AcceptEntityInput(entSpr, "HideSprite");
}
|
|