Advertisement
furiadanoitebr

Bomb Tag (Events)

Jun 6th, 2025 (edited)
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.50 KB | None | 0 0
  1. /*
  2. Sistema de Bomba Tag criado por furiadanoite
  3. Discord: furiadanoitebr / !FuriaDaNoiteBR#6666
  4.  
  5. Cada jogador que estiver com a bomba deve transferi-la para outro jogador ao encostar nele, para sobreviver.
  6. Quem estiver com a bomba quando o tempo acabar, explode e perde uma vida. O último jogador vivo vence!
  7. */
  8.  
  9. #define SAMP_COMPAT
  10. #include <open.mp> // Open.mp ou <samp> é usado para compatibilidade com o SA:MP
  11. #include <zcmd> // ZCMD é usado para comando
  12. #include <YSI_Data\y_iterate> // esse include é necessário para o foreach ou outro include foreach
  13.  
  14. // Bomba Tag - Jogo da Bomba
  15. new bool:HasBomb[MAX_PLAYERS];
  16. // new bool:BombGameActive = false; // Bomba Tag ativo - usado para verificar se o jogo está em andamento
  17. new BombCountdown[MAX_PLAYERS];
  18. new PlayerParticle[MAX_PLAYERS];
  19.  
  20. // Cores
  21. #define C_RED  0xFF0000C8
  22.  
  23. public OnFilterScriptInit()
  24. {
  25.     SetTimer("CheckVehicleCollisions", 500, true);
  26.     return 1;
  27. }
  28.  
  29. public OnFilterScriptExit()
  30. {
  31.     // Limpa partículas e timers ao descarregar o filterscript
  32.     for(new i = 0; i < MAX_PLAYERS; i++) {
  33.         HasBomb[i] = false;
  34.         BombCountdown[i] = 0;
  35.         if(IsValidObject(PlayerParticle[i])) {
  36.             DestroyObject(PlayerParticle[i]);
  37.             PlayerParticle[i] = INVALID_OBJECT_ID;
  38.         }
  39.     }
  40.     return 1;
  41. }
  42.  
  43. // Stock pName - Retorna o nome do jogador
  44. stock pName(playerid)
  45. {
  46.     new GetName[MAX_PLAYER_NAME];
  47.     GetPlayerName(playerid, GetName, sizeof(GetName));
  48.     return GetName;
  49. }
  50.  
  51. // Declaração da funçao antes do uso
  52. forward Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2);
  53.  
  54. // Definição da funçao antes de qualquer uso
  55. stock Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
  56. {
  57.     return floatsqroot((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
  58. }
  59.  
  60. // Iniciar contagem regressiva da bomba para um jogador
  61. stock StartBombCountdown(playerid) {
  62.     BombCountdown[playerid] = 30;
  63.     HasBomb[playerid] = true;
  64.  
  65.     new string[64];
  66.     format(string, sizeof(string), "~r~BOMBA ATIVA!~n~Explodira em: %d", BombCountdown[playerid]);
  67.     GameTextForAll(string, 1000, 3);
  68.  
  69.     // Destroi partícula anterior, se houver
  70.     if(IsValidObject(PlayerParticle[playerid])) {
  71.         DestroyObject(PlayerParticle[playerid]);
  72.     }
  73.  
  74.     // Cria a partícula e anexa ao jogador
  75.     PlayerParticle[playerid] = CreateObject(18728, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  76.     AttachObjectToPlayer(PlayerParticle[playerid], playerid, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  77.  
  78.     SetTimerEx("UpdateBombCountdown", 1000, false, "i", playerid);
  79. }
  80.  
  81. // Retorna a distância entre dois veículos
  82. stock Float:GetVehicleDistanceFromVehicle(vehicle1, vehicle2) {
  83.     new Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2;
  84.     GetVehiclePos(vehicle1, x1, y1, z1);
  85.     GetVehiclePos(vehicle2, x2, y2, z2);
  86.     return GetDistanceBetweenPoints(x1, y1, z1, x2, y2, z2);
  87. }
  88.  
  89. // Atualizar o temporizador da contagem regressiva da bomba
  90. forward UpdateBombCountdown(playerid);
  91. public UpdateBombCountdown(playerid) {
  92.     if(BombCountdown[playerid] > 0) {
  93.         BombCountdown[playerid]--;
  94.  
  95.         if(IsPlayerInAnyVehicle(playerid)) {
  96.             new vehicleid = GetPlayerVehicleID(playerid);
  97.             new Float:vHealth;
  98.             GetVehicleHealth(vehicleid, vHealth);
  99.  
  100.             // Verifica se o veículo foi destruído
  101.             if(vHealth < 250.0) {
  102.                 new closestPlayer = INVALID_PLAYER_ID;
  103.                 new Float:minDist = 999999.0;
  104.                 new Float:px, Float:py, Float:pz;
  105.                 GetPlayerPos(playerid, px, py, pz);
  106.  
  107.                 foreach(new i : Player) {
  108.                     if(i != playerid && !HasBomb[i]) {
  109.                         new Float:x, Float:y, Float:z;
  110.                         GetPlayerPos(i, x, y, z);
  111.                         new Float:dist = GetDistanceBetweenPoints(px, py, pz, x, y, z);
  112.                         if(dist < minDist) {
  113.                             minDist = dist;
  114.                             closestPlayer = i;
  115.                         }
  116.                     }
  117.                 }
  118.  
  119.                 if(closestPlayer != INVALID_PLAYER_ID) {
  120.                     HasBomb[playerid] = false;
  121.                     HasBomb[closestPlayer] = true;
  122.                     BombCountdown[closestPlayer] = BombCountdown[playerid];
  123.                     BombCountdown[playerid] = 0;
  124.  
  125.                     new string[128];
  126.                     format(string, sizeof(string), "> {ffffff}O jogador {ff2400}%s {ffffff}transferiu a bomba para {ff2400}%s {ffffff}apos seu veiculo ser destruido!", pName(playerid), pName(closestPlayer));
  127.                     SendClientMessageToAll(C_RED, string, 0);
  128.  
  129.                     // Remove partícula antiga
  130.                     if(IsValidObject(PlayerParticle[playerid])) DestroyObject(PlayerParticle[playerid]);
  131.  
  132.                     // Cria nova partícula
  133.                     if(IsValidObject(PlayerParticle[closestPlayer])) DestroyObject(PlayerParticle[closestPlayer]);
  134.                     PlayerParticle[closestPlayer] = CreateObject(18728, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  135.                     AttachObjectToPlayer(PlayerParticle[closestPlayer], closestPlayer, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  136.  
  137.                     SetTimerEx("UpdateBombCountdown", 1000, false, "i", closestPlayer);
  138.                     return 1;
  139.                 }
  140.             }
  141.  
  142.             // Verifica colisão entre veículos
  143.             foreach(new i : Player) {
  144.                 if(i != playerid && IsPlayerInAnyVehicle(i) && !HasBomb[i]) {
  145.                     new targetVehicle = GetPlayerVehicleID(i);
  146.                     new Float:tHealth;
  147.                     GetVehicleHealth(targetVehicle, tHealth);
  148.  
  149.                     if(GetVehicleDistanceFromVehicle(vehicleid, targetVehicle) < 8.0 && (vHealth < 1000.0 || tHealth < 1000.0)) {
  150.                         HasBomb[playerid] = false;
  151.                         HasBomb[i] = true;
  152.                         BombCountdown[i] = BombCountdown[playerid];
  153.                         BombCountdown[playerid] = 0;
  154.  
  155.                         new string[128];
  156.                         format(string, sizeof(string), "> {ffffff}O jogador {ff2400}%s {ffffff}transferiu a bomba para {ff2400}%s!", pName(playerid), pName(i));
  157.                         SendClientMessageToAll(C_RED, string, 0);
  158.  
  159.                         // Remove partícula antiga
  160.                         if(IsValidObject(PlayerParticle[playerid])) DestroyObject(PlayerParticle[playerid]);
  161.  
  162.                         // Cria nova partícula
  163.                         if(IsValidObject(PlayerParticle[i])) DestroyObject(PlayerParticle[i]);
  164.                         PlayerParticle[i] = CreateObject(18728, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  165.                         AttachObjectToPlayer(PlayerParticle[i], i, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  166.  
  167.                         SetTimerEx("UpdateBombCountdown", 1000, false, "i", i);
  168.                         return 1;
  169.                     }
  170.                 }
  171.             }
  172.         }
  173.  
  174.         // Mostrar contagem se não houve transferência
  175.         new string[64];
  176.         format(string, sizeof(string), "~r~BOMBA ATIVA!~n~Explodira em: %d", BombCountdown[playerid]);
  177.         GameTextForAll(string, 1000, 3);
  178.         SetTimerEx("UpdateBombCountdown", 1000, false, "i", playerid);
  179.     } else {
  180.         // Explosão da bomba
  181.         new Float:x, Float:y, Float:z;
  182.         GetPlayerPos(playerid, x, y, z);
  183.         CreateExplosion(x, y, z, 7, 10.0);
  184.  
  185.         new string[128];
  186.         format(string, sizeof(string), "> {ffffff}O jogador {ff2400}%s {ffffff}explodiu com a bomba!", pName(playerid));
  187.         SendClientMessageToAll(C_RED, string, 0);
  188.  
  189.         HasBomb[playerid] = false;
  190.         BombCountdown[playerid] = 0;
  191.  
  192.         // Remove partícula
  193.         if(IsValidObject(PlayerParticle[playerid])) {
  194.             DestroyObject(PlayerParticle[playerid]);
  195.             PlayerParticle[playerid] = INVALID_OBJECT_ID;
  196.         }
  197.     }
  198.     return 1;
  199. }
  200.  
  201. // Comando para começar o jogo da bomba
  202. CMD:bombtag(playerid, params[]) {
  203.     HasBomb[playerid] = true;
  204.     StartBombCountdown(playerid);
  205.    
  206.     new string[128];
  207.     format(string, sizeof(string), "> {ffffff}O admin {ff2400}%s {ffffff}iniciou o jogo da bomba! Fuja dele!", pName(playerid));
  208.     SendClientMessageToAll(C_RED, string, 0);
  209.     format(string, sizeof(string), "> {ffffff}Admin {ff2400}%s {ffffff}started bomb tag! Run from them!", pName(playerid));
  210.     SendClientMessageToAll(C_RED, string, 1);
  211.     return 1;
  212. }
Tags: #bombtag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement