Take a look at this thread:
https://forums.alliedmods.net/showthread.php?t=3229
I think TE_PLAYERATTACHMENT (124) only works on actual players, which is why the error says "Bad client." The code in the above link would work, except the sprite will be attached to the origin of the other entity, not above it. Something like this should work (I tested it on a player, except I used FM_PlayerPostThink instead of FM_Think):
Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <fakemeta_util>
#define pev_my_sprite pev_iuser1
new const gSzSprite[] = "sprites/voiceicon.spr";
public plugin_init()
{
register_concmd("attach","cmd_attach");
register_forward(FM_Think,"fw_think",1);
}
public plugin_precache()
{
precache_model(gSzSprite);
}
public fw_think(ent)
{
new sprite = pev(ent,pev_my_sprite);
if(sprite && pev_valid(sprite))
{
static Float:vecOrigin[3];
pev(ent,pev_origin,vecOrigin);
vecOrigin[2] += 20.0;
fm_entity_set_origin(sprite,vecOrigin);
}
return FMRES_IGNORED;
}
public cmd_attach(id)
{
new szEnt[32];
read_argv(1,szEnt,31);
new target = str_to_num(szEnt);
if(!pev_valid(target)) return PLUGIN_HANDLED;
new ent = fm_create_entity("info_target");
if(!pev_valid(ent)) return PLUGIN_HANDLED;
fm_entity_set_model(ent,gSzSprite);
fm_set_rendering(ent,kRenderFxNone,255,255,255,kRenderTransAdd,255);
set_pev(ent,pev_solid,SOLID_NOT);
set_pev(ent,pev_movetype,MOVETYPE_NOCLIP);
set_pev(target,pev_my_sprite,ent);
console_print(id,"* Attached model to %d!",target);
return PLUGIN_HANDLED;
}
This is assuming your non-player entity moves and thinks. If it doesn't move, then there's no need to constantly update its position. If it doesn't think, you can probably make it think with something like
Code:
set_pev(target,pev_nextthink,get_gametime() + 0.01);
called on its creation and every time it thinks after that. Note that it might be better to actually register Ham_Think with the HamSandwich module so you can specify the specific classname of your non-player entity, instead of catching the thinks of every single entity.
If that doesn't update fast enough, you'd have to hook something like FM_AddToFullPack and update the origin there, which would potentially be more processor intensive.
__________________