Advertisement
Guest User

GetTickCountDifference

a guest
Jul 31st, 2015
1,141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // By Southclaw (taken from https://github.com/Southclaw/ScavengeSurvive/blob/master/gamemodes/SS/utils/tickcountfix.pwn)
  2.  
  3. stock abs(int)
  4. {
  5.     if(int < 0)
  6.         return -int;
  7.  
  8.     return int;
  9. }
  10.  
  11. stock intdiffabs(tick1, tick2)
  12. {
  13.     if(tick1 > tick2)
  14.         return abs(tick1 - tick2);
  15.  
  16.     else
  17.         return abs(tick2 - tick1);
  18. }
  19.  
  20. stock GetTickCountDifference(a, b)
  21. {
  22.     if ((a < 0) && (b > 0))
  23.     {
  24.  
  25.         new dist;
  26.  
  27.         dist = intdiffabs(a, b);
  28.  
  29.         if(dist > 2147483647)
  30.             return intdiffabs(a - 2147483647, b - 2147483647);
  31.  
  32.         else
  33.             return dist;
  34.     }
  35.  
  36.     return intdiffabs(a, b);
  37. }
  38.  
  39.  
  40. // Example of usage by http://forum.sa-mp.com/member.php?u=218502 (NOT TO BE USED WITH ANYTHING):
  41.  
  42. static
  43.     LastShot[MAX_PLAYERS];
  44.  
  45. public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
  46. {
  47.     new
  48.         interval = GetTickCountDifference(LastShot[playerid], GetTickCount());
  49.  
  50.     printf("[] Last shot interval: %i ms", interval);
  51.  
  52.     LastShot[playerid] = GetTickCount();
  53.  
  54.     return 1;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement