Advertisement
Guest User

Untitled

a guest
Mar 4th, 2013
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.13 KB | None | 0 0
  1. /*/////////////////////////////////////////////////////////////////////////////////
  2.         Anti-AmmoHack:
  3.         --------------
  4.         * This filterscript was created by iRage (http://forum.sa-mp.com/member.php?u=135577)
  5.         * Feel free to do whatever you want with it.
  6.         * Version: 1.0
  7. *//////////////////////////////////////////////////////////////////////////////////
  8.  
  9. #include <a_samp>
  10. #include <zcmd>
  11. #include <sscanf>
  12.  
  13. #define COLOR_ORANGE 0xFF8000FF
  14.  
  15. public OnFilterScriptInit()
  16. {
  17.     print("\n          --------------------------------------");
  18.     print("             Anti-AmmoHack v1.0 by iRage [LOADED]");
  19.     print("          --------------------------------------\n");
  20.     return 1;
  21. }
  22.  
  23.  
  24. /*/////////////////////////////////////////////////////////////////////////////////
  25.     Variables:
  26.     ----------
  27.     * iAmmo: Saves the player's weapon ammo upon shooting to re-check later on in the timer.
  28.     * iWeaponSlot: Saves the player's weapon slot upon shooting to define where to search in the timer.
  29.     * iCheck: Defines if the player is already being checked or not, terminating double-checks if a player double clicks when shooting to avoid false accusations.
  30.  
  31. *//////////////////////////////////////////////////////////////////////////////////
  32. new iAmmo[MAX_PLAYERS], iWeaponSlot[MAX_PLAYERS], iCheck[MAX_PLAYERS];
  33.  
  34.  
  35. /*/////////////////////////////////////////////////////////////////////////////////
  36.     Timer:
  37.     ------
  38.     * Gets called once a player shoots, used to check if the ammo is still the same after player started shooting or not.
  39. *//////////////////////////////////////////////////////////////////////////////////
  40. forward AmmoCheck(playerid);
  41. public AmmoCheck(playerid)
  42. {
  43.     if(iCheck[playerid])
  44.     {
  45.         new NewAmmo, WeaponID, string[128];
  46.         GetPlayerWeaponData(playerid, iWeaponSlot[playerid], WeaponID, NewAmmo);
  47.         if(NewAmmo >= iAmmo[playerid])
  48.         {
  49.             GetPlayerName(playerid, string, sizeof(string));
  50.             format(string, sizeof(string), ">> {FF6347}[CHEAT] {33CCFF}Ammo-hack detected {9ACD32}(ID: %d | Name: %s)", playerid, string);
  51.             SendClientMessageToAll(COLOR_ORANGE, string);
  52.         }
  53.         iCheck[playerid] = 0;
  54.     }
  55.     return 1;
  56. }
  57.  
  58. /*/////////////////////////////////////////////////////////////////////////////////
  59.     OnPlayerKeyStateChange:
  60.     -----------------------
  61.     * The filterscript uses this callback to detect once a player starts shooting, saving his current ammo value to check if it's the same after a while.
  62. *//////////////////////////////////////////////////////////////////////////////////
  63. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  64. {
  65.     new string[128], WeaponID;
  66.     if(!iCheck[playerid] && FiniteWeapon(playerid))
  67.     {
  68.         if(newkeys & KEY_FIRE || newkeys & KEY_ACTION)
  69.         {
  70.             if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
  71.             {
  72.                 iWeaponSlot[playerid] = GetWeaponSlot(GetPlayerWeapon(playerid));
  73.                 GetWeaponName(GetPlayerWeapon(playerid), string, sizeof(string));
  74.                 GetPlayerWeaponData(playerid, iWeaponSlot[playerid], WeaponID, iAmmo[playerid]);
  75.                 iCheck[playerid] = 1;
  76.                 SetTimerEx("AmmoCheck", 800, false, "i", playerid);
  77.             }
  78.         }
  79.     }
  80.     return 1;
  81. }
  82.  
  83.  
  84. /*/////////////////////////////////////////////////////////////////////////////////
  85.     Stocks:
  86.     -------
  87.     * GetWeaponSlot: Used to get which slot the weapon being held by a player is stored in.
  88.     * FiniteWeapon: Used to define which weapons can lose ammo when used, camera excluded as it's not detected 100% accurately.
  89. *//////////////////////////////////////////////////////////////////////////////////
  90. stock GetWeaponSlot(weaponid)
  91. {
  92.     new slot;
  93.     switch(weaponid)
  94.     {
  95.         case 0,1: slot = 0;
  96.         case 2 .. 9: slot = 1;
  97.         case 10 .. 15: slot = 10;
  98.         case 16 .. 18, 39: slot = 8;
  99.         case 22 .. 24: slot = 2;
  100.         case 25 .. 27: slot = 3;
  101.         case 28, 29, 32: slot = 4;
  102.         case 30, 31: slot = 5;
  103.         case 33, 34: slot = 6;
  104.         case 35 .. 38: slot = 7;
  105.         case 40: slot = 12;
  106.         case 41 .. 43: slot = 9;
  107.         case 44 .. 46: slot = 11;
  108.     }
  109.     return slot;
  110. }
  111.  
  112. stock FiniteWeapon(playerid)
  113. {
  114.     new status = 0;
  115.     for(new i = 16; i<43; i++)
  116.     {
  117.         if(GetPlayerWeapon(playerid) == i && GetPlayerWeapon(playerid) != 43) status = 1;
  118.     }
  119.     return status;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement