Raised This Month: $51 Target: $400
 12% 

Solved [HELP] How can i get clients speed (Units per second)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ReeZey
Junior Member
Join Date: Jun 2017
Location: $_GET['location'];
Old 09-15-2017 , 13:48   [HELP] How can i get clients speed (Units per second)
Reply With Quote #1

how can i print the current speed of a player into a SPEED counter in a custom hud

Last edited by ReeZey; 02-08-2018 at 05:28. Reason: Solved
ReeZey is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 09-15-2017 , 15:04   Re: [HELP] How can i get clients speed (Units per second)
Reply With Quote #2

With vector_length and pass the player's velocity as parameter.

Last edited by KiLLeR.; 09-15-2017 at 15:06.
KiLLeR. is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-16-2017 , 14:12   Re: [HELP] How can i get clients speed (Units per second)
Reply With Quote #3

PHP Code:
#include <amxmodx>
#include <fakemeta>

new const Version[] = "0.1";

#define MAX_PLAYERS 32

new bool:g_bTaskSet Float:fPrevOriginMAX_PLAYERS ][ ];

public 
plugin_init() 
{
    
register_plugin"Units per Second" Version "bugsy" );
    
    
register_logevent"RoundStart" "1=Round_Start" ); 
}


public 
RoundStart()
{
    new 
iPlayers32 ] , iNum;
    
    
get_playersiPlayers iNum "ach" );
    
    if ( 
iNum )
    {
        for ( new 
iNum i++ )
        {
            
arrayset_:fPrevOriginiPlayers] ] , );
        }
        
        if ( !
g_bTaskSet )
        {
            
set_task1.0 "GetUPS" 0b11101011011 , .flags="b" );
            
g_bTaskSet true;
        }
    }
    else if ( 
g_bTaskSet )
    {
        
remove_task0b11101011011 );
        
g_bTaskSet false;
    }
}

public 
GetUPS()
{
    new 
iPlayers32 ] , iNum id Float:fCurOrigin];
    
    
get_playersiPlayers iNum "ach" );
    
    if ( 
iNum )
    {
        for ( new 
iNum i++ )
        {
            
id iPlayers];
            
            
pevid pev_origin fCurOrigin );
                
            if ( 
fPrevOriginid ][ ] )
            {    
                
client_printid print_chat "* You are traveling %d units per second" floatroundget_distance_ffPrevOriginid ] , fCurOrigin ) ) ); 
            }
            
            
fPrevOriginid ][ ] = fCurOrigin];
            
fPrevOriginid ][ ] = fCurOrigin];
            
fPrevOriginid ][ ] = fCurOrigin];
        }
    }

__________________
Bugsy is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 09-16-2017 , 14:19   Re: [HELP] How can i get clients speed (Units per second)
Reply With Quote #4

@Bugsy, why not just use 0 as task id? (default param value)
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-16-2017 , 16:21   Re: [HELP] How can i get clients speed (Units per second)
Reply With Quote #5

Quote:
Originally Posted by PRoSToTeM@ View Post
@Bugsy, why not just use 0 as task id? (default param value)
Because idk, lol. Does it really matter 0 vs non-zero?

Also, OP, I realized this is only giving you how far he has traveled in the past 1 second which is probably not what you want. Are you looking for an overall average distance per second?

Here's average units per second, with HUD.
PHP Code:

#include <amxmodx>
#include <fakemeta>

new const Version[] = "0.2";

#define MAX_PLAYERS 32

enum DistanceData
{
    
DistanceTraveled,
    
ReadingsTaken
}

new 
bool:g_bTaskSet Float:fPrevOriginMAX_PLAYERS ][ ];
new 
g_PlayerDataMAX_PLAYERS ][ DistanceData ];

public 
plugin_init() 
{
    
register_plugin"Average Units per Second" Version "bugsy" );
    
    
register_logevent"RoundStart" "1=Round_Start" ); 
}


public 
RoundStart()
{
    new 
iPlayers32 ] , iNum id;
    
    
get_playersiPlayers iNum "ach" );
    
    if ( 
iNum )
    {
        for ( new 
iNum i++ )
        {
            
id iPlayers];
            
            
g_PlayerDataid ][ DistanceTraveled ] = 0;
            
g_PlayerDataid ][ ReadingsTaken ] = 0;
            
arrayset_:fPrevOriginid ] , sizeoffPrevOrigin[] ) );
        }
        
        if ( !
g_bTaskSet )
        {
            
set_task1.0 "GetUPS" 0b11101011011 , .flags="b" );
            
g_bTaskSet true;
        }
    }
    else if ( 
g_bTaskSet )
    {
        
remove_task0b11101011011 );
        
g_bTaskSet false;
    }
}

public 
GetUPS()
{
    new 
iPlayers32 ] , iNum id Float:fCurOrigin];
    
    
get_playersiPlayers iNum "ach" );
    
    if ( 
iNum )
    {
        for ( new 
iNum i++ )
        {
            
id iPlayers];
            
            
pevid pev_origin fCurOrigin );
            
            if ( 
fPrevOriginid ][ ] )
            {    
                
g_PlayerDataid ][ DistanceTraveled ] += floatroundget_distance_ffPrevOriginid ] , fCurOrigin ) );
                
g_PlayerDataid ][ ReadingsTaken ]++;
                
                
set_hudmessage255 , -1.0 0.4 0.0 0.9 );
                
show_hudmessageid "%d units/sec" g_PlayerDataid ][ DistanceTraveled ] / g_PlayerDataid ][ ReadingsTaken ] );
                
                
//client_print( id , print_chat , "* You are traveling approximately %d units per second. [%d,%d]" , g_PlayerData[ id ][ DistanceTraveled ] / g_PlayerData[ id ][ ReadingsTaken ] , g_PlayerData[ id ][ ReadingsTaken ] , g_PlayerData[ id ][ DistanceTraveled ] ); 
            
}
            
            
fPrevOriginid ][ ] = fCurOrigin];
            
fPrevOriginid ][ ] = fCurOrigin];
            
fPrevOriginid ][ ] = fCurOrigin];
        }
    }

__________________

Last edited by Bugsy; 09-16-2017 at 17:42.
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 18:16.


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