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

Detect how far someone walked.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 05-13-2010 , 18:22   Detect how far someone walked.
Reply With Quote #1

Hi,

Is there a way to detect the km of feet or whatever distance a player moved?
I've been thinking about this but couldn't figure it out
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 05-13-2010 , 18:29   Re: Detect how far someone walked.
Reply With Quote #2

Code:
#include <amxmodx> new Start[33][3] new Stop[33][3] public plugin_init() {     register_plugin( "Distance Example", "1.0", "Wrecked" )         register_clcmd( "say /start", "CmdGet" )     register_clcmd( "say /stop", "CmdShow" ) } public CmdGet( id ) {     if( is_user_alive( id ) )     {         get_user_origin( id, Start[id] )     } } public CmdShow( id ) {     if( is_user_alive( id ) )     {         get_user_origin( id, Stop[id] )         client_print( id, print_chat, "Distance: %d units", get_distance( Start[id], Stop[id] ) )     }         arrayset( Start[id], 0, sizeof Start[] )     arrayset( Stop[id], 0, sizeof Stop[] ) }
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-13-2010 , 18:34   Re: Detect how far someone walked.
Reply With Quote #3

I think he means more of a real distance, such as each unit walked in any direction.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-13-2010 , 18:34   Re: Detect how far someone walked.
Reply With Quote #4

Wrecked, technically that is the net displacement and not the distance "walked".
__________________
fysiks is offline
grimvh2
Veteran Member
Join Date: Nov 2007
Location: Fishdot Nation
Old 05-13-2010 , 18:59   Re: Detect how far someone walked.
Reply With Quote #5

Wrecked's way is using a reference point, so infact its the distance you walked away from that point. That's quite interesting, im wondering how u could do that.

this might work :

PHP Code:
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "Grim"

new Walk[33]
new 
Float:OldOrigin[3]
new 
Float:DistWalked

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say walk""startwalk")
    
register_clcmd("say stop""stopwalk")
    
RegisterHam(Ham_Player_PreThink"player""FwdPreThink")
}

public 
startwalk(id)
{
    
Walk[id]++
    
pev(id,pev_origin,OldOrigin)
}

public 
stopwalk(id)
{
    
Walk[id]=0
    client_print
(id,print_chat"%d"floatround(DistWalked))
}

public 
FwdPreThink(id)
{
    if(
Walk[id])
    {
        new 
Float:Origin[3]
        
pev(id,pev_origin,Origin)
        
        
DistWalked get_distance_f(OldOriginOrigin)
        
        
pev(id,pev_origin,OldOrigin)
    }

__________________
I am out of order!

Last edited by grimvh2; 05-13-2010 at 19:08.
grimvh2 is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 05-13-2010 , 19:09   Re: Detect how far someone walked.
Reply With Quote #6

Knowing drekes, I was thinking he only needed a way to get the distance and a small example, rather than me explain the entire thing to him. Sorry if that was too general, but the above method that I posted should lead him on the right track.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-13-2010 , 19:17   Re: Detect how far someone walked.
Reply With Quote #7

Just get origin of start pos and end pos then use get_distance. If you want to log literally every step walked then you will need more code. Explain further exactly what you want.
__________________
Bugsy is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 05-13-2010 , 19:37   Re: Detect how far someone walked.
Reply With Quote #8

What i'm trying to achieve, is the distance travelled by a player, i'm working on a achievement plugin, and i wanted to add something like "Travelled x distance.", so it should check every step he makes. I was thinking about setting a task every seconds, but that won't be the best way to do it.

it's actually like Exolent[jNr] said, getting every unit, the direction doesn't matter.

And i'm gonna see if i can find some info about Prethink like in grimvh2's example.

Thanks.

EDIT: I don't really understand the info about Prethink in ham_const.inc, but if i use fakemeta and get the direction that he is walking, i can know when he is walking, and if i can get speed, like the speedometer code, i should be able to calculate the distance right?
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.

Last edited by drekes; 05-13-2010 at 19:41.
drekes is offline
Send a message via MSN to drekes
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 #9

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
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 05-13-2010 , 20:03   Re: Detect how far someone walked.
Reply With Quote #10

Thanks guys, does someone know how many feet or meter 1 unit is? Or isn't this done in-game. Cause it would be fun to see how many miles or kilometer you travelled.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
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 06:39.


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