AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detect how far someone walked. (https://forums.alliedmods.net/showthread.php?t=126810)

drekes 05-13-2010 18:22

Detect how far someone walked.
 
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

wrecked_ 05-13-2010 18:29

Re: Detect how far someone walked.
 
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[] ) }

Exolent[jNr] 05-13-2010 18:34

Re: Detect how far someone walked.
 
I think he means more of a real distance, such as each unit walked in any direction.

fysiks 05-13-2010 18:34

Re: Detect how far someone walked.
 
Wrecked, technically that is the net displacement and not the distance "walked".

grimvh2 05-13-2010 18:59

Re: Detect how far someone walked.
 
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)
    }



wrecked_ 05-13-2010 19:09

Re: Detect how far someone walked.
 
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.

Bugsy 05-13-2010 19:17

Re: Detect how far someone walked.
 
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.

drekes 05-13-2010 19:37

Re: Detect how far someone walked.
 
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?

wrecked_ 05-13-2010 19:53

Re: Detect how far someone walked.
 
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.

drekes 05-13-2010 20:03

Re: Detect how far someone walked.
 
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.


All times are GMT -4. The time now is 23:04.

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