AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Sprite at the head of a NPC (https://forums.alliedmods.net/showthread.php?t=135561)

Netsys 08-17-2010 12:45

Sprite at the head of a NPC
 
Hello, I have trouble putting a sprite on top of the head of a NPC
I pulled the following error: Bad client in R_AttachTentToPlayer()

PHP Code:
PHP Code:

g_npcSpr precache_model("sprites/sexy.spr")

set_task2.0 "npc_sprite" g_npc "b" )
}

public 
npc_spriteent )
{
    
message_beginMSG_ALL SVC_TEMPENTITY )
    
write_byte124 )
    
write_byteent )
    
write_coord65 )
    
write_shortg_npcSpr )
    
write_short32767 )
    
message_end()



Netsys 08-17-2010 17:44

Re: Sprite at the head of a NPC
 
help pliz

XxAvalanchexX 08-17-2010 19:24

Re: Sprite at the head of a NPC
 
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.


All times are GMT -4. The time now is 22:01.

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