Raised This Month: $32 Target: $400
 8% 

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 , 02:17   [HELP] Player Model Animation Sometimes Stops
Reply With Quote #1

It's my first time using Orpheu and I'm using it to animate player models. It works but it's not consistent. Sometimes the animation gets stuck and only plays the rest when I move. But when I stand still the player model just stands there like a statue...
__________________

Last edited by hellmonja; 07-11-2019 at 13:17.
hellmonja is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-30-2019 , 03:50   Re: [HELP] Player Model Animation Sometimes Stops
Reply With Quote #2

Can you show your code or explain how you are playing animations? "Using orpheu" is not enough information.
__________________
HamletEagle is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 06-30-2019 , 04:35   Re: [HELP] Player Model Animation Sometimes Stops
Reply With Quote #3

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
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-30-2019 , 05:01   Re: [HELP] Player Model Animation Sometimes Stops
Reply With Quote #4

Problem is SetAnimation got split at some point in two functions and orpheu isn't able to deal with it properly.
However, try using this: https://forums.alliedmods.net/showpo...51&postcount=7. I'm not sure if this is the only problem in your code, but give it a try.
__________________

Last edited by HamletEagle; 06-30-2019 at 05:02.
HamletEagle is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 06-30-2019 , 08:00   Re: [HELP] Player Model Animation Sometimes Stops
Reply With Quote #5

Thank you! I will try it later...
__________________
hellmonja is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-30-2019 , 10:46   Re: [HELP] Player Model Animation Sometimes Stops
Reply With Quote #6

I forgot to mention I know for a fact the module works, because I used it for some private work.
__________________
HamletEagle is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 06-30-2019 , 20:19   Re: [HELP] Player Model Animation Sometimes Stops
Reply With Quote #7

Quote:
Originally Posted by HamletEagle View Post
I forgot to mention I know for a fact the module works, because I used it for some private work.
It works replacing the Player_SetAnimation Orpheu hook, but still freezes for me unless I move so the custom anim can play the rest. Here's what I have so far:
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))
    {
        if(
get_param(3) > 0g_anim_gait[user] = get_param(3);
        else 
g_anim_gait[user] = pev(userpev_gaitsequence);
        
        if(
get_param(2) > 0g_anim_seq[user] = get_param(2);
        else 
g_anim_seq[user]  = pev(userpev_sequence);
        
        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(isAnimating, user) || PlayerAnim:anim == PLAYER_DIE)
        return OrpheuIgnored;
    
    if(pev(user, pev_waterlevel ) > 1)
        return OrpheuIgnored;
    
    if(!FBitSet(seqInitiation, user))
    {
        // It needs to initiniate one time the animation.
        // The engine will do what it needs to increse the frame and such.
        
        InitiateSequence (user, g_anim_seq[user], g_anim_gait[user]);
        SetBits(seqInitiation, user);
    }
    else
    {
        new playerMoving = IsMoving(user);
        new shouldUpdate = playerMoving ^ FBitSet(shouldStopAnimation, user);
        
        if(shouldUpdate)
        {
            playerMoving ? SetBits(shouldStopAnimation, user) : ClearBits(shouldStopAnimation, user);
            UpdateAnimationState(user, .animationState = playerMoving);
        }
    }
    
    return OrpheuSupercede;
}
*/
public OnSetAnimation(useranim)
{
    if(!
is_user_alive(user) || !FBitSet(isAnimatinguser) || PlayerAnim:anim == PLAYER_DIE)
        return 
PLUGIN_CONTINUE
    
    
if(pev(userpev_waterlevel ) > 1)
        return 
PLUGIN_CONTINUE
    
    
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);
        return 
PLUGIN_HANDLED
    
}
    else
    {
        new 
playerMoving IsMoving(user);
        new 
shouldUpdate playerMoving FBitSet(shouldStopAnimationuser);
        
        if(
shouldUpdate)
        {
            
playerMoving SetBits(shouldStopAnimationuser) : ClearBits(shouldStopAnimationuser);
            
UpdateAnimationState(user, .animationState playerMoving);
        }
    }
    
    return 
PLUGIN_HANDLED
}

// 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)
{
    
set_pev(userpev_sequenceseq);
    
set_pev(userpev_gaitsequencegait);
    
set_pev(userpev_frame0);
    
    
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 );

It might be related to the fact that I'm trying to animate only the upper half of the player model. What I'm trying to do is playing the reload anim when the player attaches/detaches the silencer. At first it does its thing but the legs are just standing even while I'm moving. So I used pev(user, pev_gaitsequence) to try and update the lower half but it doesn't update in real time. Like if I was standing and took off the silencer and crouched mid way the legs would go thru the floor...
__________________
hellmonja is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 07-11-2019 , 13:16   Re: [HELP] Player Model Animation Sometimes Stops
Reply With Quote #8

Ah! Found the solution from a neighbor with similar problems!
https://forums.alliedmods.net/showthread.php?t=317123

In my case, all I needed was to add this line:
PHP Code:
set_pev(entpev_animtimehalflife_time()); 
Make sure you're using the engine module on your plugin for halflife_time().
Good day, everyone! Plugin working great now!...
__________________
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 02:14.


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