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

Detect maximum speed in a run?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bLacK-bLooD
AlliedModders Donor
Join Date: Jun 2008
Old 09-07-2018 , 08:53   Detect maximum speed in a run?
Reply With Quote #1

Hi,

I own a kreedz server and from the moment a player starts its run until he finishes, I would like to detect the maximum speed the player achieved during the run.

I have a start climb and end climb function, I just need to know how to store the climber's highest speed and show it at the end of the climb.

I am thinking:
  • create a task at start_climb to run every 5 seconds
  • get the current speed of the climber
  • store the new one if higher

The downside of that is during the 5 seconds he might have had a higher speed and I didn't catch that.

What would be the best way to do it/most performant way to do it?

Thank you!
__________________
We all live under the same sky but we have different horizons.
bLacK-bLooD is offline
Garey
Member
Join Date: Feb 2008
Location: Russian Federation
Old 09-08-2018 , 19:18   Re: Detect maximum speed in a run?
Reply With Quote #2

Quote:
Originally Posted by bLacK-bLooD View Post
Hi,

I own a kreedz server and from the moment a player starts its run until he finishes, I would like to detect the maximum speed the player achieved during the run.

I have a start climb and end climb function, I just need to know how to store the climber's highest speed and show it at the end of the climb.

I am thinking:
  • create a task at start_climb to run every 5 seconds
  • get the current speed of the climber
  • store the new one if higher

The downside of that is during the 5 seconds he might have had a higher speed and I didn't catch that.

What would be the best way to do it/most performant way to do it?

Thank you!
Just capture speed in PreThink? in kreedz-world there ljstats what a do many more calculations in prethink so...
__________________
Sorry for my bad english

Last edited by Garey; 09-08-2018 at 19:18.
Garey is offline
Send a message via ICQ to Garey
JocAnis
Veteran Member
Join Date: Jun 2010
Old 09-08-2018 , 19:59   Re: Detect maximum speed in a run?
Reply With Quote #3

yes check it in prethink...task in 5 secs will probably miss something, prethink is called in every 0,001 sec if im not mistaken
JocAnis is offline
bLacK-bLooD
AlliedModders Donor
Join Date: Jun 2008
Old 09-09-2018 , 02:01   Re: Detect maximum speed in a run?
Reply With Quote #4

Thanks for the answere guys.

I ended up using Ham_Think on “player”, because it’s better performance wise than FM_Think, since it’s only called on players, not on all entities.
__________________
We all live under the same sky but we have different horizons.

Last edited by bLacK-bLooD; 09-09-2018 at 02:02.
bLacK-bLooD is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-09-2018 , 14:41   Re: Detect maximum speed in a run?
Reply With Quote #5

PreThink is overkill for this, use a thinking entity with a 0.1-0.3 interval to check speed.

The below will determine a players max run speed. To test, say 'start', run around, and then say 'end'.

PHP Code:

#include <amxmodx>
#include <engine>

new const Version[] = "0.1";

#define MAX_PLAYERS 32

const Float:SpeedCheckInterval 0.2;

new 
Float:g_fMaxSpeedMAX_PLAYERS ] , g_Entity g_PlayersInClimb;

public 
plugin_init() 
{
    
register_plugin"Get Max Speed" Version "bugsy" );
    
    
g_Entity create_entity"info_target" );
    
entity_set_stringg_Entity EV_SZ_classname "speed_entity" );
    
register_think"speed_entity" "EntityThink" );

    
register_clcmd"say start" "ClimbStart" );
    
register_clcmd"say end" "ClimbEnd" );
}

public 
ClimbStartid )
{
    if ( !
g_PlayersInClimb )
    {
        
entity_set_floatg_Entity EV_FL_nextthink , ( get_gametime() + SpeedCheckInterval ) );
    }
    
    
g_PlayersInClimb |= ( << ( id 31 ) );
    
    
g_fMaxSpeedid ] = 0.0;
}

public 
ClimbEndid )
{
    
g_PlayersInClimb &= ~( << ( id 31 ) );
    
    
client_printid print_chat "Max speed (units/second) = %f" g_fMaxSpeedid ] );
}

public 
EntityThinkiEntity )
{
    new 
iPlayers32 ] , iNum Float:fVecVelocity] , Float:fSpeed;
    
    if( 
iEntity == g_Entity 
    {
        
get_playersiPlayers iNum "ah" );
        
        for ( new 
id iNum i++ )
        {
            
id iPlayers];
            
            if ( 
g_PlayersInClimb & ( << ( id 31 ) ) )
            {
                
entity_get_vectorid EV_VEC_velocity fVecVelocity );
                
fSpeed floatsqrootfloatpowerfVecVelocity] , 2.0 ) + floatpowerfVecVelocity] , 2.0 ) );
                
                if ( 
fSpeed g_fMaxSpeedid ] )
                {
                    
g_fMaxSpeedid ] = fSpeed;
                }
            }
        }
    }
    
    if ( 
g_PlayersInClimb )
    {
        
entity_set_floatg_Entity EV_FL_nextthink , ( get_gametime() + SpeedCheckInterval ) );
    }

__________________
Bugsy is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-09-2018 , 15:11   Re: Detect maximum speed in a run?
Reply With Quote #6

It's really not overkill, in KreedZ world (supposedly this is for KreedZ) you want to be frame perfect with stats.
__________________
klippy is offline
bLacK-bLooD
AlliedModders Donor
Join Date: Jun 2008
Old 09-09-2018 , 15:12   Re: Detect maximum speed in a run?
Reply With Quote #7

Yes, it is for kreedz, therefore it must be frame perfect with stats.

Should I therefore use Bugsy's approach or use Ham_Think on player?
__________________
We all live under the same sky but we have different horizons.
bLacK-bLooD 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:26.


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