Raised This Month: $ Target: $400
 0% 

Detect how far someone walked.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 05-13-2010 , 19:53   Re: Detect how far someone walked.
Reply With Quote #1

Try this out:
Code:
#include <amxmodx> #include <engine> #include <hamsandwich> new Origin[33][3] new Distance[33] public plugin_init() {     register_plugin( "Distance Example", "1.0", "Wrecked" )         register_clcmd( "say /distance", "CmdDistance" )         RegisterHam( Ham_Spawn, "player", "HamSpawnPost", 1 ) } public client_connect( id ) {     Distance[id] = 0 } public client_PreThink( id ) {     if( is_user_alive( id ) )     {         static OldOrigin[3]         // xs_vec_copy( Origin[id], OldOrigin )         for( new i = 0; i < 3; i++ ) OldOrigin[i] = Origin[id][i]         get_user_origin( id, Origin[id] )                 Distance[id] += get_distance( Origin[id], OldOrigin )     } } public HamSpawnPost( id ) {     // prevent distance calculation from old origin to spawn point     get_user_origin( id, Origin[id] ) } public CmdDistance( id ) {     client_print( id, print_chat, "Distance: %d units", Distance[id] ) }

Note: I would've used xs_vec_copy, but that only works with floats, apparently.

EDIT: Added Ham_Spawn registry. Tell me if that works or not. I don't know if that's called before any frames on the client or not.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT

Last edited by wrecked_; 05-13-2010 at 20:27.
wrecked_ is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-13-2010 , 20:05   Re: Detect how far someone walked.
Reply With Quote #2

Code:
#include < amxmodx > #include < engine > #include < hamsandwich > #include < xs > const MAX_PLAYERS = 32; new const Float:vecNullOrigin[ 3 ] /*= { 0.0, 0.0, 0.0 }*/; new Float:flDistance[ MAX_PLAYERS + 1 ]; new Float:vecOldOrigin[ MAX_PLAYERS + 1 ][ 3 ]; public plugin_init( ) {     register_clcmd( "say /dist", "CmdDistance" );         RegisterHam( Ham_Spawn, "player", "FwdPlayerSpawnPost", 1 ); } public client_connect( iPlayer ) {     ResetStats( iPlayer ); } public CmdDistance( iPlayer ) {     client_print( iPlayer, print_chat, "You have walked %.3f units", flDistance[ iPlayer ] ); } public FwdPlayerSpawnPost( iPlayer ) {     if( is_user_alive( iPlayer ) )     {         ResetStats( iPlayer );     } } public client_PreThink( iPlayer ) {     if( is_user_alive( iPlayer ) )     {         new Float:vecOrigin[ 3 ];         entity_get_vector( iPlayer, EV_VEC_origin, vecOrigin );                 if( !xs_vec_equal( vecOldOrigin[ iPlayer ], vecNullOrigin ) )         {             flDistance[ iPlayer ] += get_distance_f( vecOrigin, vecOldOrigin[ iPlayer ] );         }                 xs_vec_copy( vecOrigin, vecOldOrigin[ iPlayer ] );     } } ResetStats( iPlayer ) {     flDistance[ iPlayer ] = 0.0;     xs_vec_copy( vecNullOrigin, vecOldOrigin[ iPlayer ] ); }

I've seen a unit->feet conversion or something similar on these forums before.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
IneedHelp
Veteran Member
Join Date: Mar 2007
Location: Argentina
Old 05-14-2010 , 23:27   Re: Detect how far someone walked.
Reply With Quote #3

Quote:
Originally Posted by Exolent[jNr] View Post
I've seen a unit->feet conversion or something similar on these forums before.
http://forums.alliedmods.net/showpos...40&postcount=9

I'm wondering from where did he got those values hmm
__________________
IneedHelp 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 03:38.


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