Nyft_

Armamento por variáveis (Anti Weapon Hack) ~Nyft

Apr 23rd, 2022 (edited)
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.08 KB | None | 0 0
  1. /*
  2.  
  3. > Funções:
  4.  
  5.     - IsPlayerHasWeapon(playerid, weaponid)
  6.     - SetPlayerWeapon(playerid, weaponid)
  7.     - RemovePlayerWeapon(playerid, weaponid)
  8.     - RemovePlayerWeapons(playerid)
  9.  
  10. > Comandos:
  11.  
  12.     - /armar (id) (arma-id) (munição)     (>) armar um jogador
  13.     - /removerarma (id) (arma-id)       (>) remover uma arma específica de um jogador
  14.     - /desarmar (id)                    (>) remover todas as armas de um jogador
  15.     - /armas                            (>) exibe em uma dialog todos os armamentos
  16.    
  17. */
  18.  
  19. // -----------------------------------------------------------------------------
  20.  
  21. #include a_samp
  22. #include sscanf2
  23. #include pawn.cmd
  24. #include <YSI_Coding\y_va>
  25.  
  26. // -----------------------------------------------------------------------------
  27.  
  28. #define MAX_WEAPON_SLOTS        13
  29.  
  30. // -----------------------------------------------------------------------------
  31.  
  32. enum E_WEAPON_DATA
  33. {
  34.     E_WEAPON_ID,
  35.     E_WEAPON_AMMO,
  36. };
  37.  
  38. new weapon[MAX_PLAYERS][MAX_WEAPON_SLOTS][E_WEAPON_DATA];
  39. new bool:playerWeaponHackDetected[MAX_PLAYERS];
  40. new playerWeaponHackTimer[MAX_PLAYERS];
  41.  
  42. // -----------------------------------------------------------------------------
  43.  
  44. forward OnPlayerWeaponHack(playerid);
  45.  
  46. // -----------------------------------------------------------------------------
  47.  
  48. main(){}
  49.  
  50. public OnPlayerConnect(playerid)
  51. {
  52.     playerWeaponHackTimer[playerid] = SetTimerEx("OnPlayerWeaponHack", 1000, true, "i", playerid);
  53.     return 1;
  54. }
  55.  
  56. public OnPlayerDisconnect(playerid, reason)
  57. {
  58.     KillTimer(playerWeaponHackTimer[playerid]);
  59.     playerWeaponHackDetected[playerid] = false;
  60.     return 1;
  61. }
  62.  
  63. public OnPlayerWeaponHack(playerid)
  64. {
  65.     if(!playerWeaponHackDetected[playerid])
  66.     {
  67.         for(new i; i < MAX_WEAPON_SLOTS; i++)
  68.         {
  69.             new weapons[MAX_WEAPON_SLOTS][2];
  70.             GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
  71.  
  72.             if(weapon[playerid][i][E_WEAPON_ID] != weapons[i][0])
  73.             {
  74.                 va_SendClientMessageToAll(-1, "* %s foi detectado com Weapon Hack.", GetPlayerNamef(playerid));
  75.                 playerWeaponHackDetected[playerid] = true;
  76.                 ResetPlayerWeapons(playerid);
  77.                 // Kick(playerid);
  78.             }
  79.         }
  80.     }
  81.     return 1;
  82. }
  83.  
  84. GetPlayerNamef(playerid)
  85. {
  86.     new name[MAX_PLAYER_NAME];
  87.     GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  88.     return name;
  89. }
  90.  
  91. SetPlayerWeapon(playerid, weaponid, ammo)
  92. {
  93.     new
  94.         weapSlot = -1;
  95.  
  96.     if((weapSlot = GetWeaponSlot(weaponid)) == -1)
  97.         return 0;
  98.  
  99.     if(!ammo)
  100.         return 0;
  101.  
  102.     weapon[playerid][weapSlot][E_WEAPON_ID] = weaponid;
  103.     weapon[playerid][weapSlot][E_WEAPON_AMMO] = ammo;
  104.     GivePlayerWeapon(playerid, weapon[playerid][weapSlot][E_WEAPON_ID], weapon[playerid][weapSlot][E_WEAPON_AMMO]);
  105.     return 1;
  106. }
  107.  
  108. RemovePlayerWeaponID(playerid, weaponid)
  109. {
  110.     if(!IsPlayerHasWeaponID(playerid, weaponid))
  111.         return 0;
  112.  
  113.     ResetPlayerWeapons(playerid);
  114.  
  115.     for(new i; i < MAX_WEAPON_SLOTS; i++)
  116.     {
  117.         if(weapon[playerid][i][E_WEAPON_ID] == weaponid) weapon[playerid][i][E_WEAPON_ID] = 0;
  118.         SetPlayerWeapon(playerid, weapon[playerid][i][E_WEAPON_ID], weapon[playerid][i][E_WEAPON_AMMO]);
  119.     }
  120.     return 1;
  121. }
  122.  
  123. RemovePlayerWeapons(playerid)
  124. {
  125.     for(new i; i < MAX_WEAPON_SLOTS; i++)
  126.         if(weapon[playerid][i][E_WEAPON_ID] != 0)
  127.             weapon[playerid][i][E_WEAPON_ID] = weapon[playerid][i][E_WEAPON_AMMO] = 0;
  128.  
  129.     return ResetPlayerWeapons(playerid);
  130. }
  131.  
  132. IsPlayerHasWeaponID(playerid, weaponid)
  133. {
  134.     for(new i; i < MAX_WEAPON_SLOTS; i++)
  135.         if(weapon[playerid][i][E_WEAPON_ID] == weaponid)
  136.             return 1;
  137.  
  138.     return 0;
  139. }
  140.  
  141. GetWeaponSlot(weaponid)
  142. {
  143.     switch(weaponid)
  144.     {
  145.         case 0..1:   return 0;
  146.         case 2..9:   return 1;
  147.         case 22..24: return 2;
  148.         case 25..27: return 3;
  149.         case 28..29: return 4;
  150.         case 32:     return 4;
  151.         case 30..31: return 5;
  152.         case 33..34: return 6;
  153.         case 35..38: return 7;
  154.         case 16..18: return 8;
  155.         case 39:     return 8;
  156.         case 41..43: return 9;
  157.         case 10..15: return 10;
  158.         case 44..46: return 11;
  159.         case 40:     return 12;
  160.     }
  161.     return -1;
  162. }
  163.  
  164. // -----------------------------------------------------------------------------
  165.  
  166. CMD:armar(playerid, params[])
  167. {
  168.     new id, weaponid, ammo;
  169.  
  170.     if(sscanf(params, "uii", id, weaponid, ammo))
  171.         return SendClientMessage(playerid, -1, "* /armar (id) (arma-id) (munição)");
  172.        
  173.     if(!IsPlayerConnected(id))
  174.         return SendClientMessage(playerid, -1, "* ID inválido.");
  175.  
  176.     if(!(1 <= weaponid <= 46))
  177.         return SendClientMessage(playerid, -1, "* Arma inválida.");
  178.  
  179.     if(ammo <= 0)
  180.         return SendClientMessage(playerid, -1, "* Munição inválida.");
  181.  
  182.     SetPlayerWeapon(playerid, weaponid, ammo);
  183.     va_SendClientMessage(playerid, -1, "* Você setou a arma %i para %s com %i de munição.", weaponid, GetPlayerNamef(id), ammo);
  184.     return 1;
  185. }
  186. CMD:removerarma(playerid, params[])
  187. {
  188.     new id, weaponid;
  189.  
  190.     if(sscanf(params, "ui", id, weaponid))
  191.         return SendClientMessage(playerid, -1, "* /removerarma (id) (arma-id)");
  192.  
  193.     if(!IsPlayerConnected(id))
  194.         return SendClientMessage(playerid, -1, "* ID inválido.");
  195.  
  196.     if(!(1 <= weaponid <= 46))
  197.         return SendClientMessage(playerid, -1, "* Arma inválida.");
  198.  
  199.     if(!IsPlayerHasWeaponID(playerid, weaponid))
  200.         return va_SendClientMessage(playerid, -1, "* %s não possui a arma %i.", GetPlayerNamef(id), weaponid);
  201.  
  202.     RemovePlayerWeaponID(id, weaponid);
  203.     va_SendClientMessage(playerid, -1, "* Você removeu a arma %i de %s.", weaponid, GetPlayerNamef(id));
  204.     return 1;
  205. }
  206. CMD:desarmar(playerid, params[])
  207. {
  208.     new id;
  209.  
  210.     if(sscanf(params, "u", id))
  211.         return SendClientMessage(playerid, -1, "* /desarmar (id)");
  212.  
  213.     if(!IsPlayerConnected(id))
  214.         return SendClientMessage(playerid, -1, "* ID inválido.");
  215.  
  216.     RemovePlayerWeapons(id);
  217.     va_SendClientMessage(playerid, -1, "* Você removeu todas as armas de %s.", GetPlayerNamef(id));
  218.     return 1;
  219. }
  220. CMD:armas(playerid)
  221. {
  222.     new list[45 * MAX_WEAPON_SLOTS];
  223.  
  224.     for(new i; i < MAX_WEAPON_SLOTS; i++)
  225.         if(weapon[playerid][i][E_WEAPON_ID] != 0)
  226.             format(list, sizeof(list), "%sSlot: %i - ArmaID: %i - Munição: %i\n", list, i, weapon[playerid][i][E_WEAPON_ID], weapon[playerid][i][E_WEAPON_AMMO]);
  227.  
  228.     ShowPlayerDialog(playerid, 1, DIALOG_STYLE_TABLIST, "Armamentos", list, "OK", #);
  229.     return 1;
  230. }
Add Comment
Please, Sign In to add comment