evgen1137

SendClientCheck usage

Jan 13th, 2016
2,037
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.20 KB | None | 1 0
  1. // SendClientCheck example script by evgen1137
  2. // thanks to MTA devs for structs
  3. #include <a_samp>
  4.  
  5. native SendClientCheck(playerid, type, arg, offset, size);
  6. forward OnClientCheckResponse(playerid, type, arg, response);
  7.  
  8. #define GetBit(%0,%1) ((%0 >> %1) & 1)
  9.  
  10. enum Flags
  11. {
  12.     b0x01,
  13.     bApplyGravity,
  14.     bDisableFriction,
  15.     bCollidable,
  16.     b0x10,
  17.     bDisableMovement,
  18.     b0x40,
  19.     b0x80,
  20.  
  21.     bSubmergedInWater,
  22.     bOnSolidSurface,
  23.     bBroken,
  24.     b0x800,
  25.     b0x1000,
  26.     b0x2000,
  27.     b0x4000,
  28.     b0x8000,
  29.  
  30.     b0x10000,
  31.     b0x20000,
  32.     bBulletProof,
  33.     bFireProof,
  34.     bCollisionProof,
  35.     bMeeleProof,
  36.     bInvulnerable,
  37.     bExplosionProof,
  38.  
  39.     b0x1000000,
  40.     bAttachedToEntity,
  41.     b0x4000000,
  42.     bTouchingWater,
  43.     bEnableCollision,
  44.     bDestroyed,
  45.     b0x40000000,
  46.     b0x80000000
  47. };
  48.  
  49. new PhysFlags[MAX_PLAYERS][Flags];
  50. new Timer;
  51.  
  52. public OnFilterScriptInit()
  53. {
  54.     Timer = SetTimer("TimerFunc", 1000, true);
  55. }
  56.  
  57. public OnFilterScriptExit()
  58. {
  59.     KillTimer(Timer);
  60. }
  61.  
  62. public OnPlayerConnect(playerid)
  63. {
  64.     for(new i = 0; i < 32; i++)
  65.     {
  66.         PhysFlags[playerid][Flags:i] = 0;
  67.     }
  68.     SendClientCheck(playerid, 0x48, 0, 0, 2);
  69.     SendClientCheck(playerid, 0x46, 1598, 0, 28); // 1598 - beachball
  70.     SendClientCheck(playerid, 0x47, 1598, 0, 48); // 1598 - beachball
  71.     return 1;
  72. }
  73.  
  74. public OnClientCheckResponse(playerid, type, arg, response)
  75. {
  76.     new str[128];
  77.     switch(type)
  78.     {
  79.         case 0x2:
  80.         {
  81.             // CPhysicalSAInterface
  82.             // https://github.com/multitheftauto/mtasa-blue/blob/master/MTA10/game_sa/CPhysicalSA.h#L39-L73
  83.             for(new i = 0; i < 32; i++)
  84.             {
  85.                 PhysFlags[playerid][Flags:i] = GetBit(arg, i);
  86.             }
  87.             format(str, sizeof(str), "bSubmergedInWater: %d, bOnSolidSurface: %d", PhysFlags[playerid][bSubmergedInWater], PhysFlags[playerid][bOnSolidSurface]);
  88.             SendClientMessage(playerid, -1, str);
  89.         }
  90.         case 0x46:
  91.         {
  92.             // CBaseModelInfoSAInterface
  93.             // https://github.com/multitheftauto/mtasa-blue/blob/master/MTA10/game_sa/CModelInfoSA.h#L138-L181
  94.             format(str, sizeof(str), "Model %d has checksum 0x%x", arg, response);
  95.             SendClientMessage(playerid, -1, str);
  96.         }
  97.         case 0x47:
  98.         {
  99.             // CColModelSAInterface
  100.             // https://github.com/multitheftauto/mtasa-blue/blob/master/MTA10/game_sa/CColModelSA.h#L87-L91
  101.             format(str, sizeof(str), "Col model %d has checksum 0x%x", arg, response);
  102.             SendClientMessage(playerid, -1, str);
  103.         }
  104.         case 0x48:
  105.         {
  106.             format(str, sizeof(str), "Your computer has been running for %s!", Convert(arg / 1000));
  107.             SendClientMessage(playerid, -1, str);
  108.         }
  109.     }
  110.     return 1;
  111. }
  112.  
  113. forward TimerFunc();
  114. public TimerFunc()
  115. {
  116.     for(new i = 0; i < MAX_PLAYERS; i++)
  117.     {
  118.         if(!IsPlayerConnected(i)) continue;
  119.         SendClientCheck(i, 0x2, 0, 0, 2);
  120.     }
  121. }
  122.  
  123. Convert(number)
  124. {
  125.     new hours = 0, mins = 0, secs = 0, string[100];
  126.     hours = floatround(number / 3600);
  127.     mins = floatround((number / 60) - (hours * 60));
  128.     secs = floatround(number - ((hours * 3600) + (mins * 60)));
  129.     if(hours > 0)
  130.     {
  131.         format(string, 100, "%d:%02d:%02d", hours, mins, secs);
  132.     }
  133.     else
  134.     {
  135.         format(string, 100, "%d:%02d", mins, secs);
  136.     }
  137.     return string;
  138. }
Add Comment
Please, Sign In to add comment