AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detect player moving (https://forums.alliedmods.net/showthread.php?t=156057)

xbatista 04-30-2011 11:51

Detect player moving
 
I don't know how to detect if player runs or walks ( not including IN_JUMP IN_FORWARD etc.. ) , can someone give me advise? :)

xbatista 04-30-2011 11:54

Re: Detect player moving
 
Ohh I can detect it by player's velocity :) :crab:

Bugsy 04-30-2011 13:40

Re: Detect player moving
 
You can hook CmdStart for when IN_JUMP/IN_FORWARD/IN_WHATEVER are being used for checking velocity (instead of prethink).

hleV 04-30-2011 15:03

Re: Detect player moving
 
Best efficient way I could think of.
Code:
#include <fun>   #define MOVEMENT_CHECK_INTERVAL 5.0   new bool:IsMoving[33];   public plugin_init()         set_task(MOVEMENT_CHECK_INTERVAL, "TaskCheckIfMoved", _, _, _, "b");   public TaskCheckIfMoved() {         static oldOrigin[33][3];         new players[32];         new num;           get_players(players, num, "a");           for (new i, id, newOrigin[3]; i < num; i++)         {                 id = players[i];                   get_user_origin(id, newOrigin);                   IsMoving[id] = bool:(newOrigin[0] != oldOrigin[id][0] || newOrigin[1] != oldOrigin[id][1]);         } }

fysiks 04-30-2011 15:08

Re: Detect player moving
 
That does not detect if someone is moving. That detects if someone has moved (in the last 5 seconds). Totally different.

hleV 04-30-2011 15:10

Re: Detect player moving
 
Right.

xbatista 04-30-2011 17:22

Re: Detect player moving
 
Thanks guys, but I think the best way is to use engine function: get_speed(id) > 0

hleV 04-30-2011 18:20

Re: Detect player moving
 
Quote:

Originally Posted by xbatista (Post 1460887)
Thanks guys, but I think the best way is to use engine function: get_speed(id) > 0

It returns 0 when player doesn't move? That would be great.

Bugsy 04-30-2011 18:45

Re: Detect player moving
 
Quote:

Originally Posted by xbatista (Post 1460887)
Thanks guys, but I think the best way is to use engine function: get_speed(id) > 0

PHP Code:

#include <amxmodx>
#include <fakemeta>

new const Version[] = "0.1";

const 
ButtonBits = ( IN_FORWARD IN_BACK IN_MOVELEFT IN_MOVERIGHT );

const 
Float:SlowestRun 210.0//vector_length(velocity) returns 210 when running with AWP

public plugin_init() 
{
    
register_plugin"Detect Moving" Version "bugsy" );
    
    
register_forwardFM_CmdStart "fw_FMCmdStart" );
}

public 
fw_FMCmdStartid handle seed )
{
    if ( 
get_uchandle UC_Buttons ) & ButtonBits )
    {
        static 
Float:fVelocity];

        
pevid pev_velocity fVelocity );
        
client_printid print_chat "You are %s" , ( vector_lengthfVelocity ) >= SlowestRun ) ? "running" "walking" );
    }



SonicSonedit 04-30-2011 19:47

Re: Detect player moving
 
xbatista
The best way is well known: check velocity on prethink.

Bugsy
This will not detect player movement, unless player will press a button.


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

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