Eduardo_AC

[INC] Anti-Weapon/Ammo Hack (Hook) [Updated - 18/07/2017]

Jul 18th, 2017
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.18 KB | None | 0 0
  1. /*
  2.     * CALLBACK'S
  3.         - CheckPlayerWeaponHack(playerid)
  4.         - OnPlayerWeaponHackDetected(playerid, detectionid, weaponid, ammo)
  5.     ______________________________________________
  6.  
  7.     * STOCK'S
  8.         - ACW_GivePlayerWeapon(playerid, weaponid, ammo)
  9.         - ACW_SetPlayerWeaponAmmo(playerid, weaponid, ammo)
  10.         - ACW_RemovePlayerWeapon(playerid, weaponid)
  11.         - ACW_ResetPlayerWeapons(playerid)
  12.     ______________________________________________
  13. */
  14. // -- Macros
  15. #define WEAPON_HACK_CHECK_TIME              (3) // Segundos
  16. // ______________________________________________
  17. // -- Variáveis do jogador
  18. static
  19.     dataWeapon[MAX_PLAYERS][13],
  20.     dataAmmo[MAX_PLAYERS][13],
  21.     dataTime[MAX_PLAYERS]
  22. ;
  23. new
  24.     serverAirVehicles[] =
  25.     {
  26.         417, 425, 447, 460, 469,
  27.         476, 487, 488, 497, 511,
  28.         512, 513, 519, 520, 548,
  29.         553, 563, 577, 592, 593
  30.     }
  31. ;
  32. // ______________________________________________
  33. // -- Forwards
  34. forward CheckPlayerWeaponHack(playerid);
  35. forward OnPlayerWeaponHackDetected(playerid, detectionid, weaponid, ammo);
  36. // ______________________________________________
  37. // -- Callback's
  38. public OnPlayerUpdate(playerid)
  39. {
  40.     if(dataTime[playerid] < gettime())
  41.     {
  42.         dataTime[playerid] = gettime() + WEAPON_HACK_CHECK_TIME;
  43.  
  44.         CheckPlayerWeaponHack(playerid);
  45.     }
  46.  
  47.     #if defined ACW_OnPlayerUpdate
  48.         return ACW_OnPlayerUpdate(playerid);
  49.     #else
  50.         return true;
  51.     #endif
  52. }
  53. public OnPlayerExitVehicle(playerid, vehicleid)
  54. {
  55.     new
  56.         getModel = GetVehicleModel(vehicleid)
  57.     ;
  58.  
  59.     dataTime[playerid] += 1;
  60.  
  61.     for(new x = 0; x < sizeof serverAirVehicles; ++ x)
  62.     {
  63.         if(getModel == serverAirVehicles[x])
  64.         {
  65.             dataWeapon[playerid][11] = 46;
  66.             dataAmmo[playerid][11] = 1;
  67.  
  68.             break;
  69.         }
  70.     }
  71.  
  72.     #if defined ACW_OnPlayerExitVehicle
  73.         return ACW_OnPlayerExitVehicle(playerid, vehicleid);
  74.     #else
  75.         return true;
  76.     #endif
  77. }
  78. public OnPlayerDeath(playerid, killerid, reason)
  79. {
  80.     ACW_ResetPlayerWeapons(playerid);
  81.  
  82.     #if defined ACW_OnPlayerDeath
  83.         return ACW_OnPlayerDeath(playerid, killerid, reason);
  84.     #else
  85.         return true;
  86.     #endif
  87. }
  88. public CheckPlayerWeaponHack(playerid)
  89. {
  90.     new
  91.         w,
  92.         a
  93.     ;
  94.  
  95.     for(new x = 0; x < 13; ++ x)
  96.     {
  97.         GetPlayerWeaponData(playerid, x, w, a);
  98.  
  99.         if(dataWeapon[playerid][x] == 40)
  100.         {
  101.             if(dataWeapon[playerid][8] == 39) continue;
  102.             else
  103.             {
  104.                 ACW_RemovePlayerWeapon(playerid, 40);
  105.  
  106.                 continue;
  107.             }
  108.         }
  109.  
  110.         if(dataWeapon[playerid][x] != w)
  111.         {
  112.             if(dataWeapon[playerid][x] == 46)
  113.             {
  114.                 if(w == 0)
  115.                 {
  116.                     dataWeapon[playerid][x] = 0;
  117.                     dataAmmo[playerid][x] = 0;
  118.  
  119.                     continue;
  120.                 }
  121.             }
  122.  
  123.             if(dataWeapon[playerid][x] == 40)
  124.             {
  125.                 if(dataWeapon[playerid][8]) continue;
  126.             }
  127.  
  128.             OnPlayerWeaponHackDetected(playerid, 1, w, a);
  129.         }
  130.  
  131.         if(a > dataAmmo[playerid][x]) OnPlayerWeaponHackDetected(playerid, 2, w, a);
  132.         else dataAmmo[playerid][x] = a;
  133.     }
  134.  
  135.     return true;
  136. }
  137. // ______________________________________________
  138. // -- Stock's
  139. stock ACW_GivePlayerWeapon(playerid, weaponid, ammo)
  140. {
  141.     ACW_RemovePlayerAmmo(playerid, weaponid);
  142.  
  143.     switch(weaponid)
  144.     {
  145.         case 0,1:
  146.         {
  147.             dataWeapon[playerid][0] = weaponid;
  148.             dataAmmo[playerid][0] = ammo;
  149.         }
  150.         case 2..9:
  151.         {
  152.             dataWeapon[playerid][1] = weaponid;
  153.             dataAmmo[playerid][1] = ammo;
  154.         }
  155.         case 22..24:
  156.         {
  157.             dataWeapon[playerid][2] = weaponid;
  158.             dataAmmo[playerid][2] = ammo;
  159.         }
  160.         case 25..27:
  161.         {
  162.             dataWeapon[playerid][3] = weaponid;
  163.             dataAmmo[playerid][3] = ammo;
  164.         }
  165.         case 28,29,32:
  166.         {
  167.             dataWeapon[playerid][4] = weaponid;
  168.             dataAmmo[playerid][4] = ammo;
  169.         }
  170.         case 30,31:
  171.         {
  172.             dataWeapon[playerid][5] = weaponid;
  173.             dataAmmo[playerid][5] = ammo;
  174.         }
  175.         case 33,34:
  176.         {
  177.             dataWeapon[playerid][6] = weaponid;
  178.             dataAmmo[playerid][6] = ammo;
  179.         }
  180.         case 35..38:
  181.         {
  182.             dataWeapon[playerid][7] = weaponid;
  183.             dataAmmo[playerid][7] = ammo;
  184.         }
  185.         case 16..18:
  186.         {
  187.             dataWeapon[playerid][8] = weaponid;
  188.             dataAmmo[playerid][8] = ammo;
  189.         }
  190.         case 39:
  191.         {
  192.             dataWeapon[playerid][8] = weaponid;
  193.             dataAmmo[playerid][8] = ammo;
  194.  
  195.             //WEAPON_BOMB (Detonator)
  196.             dataWeapon[playerid][12] = 40;
  197.             dataAmmo[playerid][12] = ammo;
  198.         }
  199.         case 41..43:
  200.         {
  201.             dataWeapon[playerid][9] = weaponid;
  202.             dataAmmo[playerid][9] = ammo;
  203.         }
  204.         case 10..15:
  205.         {
  206.             dataWeapon[playerid][10] = weaponid;
  207.             dataAmmo[playerid][10] = ammo;
  208.         }
  209.         case 44..46:
  210.         {
  211.             dataWeapon[playerid][11] = weaponid;
  212.             dataAmmo[playerid][11] = ammo;
  213.         }
  214.         case 40:
  215.         {
  216.             dataWeapon[playerid][12] = weaponid;
  217.             dataAmmo[playerid][12] = ammo;
  218.         }
  219.         default: return false;
  220.     }
  221.  
  222.     return GivePlayerWeapon(playerid, weaponid, ammo);
  223. }
  224. static stock ACW_RemovePlayerAmmo(playerid, weaponid)
  225. {
  226.     new
  227.         w,
  228.         a
  229.     ;
  230.  
  231.     for(new x = 0; x < 13; ++ x)
  232.     {
  233.         GetPlayerWeaponData(playerid, x, w, a);
  234.  
  235.         if(w == weaponid)
  236.         {
  237.             GivePlayerWeapon(playerid, weaponid, -a);
  238.  
  239.             break;
  240.         }
  241.     }
  242.  
  243.     return true;
  244. }
  245. stock ACW_SetPlayerWeaponAmmo(playerid, weaponid, ammo)
  246. {
  247.     new
  248.         w,
  249.         a
  250.     ;
  251.  
  252.     for(new x = 0; x < 13; ++ x)
  253.     {
  254.         GetPlayerWeaponData(playerid, x, w, a);
  255.  
  256.         if(w == weaponid)
  257.         {
  258.             GivePlayerWeapon(playerid, weaponid, -a);
  259.             GivePlayerWeapon(playerid, weaponid, ammo);
  260.  
  261.             dataAmmo[playerid][x] = ammo;
  262.  
  263.             break;
  264.         }
  265.     }
  266.  
  267.     return true;
  268. }
  269. stock ACW_RemovePlayerWeapon(playerid, weaponid)
  270. {
  271.     new
  272.         w[13],
  273.         a[13]
  274.     ;
  275.  
  276.     for(new x = 0; x < 13; ++ x)
  277.     {
  278.         GetPlayerWeaponData(playerid, x, w[x], a[x]);
  279.     }
  280.  
  281.     ResetPlayerWeapons(playerid);
  282.  
  283.     for(new x = 0; x < 13; ++ x)
  284.     {
  285.         if(w[x] != weaponid)
  286.         {
  287.             GivePlayerWeapon(playerid, w[x], a[x]);
  288.         }
  289.         else if(w[x] == weaponid)
  290.         {
  291.             dataWeapon[playerid][x] = 0;
  292.             dataAmmo[playerid][x] = 0;
  293.         }
  294.     }
  295.  
  296.     return true;
  297. }
  298. stock ACW_ResetPlayerWeapons(playerid)
  299. {
  300.     for(new x = 0; x < 13; ++ x)
  301.     {
  302.         dataWeapon[playerid][x] = 0;
  303.         dataAmmo[playerid][x] = 0;
  304.     }
  305.    
  306.     return ResetPlayerWeapons(playerid);
  307. }
  308. // ______________________________________________
  309. // -- Hook's
  310. #if defined _ALS_OnPlayerUpdate
  311.     #undef OnPlayerUpdate
  312. #else
  313.     #define _ALS_OnPlayerUpdate
  314. #endif
  315. #define OnPlayerUpdate ACW_OnPlayerUpdate
  316. #if defined ACW_OnPlayerUpdate
  317.     forward ACW_OnPlayerUpdate(playerid);
  318. #endif
  319. //
  320. #if defined _ALS_OnPlayerExitVehicle
  321.     #undef OnPlayerExitVehicle
  322. #else
  323.     #define _ALS_OnPlayerExitVehicle
  324. #endif
  325. #define OnPlayerExitVehicle ACW_OnPlayerExitVehicle
  326. #if defined ACW_OnPlayerExitVehicle
  327.     forward ACW_OnPlayerExitVehicle(playerid, vehicleid);
  328. #endif
  329. //
  330. #if defined _ALS_OnPlayerDeath
  331.     #undef OnPlayerDeath
  332. #else
  333.     #define _ALS_OnPlayerDeath
  334. #endif
  335. #define OnPlayerDeath ACW_OnPlayerDeath
  336. #if defined ACW_OnPlayerDeath
  337.     forward ACW_OnPlayerDeath(playerid, killerid, reason);
  338. #endif
  339. //
  340. #if defined _ALS_GivePlayerWeapon
  341.     #undef GivePlayerWeapon
  342. #else
  343.     #define _ALS_GivePlayerWeapon
  344. #endif
  345. #define GivePlayerWeapon ACW_GivePlayerWeapon
  346. #if defined ACW_GivePlayerWeapon
  347.     forward ACW_GivePlayerWeapon(playerid, weaponid, ammo);
  348. #endif
  349. //
  350. #if defined _ALS_ResetPlayerWeapons
  351.     #undef ResetPlayerWeapons
  352. #else
  353.     #define _ALS_ResetPlayerWeapons
  354. #endif
  355. #define ResetPlayerWeapons ACW_ResetPlayerWeapons
  356. #if defined ACW_ResetPlayerWeapons
  357.     forward ACW_ResetPlayerWeapons(playerid);
  358. #endif
Add Comment
Please, Sign In to add comment