View Single Post
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 05-02-2024 , 21:30   Re: change v_ model for a few seconds
Reply With Quote #7

this works, just cancel task when switching weapons
only drawback is that you have to keep both weapon model replacement and syringe injector in the same source
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>

const USE_ANIMATION 0
new const model[] = "models/v_injectorX.mdl"
new const knife_model[] = "models/v_knife_r.mdl"

public plugin_init()
{
    
register_clcmd("say f""clcmd_f")
    
RegisterHam(Ham_Item_Deploy"weapon_knife""weapon_knife"1)
}

public 
plugin_precache()
{
    
precache_model(model)
    
precache_model(knife_model)
}

public 
clcmd_f(id)
{
    new 
weapon_model[64]
    
pev(idpev_viewmodel2weapon_modelcharsmax(weapon_model))
    
set_pev(idpev_viewmodel2model)
    
UTIL_SenwWeaponAnim(idUSE_ANIMATION)
    
set_task(2.83"end_animation"idweapon_modelsizeof(weapon_model))
}

public 
weapon_knife(knife_entity)
{
    new 
id pev(knife_entitypev_owner)
    if (
id)
        
set_pev(idpev_viewmodel2knife_model)
}

public 
end_animation(weapon_model[64], id)
{
    if (
is_user_alive(id))
    {
        new 
weapon_entity fm_get_user_weapon_entity(idget_user_weapon(id))
        
ExecuteHam(Ham_Item_Deployweapon_entity)
        
set_pev(idpev_viewmodel2weapon_model)
    }
}

// https://forums.alliedmods.net/showpost.php?p=2387036&postcount=2
stock UTIL_SenwWeaponAnim(const pPlayer, const Sequence)
{
    
set_pev(pPlayerpev_weaponanimSequence)
    
    
message_begin(MSG_ONE_UNRELIABLESVC_WEAPONANIM, .player pPlayer)
    
write_byte(Sequence)
    
write_byte(pev(pPlayerpev_body))
    
message_end()

to test select knife and press `f` in chat
__________________
bigdaddy424 is offline