Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- > Funções:
- - IsPlayerHasWeapon(playerid, weaponid)
- - SetPlayerWeapon(playerid, weaponid)
- - RemovePlayerWeapon(playerid, weaponid)
- - RemovePlayerWeapons(playerid)
- > Comandos:
- - /armar (id) (arma-id) (munição) (>) armar um jogador
- - /removerarma (id) (arma-id) (>) remover uma arma específica de um jogador
- - /desarmar (id) (>) remover todas as armas de um jogador
- - /armas (>) exibe em uma dialog todos os armamentos
- */
- // -----------------------------------------------------------------------------
- #include a_samp
- #include sscanf2
- #include pawn.cmd
- #include <YSI_Coding\y_va>
- // -----------------------------------------------------------------------------
- #define MAX_WEAPON_SLOTS 13
- // -----------------------------------------------------------------------------
- enum E_WEAPON_DATA
- {
- E_WEAPON_ID,
- E_WEAPON_AMMO,
- };
- new weapon[MAX_PLAYERS][MAX_WEAPON_SLOTS][E_WEAPON_DATA];
- new bool:playerWeaponHackDetected[MAX_PLAYERS];
- new playerWeaponHackTimer[MAX_PLAYERS];
- // -----------------------------------------------------------------------------
- forward OnPlayerWeaponHack(playerid);
- // -----------------------------------------------------------------------------
- main(){}
- public OnPlayerConnect(playerid)
- {
- playerWeaponHackTimer[playerid] = SetTimerEx("OnPlayerWeaponHack", 1000, true, "i", playerid);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- KillTimer(playerWeaponHackTimer[playerid]);
- playerWeaponHackDetected[playerid] = false;
- return 1;
- }
- public OnPlayerWeaponHack(playerid)
- {
- if(!playerWeaponHackDetected[playerid])
- {
- for(new i; i < MAX_WEAPON_SLOTS; i++)
- {
- new weapons[MAX_WEAPON_SLOTS][2];
- GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
- if(weapon[playerid][i][E_WEAPON_ID] != weapons[i][0])
- {
- va_SendClientMessageToAll(-1, "* %s foi detectado com Weapon Hack.", GetPlayerNamef(playerid));
- playerWeaponHackDetected[playerid] = true;
- ResetPlayerWeapons(playerid);
- // Kick(playerid);
- }
- }
- }
- return 1;
- }
- GetPlayerNamef(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, MAX_PLAYER_NAME);
- return name;
- }
- SetPlayerWeapon(playerid, weaponid, ammo)
- {
- new
- weapSlot = -1;
- if((weapSlot = GetWeaponSlot(weaponid)) == -1)
- return 0;
- if(!ammo)
- return 0;
- weapon[playerid][weapSlot][E_WEAPON_ID] = weaponid;
- weapon[playerid][weapSlot][E_WEAPON_AMMO] = ammo;
- GivePlayerWeapon(playerid, weapon[playerid][weapSlot][E_WEAPON_ID], weapon[playerid][weapSlot][E_WEAPON_AMMO]);
- return 1;
- }
- RemovePlayerWeaponID(playerid, weaponid)
- {
- if(!IsPlayerHasWeaponID(playerid, weaponid))
- return 0;
- ResetPlayerWeapons(playerid);
- for(new i; i < MAX_WEAPON_SLOTS; i++)
- {
- if(weapon[playerid][i][E_WEAPON_ID] == weaponid) weapon[playerid][i][E_WEAPON_ID] = 0;
- SetPlayerWeapon(playerid, weapon[playerid][i][E_WEAPON_ID], weapon[playerid][i][E_WEAPON_AMMO]);
- }
- return 1;
- }
- RemovePlayerWeapons(playerid)
- {
- for(new i; i < MAX_WEAPON_SLOTS; i++)
- if(weapon[playerid][i][E_WEAPON_ID] != 0)
- weapon[playerid][i][E_WEAPON_ID] = weapon[playerid][i][E_WEAPON_AMMO] = 0;
- return ResetPlayerWeapons(playerid);
- }
- IsPlayerHasWeaponID(playerid, weaponid)
- {
- for(new i; i < MAX_WEAPON_SLOTS; i++)
- if(weapon[playerid][i][E_WEAPON_ID] == weaponid)
- return 1;
- return 0;
- }
- GetWeaponSlot(weaponid)
- {
- switch(weaponid)
- {
- case 0..1: return 0;
- case 2..9: return 1;
- case 22..24: return 2;
- case 25..27: return 3;
- case 28..29: return 4;
- case 32: return 4;
- case 30..31: return 5;
- case 33..34: return 6;
- case 35..38: return 7;
- case 16..18: return 8;
- case 39: return 8;
- case 41..43: return 9;
- case 10..15: return 10;
- case 44..46: return 11;
- case 40: return 12;
- }
- return -1;
- }
- // -----------------------------------------------------------------------------
- CMD:armar(playerid, params[])
- {
- new id, weaponid, ammo;
- if(sscanf(params, "uii", id, weaponid, ammo))
- return SendClientMessage(playerid, -1, "* /armar (id) (arma-id) (munição)");
- if(!IsPlayerConnected(id))
- return SendClientMessage(playerid, -1, "* ID inválido.");
- if(!(1 <= weaponid <= 46))
- return SendClientMessage(playerid, -1, "* Arma inválida.");
- if(ammo <= 0)
- return SendClientMessage(playerid, -1, "* Munição inválida.");
- SetPlayerWeapon(playerid, weaponid, ammo);
- va_SendClientMessage(playerid, -1, "* Você setou a arma %i para %s com %i de munição.", weaponid, GetPlayerNamef(id), ammo);
- return 1;
- }
- CMD:removerarma(playerid, params[])
- {
- new id, weaponid;
- if(sscanf(params, "ui", id, weaponid))
- return SendClientMessage(playerid, -1, "* /removerarma (id) (arma-id)");
- if(!IsPlayerConnected(id))
- return SendClientMessage(playerid, -1, "* ID inválido.");
- if(!(1 <= weaponid <= 46))
- return SendClientMessage(playerid, -1, "* Arma inválida.");
- if(!IsPlayerHasWeaponID(playerid, weaponid))
- return va_SendClientMessage(playerid, -1, "* %s não possui a arma %i.", GetPlayerNamef(id), weaponid);
- RemovePlayerWeaponID(id, weaponid);
- va_SendClientMessage(playerid, -1, "* Você removeu a arma %i de %s.", weaponid, GetPlayerNamef(id));
- return 1;
- }
- CMD:desarmar(playerid, params[])
- {
- new id;
- if(sscanf(params, "u", id))
- return SendClientMessage(playerid, -1, "* /desarmar (id)");
- if(!IsPlayerConnected(id))
- return SendClientMessage(playerid, -1, "* ID inválido.");
- RemovePlayerWeapons(id);
- va_SendClientMessage(playerid, -1, "* Você removeu todas as armas de %s.", GetPlayerNamef(id));
- return 1;
- }
- CMD:armas(playerid)
- {
- new list[45 * MAX_WEAPON_SLOTS];
- for(new i; i < MAX_WEAPON_SLOTS; i++)
- if(weapon[playerid][i][E_WEAPON_ID] != 0)
- 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]);
- ShowPlayerDialog(playerid, 1, DIALOG_STYLE_TABLIST, "Armamentos", list, "OK", #);
- return 1;
- }
Add Comment
Please, Sign In to add comment