Raised This Month: $ Target: $400
 0% 

Sprite at the head of a NPC


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 08-17-2010 , 19:24   Re: Sprite at the head of a NPC
Reply With Quote #3

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.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS

Last edited by XxAvalanchexX; 08-17-2010 at 20:13.
XxAvalanchexX is offline
 



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 22:01.


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