Calculating Player Sync Movement

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 417
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Calculating Player Sync Movement

Postby decompile » Mon May 02, 2016 4:08 pm

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;
   }
}
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Calculating Player Sync Movement

Postby iPlayer » Mon May 02, 2016 6:23 pm

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.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
decompile
Senior Member
Posts: 417
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: Calculating Player Sync Movement

Postby decompile » Sun May 22, 2016 9:46 pm

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
User avatar
Ayuto
Project Leader
Posts: 2209
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Calculating Player Sync Movement

Postby Ayuto » Sun May 22, 2016 10:11 pm

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?

Return to “Plugin Development Support”

Who is online

Users browsing this forum: Bing [Bot] and 90 guests