Raised This Month: $ Target: $400
 0% 

Player walk distance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
spag
Junior Member
Join Date: Feb 2013
Old 05-10-2014 , 06:05   Player walk distance
Reply With Quote #1

I have one good idea, and i need to get player walk distance, but how get it?

Last edited by spag; 05-10-2014 at 06:06.
spag is offline
jok
Member
Join Date: Sep 2013
Old 05-10-2014 , 07:13   Re: Player walk distance
Reply With Quote #2

What do you mean player walk distance?

Distance from one origin to another?

If so you can use get_distance for integers or get_distance_f for float.
jok is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-10-2014 , 08:19   Re: Player walk distance
Reply With Quote #3

How often do you want to check for distance moved? Just create a constantly looping set_task or thinking entity, create a static variable that holds the origin from last call, global variable that holds the total walk distance and use get_distance_f. Something like this:

PHP Code:
// should limit the distance somehow in case the player gets teleported back to spawn
#define DISTANCE_MAX 100.0

#define LOOP_TIMER 1.0

new Floatg_fTotalDistanceWalked33 ]

set_taskLOOP_TIMER"_tCycle", .flags "b" )

public 
_tCycle( )
{
    new 
aPlayers32 ], iNumid
    
    
static Floats_fLastOrigin33 ][ ]
    new 
FloatfCurrentOrigin]
    
    new 
FloatfDistance
    
    get_players
aPlayersiNum"a" )
    
    for( new 
iiNum++ )
    {
        
id aPlayers]
        
        
entity_get_vectoridEV_VEC_originfCurrentOrigin )
        
        if( 
s_fLastOriginid ] != 0.0 )
        {    
            
fDistance get_distance_fs_fLastOriginid ], fCurrentOrigin )
            
            if( 
fDistance DISTANCE_MAX )
            {
                
g_fTotalDistanceWalked33 ] += fDistance
            
}
        }
            
        
xs_vec_copyfCurrentOrigins_fLastOriginid ] )
    }

Thinking entity would probably be better but I don't feel like writing it.

Last edited by Backstabnoob; 05-10-2014 at 08:21.
Backstabnoob is offline
spag
Junior Member
Join Date: Feb 2013
Old 05-17-2014 , 13:11   Re: Player walk distance
Reply With Quote #4

I want to get it always when player is on ground. I don't know, but maybe should get with FwdPreFrame_Post ? Can you give me example?
spag is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-17-2014 , 13:23   Re: Player walk distance
Reply With Quote #5

I have no idea what FwdPreFrame_Post is, but just use the code I posted, it's enough for what you want to do. Think is called unnecessarily too often.
Backstabnoob is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-17-2014 , 22:11   Re: Player walk distance
Reply With Quote #6

This will display distance walked and reset to 0 when the player either presses jump or is not on the ground for whatever reason (walks off ledge etc).

If this isn't what you want, it can be tweaked.
  • Did you want to reset distance if player runs?
  • Did you not want to reset if player walks off ledge etc and only reset when manually jumping?
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <xs>

new const Version[] = "0.1";

new 
Float:g_fDistance33 ] , bool:g_bWasOffGround33 ];

public 
plugin_init()
{
    
register_plugin"Get Distance on Ground" Version "bugsy" );

    
register_forwardFM_CmdStart "fw_FMCmdStart" );
}

public 
client_putinserverid )
{
    
g_bWasOffGroundid ] = true;
    
g_fDistanceid ] = 0.0;
    
    
set_task1.0 "ShowDistance" id , .flags="b" );
}

public 
ShowDistanceid )
{
    
client_printid print_center "Distance walked = %f" g_fDistanceid ] );
}

public 
fw_FMCmdStartid handle seed )
{
    static 
Float:fLastOrigin33 ][ ] , Float:fCurrentOrigin] , iButtons;
    
    
iButtons get_uchandle UC_Buttons );
    
    if ( 
iButtons IN_JUMP )
    {
        
g_fDistanceid ] = 0.0;
        
g_bWasOffGroundid ] = true;
    }
    else if ( 
iButtons & ( IN_FORWARD IN_BACK IN_MOVELEFT IN_MOVERIGHT ) )
    {
        if ( 
pevid pev_flags ) & FL_ONGROUND )
        {
            if ( 
g_bWasOffGroundid ] == true )
            {    
                
pevid pev_origin fLastOriginid ] );
                
                
g_fDistanceid ] = 0.0;
                
g_bWasOffGroundid ] = false;
            }
            else
            {
                
pevid pev_origin fCurrentOrigin );
                
                if ( !
xs_vec_equalfLastOriginid ] , fCurrentOrigin ) )
                {
                    
g_fDistanceid ] += get_distance_ffLastOriginid ] , fCurrentOrigin );
                    
xs_vec_copyfCurrentOrigin fLastOriginid ] );
                }
            }
        }
        else
        {
            
g_bWasOffGroundid ] = true;
        }
    }

__________________

Last edited by Bugsy; 05-17-2014 at 22:25.
Bugsy is offline
spag
Junior Member
Join Date: Feb 2013
Old 05-18-2014 , 12:42   Re: Player walk distance
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
This will display distance walked and reset to 0 when the player either presses jump or is not on the ground for whatever reason (walks off ledge etc).

If this isn't what you want, it can be tweaked.
  • Did you want to reset distance if player runs?
  • Did you not want to reset if player walks off ledge etc and only reset when manually jumping?
Nope, i wont reset distance when player jump. But it doesn't matter.
Look, with this code, i get distance when

1) Player walk with button W + SHITF
2) Player walk only with button W
3) Player walk when are SQUAT
4) Player walk when SQUAT + SHITF
5) Player swimming?

If yes, so everything okay! But i have another question, when player surfing or use bhop still get distance?

Last edited by spag; 05-18-2014 at 13:33.
spag is offline
Old 05-18-2014, 13:32
spag
This message has been deleted by spag.
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-18-2014 , 14:38   Re: Player walk distance
Reply With Quote #8

1) Player walk with button W + SHITF - Good
2) Player walk only with button W - Good
3) Player walk when are SQUAT - Good
4) Player walk when SQUAT + SHITF - Good
5) Player swimming? - I dont know, check to see if FL_ONGROUND is set when swimming. If so then good.

If yes, so everything okay! But i have another question, when player surfing or use bhop still get distance? - Surfing idk, see response #5 above. bhop no because he is off the ground.
__________________
Bugsy 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 09:42.


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