View Single Post
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 04-25-2014 , 16:33   Re: pev_skin on grenades
Reply With Quote #3

I went with body anyway, because I'll probably use completely different models too.

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include < fun >
#include < fakemeta >

#define PLUGIN "New Plugin"
#define VERSION "1.0"
#define AUTHOR "Author"


const ANIM_DEPLOY 3

new g_body

public plugin_init() 
{
    
register_pluginPLUGINVERSIONAUTHOR )
    
    
register_clcmd"gettestnade""gettestnade" )
    
register_clcmd"changeskin""changeskin" )
    
    
register_forwardFM_UpdateClientData"UpdateClientData")
}

public 
UpdateClientDataidsendweaponscd )
{
    if( 
sendweapons && get_user_weaponid ) == CSW_HEGRENADE )
    {
        
        static 
iAnimPrevious
        
new iAnim get_cdcdCD_WeaponAnim )
    
        if( 
iAnimPrevious != iAnim )
        {
            if( 
iAnim == ANIM_DEPLOY )
            {
                
set_pevidpev_viewmodel2"models/traxxrp/v_combined.mdl" )
            }
        
            
client_printidprint_chat"UpdateClientData iAnim: %d"iAnim )
            
flushanimationidiAnimg_body )
        
            
iAnimPrevious iAnim
        
}
    
    }
}  

public 
plugin_precache( )
{
    
precache_model"models/traxxrp/v_combined.mdl" )
}

public 
gettestnadeid )
{
    
give_itemid"weapon_hegrenade" )
}

public 
changeskinid )
{
    new 
szArgs]
    
read_argsszArgscharsmaxszArgs ) )
    
    
remove_quotesszArgs )
    
trimszArgs )
    
    
g_body str_to_numszArgs )
    
    
flushanimationidANIM_DEPLOYg_body )
    
    
client_printidprint_console"Setting animation with pev_body: %d"g_body )
}

flushanimationidiAnimiBodyValue )
{
    
set_pevidpev_weaponanimiAnim )
    
message_beginMSG_ONESVC_WEAPONANIM, {000}, id )
    
write_byteiAnim )
    
write_byteiBodyValue )
    
message_end( )

It works more or less, but for some reason, the deploy animation never gets the correct body value. I actually need to wait for the idle animation swap, then it gets properly changed. Also when another animation's played, the model flickers back to it's original body value for one frame, then it goes back to the correct one. Do you have any idea? I'm attaching the model as well in case you want to try it. The "other" body value is 3, so use changeskin 3.

The code is bad but it's enough for testing. Didn't feel like using Ham_Item_Deploy.

Edit: I think that the animation flicker is caused by the fact FM_UpdateClientData is a post forward, however it's impossible to replace the animation in a pre call.
Attached Files
File Type: zip v_combined.zip (235.2 KB, 176 views)
__________________
Currently busy working on a very large scale anime database project.

Last edited by Backstabnoob; 04-25-2014 at 16:40.
Backstabnoob is offline