AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Player walk distance (https://forums.alliedmods.net/showthread.php?t=240167)

spag 05-10-2014 06:05

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

jok 05-10-2014 07:13

Re: Player walk distance
 
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.

Backstabnoob 05-10-2014 08:19

Re: Player walk distance
 
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.

spag 05-17-2014 13:11

Re: Player walk distance
 
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?

Backstabnoob 05-17-2014 13:23

Re: Player walk distance
 
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.

Bugsy 05-17-2014 22:11

Re: Player walk distance
 
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;
        }
    }



spag 05-18-2014 12:42

Re: Player walk distance
 
Quote:

Originally Posted by Bugsy (Post 2139251)
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?

Bugsy 05-18-2014 14:38

Re: Player walk distance
 
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.


All times are GMT -4. The time now is 09:42.

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