Page 1 of 1

Calculating Player Sync Movement

Posted: Mon May 02, 2016 4:08 pm
by decompile
Hey Guys,

How can you calculate players movement sync with SP?

Its pretty simple with SourcePawn

Code: Select all

#include <sourcemod>
#include <sdktools>

float g_fOldAngle[MAXPLAYERS+1];
int gi_TotalTicks[MAXPLAYERS+1];
int gi_SyncedTicks[MAXPLAYERS+1];

public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon, &subtype, &cmdnum, &tickcount, &seed, mouse[2])
{
   //Getting the angle differnce
   new Float:fAngleDiff = angles[1] - g_fOldAngle[client];
   //fixing the angle differnce to positive value
   if (fAngleDiff > 180)
   {
      fAngleDiff -= 360;   
   }
   else if (fAngleDiff < -180)
   {
      fAngleDiff += 360;
   }

   //Checking for mouse movement
   if(fAngleDiff > 0) //mouse moving left
   {
      gi_TotalTicks[client]++;

      if(buttons & IN_MOVELEFT) //if player pressing A
      {
         gi_SyncedTicks[client]++;
      }
   }
   else if(fAngleDiff < 0) //mouse moving right
   {
      gi_TotalTicks[client]++;

      if(buttons & IN_MOVERIGHT) //if player pressing D
      {
         gi_SyncedTicks[client]++;
      }
   }
}

public float CalcSync(client)
{
   //avoiding throwing error: cannot divide 0
   if(gi_TotalTicks[client] > 0)
   {
      return (float(gi_SyncedTicks[client]) / gi_TotalTicks[client])*100.0;
   }
   else
   {
      return 0.0;
   }
}

Re: Calculating Player Sync Movement

Posted: Mon May 02, 2016 6:23 pm
by iPlayer
Does the above code even work? You never update g_fOldAngle.

Also, what's the point of doing all these += 360, -= 360 if in the end all you do is compare it to zero? Can the angle difference equal, say, -540 degrees? After your "fixing the angle difference to positive value" it still will be -180 degrees.

Re: Calculating Player Sync Movement

Posted: Sun May 22, 2016 9:46 pm
by decompile
I just quick checked the code and It looked like it work, jsut found it from the sourcemod forums. Would be great to find a sp version of that

Re: Calculating Player Sync Movement

Posted: Sun May 22, 2016 10:11 pm
by Ayuto
All you need is a PlayerRunCommand hook, which you already know how to create:
viewtopic.php?f=20&t=1019&p=6775&hilit=run_command#p6775

Where exactly do you need help?