Raised This Month: $ Target: $400
 0% 

Solved [HELP] Player Model Animation Sometimes Stops


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hellmonja
Senior Member
Join Date: Oct 2015
Old 06-30-2019 , 04:35   Re: [HELP] Player Model Animation Sometimes Stops
Reply With Quote #1

Sorry about that. It's kinda embarrassing but here it is:
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <orpheu>
#include <orpheu_stocks>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

#define TASKID_ANIMRESET 773413

new seqInitiationisAnimatingshouldStopAnimationunStuckMe// PLAYER BITWISE VARS
new g_anim_seq[33], g_anim_gait[33];

// MACROS
#define SetBits(%1,%2)    (%1 |=    1 << (%2 & 31))
#define ClearBits(%1,%2)  (%1 &= ~( 1 << (%2 & 31)))
#define FBitSet(%1,%2)    (%1 &     1 << (%2 & 31))

enum PlayerAnim
{
    
PLAYER_IDLE,
    
PLAYER_WALK,
    
PLAYER_JUMP,
    
PLAYER_SUPERJUMP,
    
PLAYER_DIE,
    
PLAYER_ATTACK1,
    
PLAYER_ATTACK1_RIGHT,
    
PLAYER_SMALL_FLINCH,
    
PLAYER_LARGE_FLINCH,
    
PLAYER_RELOAD,
    
PLAYER_HOLDBOMB
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
OrpheuRegisterHook(OrpheuGetFunction("SetAnimation""CBasePlayer"), "Player_SetAnimation"OrpheuHookPre);
}

public 
plugin_natives()
{
    
register_library("playeranim");
    
register_native("playeranim_start""Player_Anim_Start");
    
register_native("playeranim_reset""Player_Anim_Reset");
}

public 
Player_Anim_Start(pluginparam)
{
    new 
user get_param(1);
    
    if(
task_exists(TASKID_ANIMRESET user))
        return
    
    
g_anim_seq[user] = get_param(2);
    
g_anim_gait[user] = get_param(3);
    new 
Float:anim_time get_param_f(4);

    if(
anim_time 0)
        
set_task(anim_time"Task_Anim_Reset"TASKID_ANIMRESET user);
    
    
SetBits(isAnimatinguser);
    
ClearBits(seqInitiationuser);
}

public 
Task_Anim_Reset(taskid)
{
    new 
user taskid TASKID_ANIMRESET;
    
ClearBits(isAnimatinguser);
    
SetBits(unStuckMeuser);
}

public 
Player_Anim_Reset(pluginparam)
{
    new 
user get_param(1);
    
    
ClearBits(isAnimatinguser);
    
SetBits(unStuckMeuser);
    
    if(
task_exists(TASKID_ANIMRESET user))
        
remove_task(TASKID_ANIMRESET user);
}

public 
OrpheuHookReturn:Player_SetAnimation(const user, const anim)
{
    if(!
is_user_alive(user) || !FBitSet(isAnimatinguser) || PlayerAnim:anim == PLAYER_DIE)
        return 
OrpheuIgnored;
    
    if(
pev(userpev_waterlevel ) > 1)
        return 
OrpheuIgnored;
    
    if(!
FBitSet(seqInitiationuser))
    {
        
// It needs to initiniate one time the animation.
        // The engine will do what it needs to increse the frame and such.
        
        
InitiateSequence (userg_anim_seq[user], g_anim_gait[user]);
        
SetBits(seqInitiationuser);
    }
    else
    {
        new 
playerMoving IsMoving(user);
        new 
shouldUpdate playerMoving FBitSet(shouldStopAnimationuser);
        
        if(
shouldUpdate)
        {
            
playerMoving SetBits(shouldStopAnimationuser) : ClearBits(shouldStopAnimationuser);
            
UpdateAnimationState(user, .animationState playerMoving);
        }
    }
    
    return 
OrpheuSupercede;
}

// Update the animation state.
// Basically if it needs to be stopped or resumed.
// @param player           The player's index.
// @param animationState   0 - stop the animation, 1 - resume it.
UpdateAnimationState ( const user, const animationState )
{
    
set_pev(userpev_frameratefloat(animationState));
}

// Initialize the animation.
// So the engine will do the job properly automatically.
// @param player           The player's index.
// @param sequence         The sequence to be initiated.
InitiateSequence(const userseqgait)
{
    if(
gait 0set_pev(userpev_gaitsequencegait);
    if(
seq 0set_pev(userpev_sequenceseq);
    
set_pev(userpev_frame0);
    
set_pev(userpev_blending_00);
    
set_pev(userpev_blending_10);
    
    
ResetSequenceInfo(user);
}

stock bool:IsMoving(const user)
{
    
#define Length2D(%0) (floatsqroot (%0[0] * %0[0] + %0[1] * %0[1]))
    
    
static Float:velocity[3];
    
pev(userpev_velocityvelocity);
    
    return 
Length2D(velocity) > 0;
}

// Reset the sequence properly before be initiated.
// @param player           The player's index.
stock ResetSequenceInfo(const user)
{
    static 
OrpheuFunction:handleResetSequenceInfo;
    
    if ( !
handleResetSequenceInfo )
        
handleResetSequenceInfo OrpheuGetFunction"ResetSequenceInfo""CBaseAnimating" );

    
OrpheuCallhandleResetSequenceInfouser );

I got it from ArkShine's Prone Position. I converted it into something that any plugin can call upon to play animations. Since I'm still not familiar with Orpheu I don't know half of the things I'm doing...
__________________
hellmonja is offline
Reply



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 17:25.


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