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

Player walk distance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 01-27-2013 , 07:08   Player walk distance
Reply With Quote #1

How would you make a function that gets called for example each time player walks 100 units? I've tried saving their old origin and comparing it to the new in a task, but that is not a great solution as when the player falls, uses teleport of any kind or something similar, it shows greatly incorrect values.

I'm creating an achievement that gets unlocked after player moves 50000 units, therefore this should be called each 100 units so I can save accordingly.

Thanks in advance.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 01-28-2013 , 08:50   Re: Player walk distance
Reply With Quote #2

Heres how I did it a while back, if it's of any help (you get the idea, it's pretty self-explanatory);

Code:
#define UnitsToMeters(%1) ( %1 * 0.0254 ) const FL_ONGROUND2 = ( FL_ONGROUND | FL_PARTIALGROUND | FL_INWATER | FL_CONVEYOR | FL_FLOAT ); new Float:Meters[ MaxClients + 1 ]; new Float:OldOrigin[ MaxClients + 1 ][ VectorSize ]; new bool:OnSurf[ MaxClients + 1 ]; // plugin_init register_forward( FM_PlayerPreThink, "Forward_FMPlayerPreThink" ); register_forward( FM_Touch, "Forward_FMTouch" ); public Forward_FMPlayerPreThink( Client ) {     if( !is_user_alive( Client ) || AchievementCompleted[ Client ][ _Runner ] )     {         return;     }         new Float:Origin[ VectorSize ], Float:Gravity;     new bool:OnGround = IsUserOnGround( Client );         if( OnSurf[ Client ] )     {         OnSurf[ Client ] = false;                 return;     }         pev( Client, pev_origin, Origin );     pev( Client, pev_gravity, Gravity );         if( ( pev( Client, pev_movetype ) != MOVETYPE_WALK )     || ( Gravity != 1.0 )     || ( pev( Client, pev_waterlevel ) > 0 )     || ( OldOrigin[ Client ][ 0 ] == Origin[ 0 ] && OldOrigin[ Client ][ 1 ] == Origin[ 1 ] && OldOrigin[ Client ][ 2 ] == Origin[ 2 ] ) )     {         return;     }         if( OnGround )     {         Meters[ Client ] += get_distance_f( Origin, OldOrigin[ Client ] );                 pev( Client, pev_origin, OldOrigin[ Client ] );                 //client_print( Client, print_chat, "debug: on ground %f %f", UnitsToMeters( floatround( Meters[ Client ] ) ), Meters[ Client ] );                 if( ( UnitsToMeters( floatround( Meters[ Client ] ) ) >= 50000 ) && !AchievementCompleted[ Client ][ _Runner ] )         {             ForwardAchievementStatus( Client, _Runner );         }     } } public Forward_FMTouch( Player, Entity ) {     if( ( 1 <= Player <= MaxPlayers ) && !IsUserOnGround( Entity ) )     {         OnSurf[ Player ] = true;     }         if( ( 1 <= Entity <= MaxPlayers ) && !IsUserOnGround( Entity ) )     {         OnSurf[ Entity ] = true;     } } bool:IsUserOnGround( Client ) {     return !!( pev( Client, pev_flags ) & FL_ONGROUND2 ); }
__________________
Achievements API - a simple way for you to create your OWN custom achievements!

Last edited by Xellath; 01-28-2013 at 08:51.
Xellath is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 01-28-2013 , 11:55   Re: Player walk distance
Reply With Quote #3

Thanks, however that doesn't solve the problem with things such as teleports. Checking whether the difference in origins is higher than X should work though, as it's called too often.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
AngeIII
Senior Member
Join Date: Sep 2007
Location: Latvia
Old 01-28-2013 , 12:17   Re: Player walk distance
Reply With Quote #4

store as static value oldorigins
and before do increement check if distance(old origin,new origin)<=10
if yes you can increement
if no do nothing..
__________________
skype: pavle_ivanof
-=ThQ=-
PRIVATE SUPPORT = PAID SUPPORT
AngeIII is offline
Send a message via Skype™ to AngeIII
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 01-28-2013 , 12:17   Re: Player walk distance
Reply With Quote #5

That's exactly what I've just said.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-28-2013 , 12:57   Re: Player walk distance
Reply With Quote #6

you can do it with task instead of using prethink like this:
PHP Code:
#define MAX_SPEED 320.0

#define UPDATE_INTERVAL 0.1
#define TID_TIMER 350983

new Float:g_p_distance[33]

public 
plugin_init(){
    
set_task(UPDATE_INTERVAL"timer_cycle"TID_TIMER__"b")    
}

public 
client_disconnect(id){
    
//save distance...
    
    
g_p_distance[id] = 0.0
}

public 
timer_cycle(){
    static 
players[32], pnumplayer_idFloat:p_last_origin[33][3], Float:tmp_origin[3], Float:tmp_distance
    get_players
(playerspnum)
    for(new 
i=0i<pnumi++){
        
player_id players[i]
        if(!
is_user_alive(player_id))
            continue
        
pev(player_idpev_origintmp_origin)
        
tmp_origin[player_id][2] = 0.0
        tmp_distance 
get_distance_f(tmp_originp_last_origin[player_id])
        if(
tmp_distance MAX_SPEED UPDATE_INTERVAL)
            
g_p_distance[player_id] += tmp_distance
        p_last_origin
[player_id][0] = tmp_origin[0]
        
p_last_origin[player_id][1] = tmp_origin[1]
    }    

__________________
Impossible is Nothing
Sylwester is offline
AngeIII
Senior Member
Join Date: Sep 2007
Location: Latvia
Old 01-28-2013 , 13:11   Re: Player walk distance
Reply With Quote #7

task for loop through 32 players... every 0.1 seconds?
.. witch uses 5-6natives?

better to use one more variable and native get_time(halftime)..
but why not to use only origins..
__________________
skype: pavle_ivanof
-=ThQ=-
PRIVATE SUPPORT = PAID SUPPORT
AngeIII is offline
Send a message via Skype™ to AngeIII
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 01-28-2013 , 13:30   Re: Player walk distance
Reply With Quote #8

Quote:
task for loop through 32 players... every 0.1 seconds?
That's still about 6x less than using PreThink.

@Sylwester: Thank you, this is exactly what I need.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-28-2013 , 13:40   Re: Player walk distance
Reply With Quote #9

Quote:
Originally Posted by AngeIII View Post
better to use one more variable and native get_time(halftime)..
but why not to use only origins..
What?
__________________
Impossible is Nothing

Last edited by Sylwester; 01-28-2013 at 13:40.
Sylwester is offline
AngeIII
Senior Member
Join Date: Sep 2007
Location: Latvia
Old 01-28-2013 , 15:34   Re: Player walk distance
Reply With Quote #10

if(timedifference(current,old)<0.1) skip;
else
{
....
calculate meters
old_time=current.
}
__________________
skype: pavle_ivanof
-=ThQ=-
PRIVATE SUPPORT = PAID SUPPORT
AngeIII is offline
Send a message via Skype™ to AngeIII
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 03:21.


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