Advertisement
RiichardAmp

GTASA - @Riichard: Sistema de Vote Kick [Pawn Code]

Mar 14th, 2013
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.01 KB | None | 0 0
  1. /*
  2.         ========================================================================
  3.           ~> Sistema de Vote Kick - TextDraw's @simples@
  4.                     By: @Riichard
  5.         ========================================================================
  6. */
  7.  
  8. // ========== [Includes] ========== //
  9. #include <a_samp>
  10. #include <zcmd>
  11.  
  12. // ========== [Defines] ========== //
  13. #define rdMotivo        2803 // DIALOGID #conflitos, cuidado.
  14. #define kSegundos       60 // 60 segundos | 1 minuto.
  15.  
  16. // ========== [Variaveis] ========== //
  17. new
  18.     rVotosPos,
  19.     rVotosNeg,
  20.     bool:rVotou[MAX_PLAYERS],
  21.     rTempo = kSegundos,
  22.     pID,
  23.     VoteKickEx
  24. ;
  25.  
  26. // ========== [TextDraw's] ========== //
  27. new
  28.     Text:rVote[10]
  29. ;
  30.  
  31. // ================================== //
  32. public OnFilterScriptInit()
  33. {
  34.     rVotosPos = 0;
  35.     rVotosNeg = 0;
  36.     CriarTDs();
  37.     return print(" [FilterScript] @r - Vote Kick [TextDraw's] #CARREGADO.");
  38. }
  39.    
  40. public OnFilterScriptExit()
  41. {
  42.     ExcluirTDs();
  43.     return print(" [FilterScript] @r - Vote Kick [TextDraw's] #DESCARREGADO.");
  44. }
  45.  
  46. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  47. {
  48.     if(rTempo < kSegundos)
  49.     {
  50.         if(rVotou[playerid] == true) return 1;
  51.         if(playerid == pID) return 1;
  52.         if(newkeys & KEY_YES)
  53.         {
  54.             rVotosPos += 1;
  55.             TextDrawHideForPlayer(playerid, rVote[3]);
  56.             TextDrawSetString(rVote[4], "~r~~h~Voto confirmado!");
  57.             rVotou[playerid] = true;
  58.         }
  59.         if(newkeys & KEY_NO)
  60.         {
  61.             rVotosNeg += 1;
  62.             TextDrawHideForPlayer(playerid, rVote[3]);
  63.             TextDrawSetString(rVote[4], "~r~~h~Voto confirmado!");
  64.             rVotou[playerid] = true;
  65.         }
  66.     }
  67.     return 1;
  68. }
  69.  
  70. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  71. {
  72.     new
  73.         tString[100]
  74.     ;
  75.     if (dialogid == rdMotivo)
  76.     {
  77.         if(response)
  78.         {
  79.             if(!strlen(inputtext))
  80.                 return  ShowPlayerDialog(playerid, rdMotivo, DIALOG_STYLE_INPUT, "(@r) Vote Kick", "Digite o motivo:", "Abrir", "Cancelar");
  81.                
  82.             format(tString, sizeof(tString), "%s", rNome(pID));
  83.             TextDrawSetString(rVote[1], tString);
  84.            
  85.             format(tString, sizeof(tString), "Motivo: ~b~~h~%s", inputtext);
  86.             TextDrawSetString(rVote[2], tString);
  87.  
  88.             format(tString, sizeof(tString), "~g~~h~%d segundos", rTempo);
  89.             TextDrawSetString(rVote[6], tString);
  90.            
  91.             TextDrawSetString(rVote[3], "~w~~h~Pressione ~y~Y~w~~h~ para ~y~SIM");
  92.             TextDrawSetString(rVote[4], "~w~~h~Pressione ~r~N~w~~h~ para ~r~NAO");
  93.            
  94.             for (new r = 0; r <MAX_PLAYERS; r++)
  95.             {
  96.                 if(IsPlayerConnected(r))
  97.                 {
  98.                     for (new rr = 0; rr <7; rr++)
  99.                     {
  100.                         TextDrawShowForPlayer(r, rVote[rr]);
  101.                     }
  102.                 }
  103.             }
  104.            
  105.             TextDrawHideForPlayer(pID, rVote[3]);
  106.             TextDrawHideForPlayer(pID, rVote[4]);
  107.            
  108.             KillTimer(VoteKickEx);
  109.            
  110.             VoteKickEx = SetTimer("VoteKickTempo", 1000, true);
  111.         }
  112.     }
  113.     return false;
  114. }
  115.  
  116. // ====================================================================
  117. CMD:votekick(playerid, params[])
  118. {
  119.     if(rTempo < kSegundos)
  120.         return SendClientMessage(playerid, -1, "-ERRO- Já contém um VoteKick em aberto.");
  121.  
  122.     if(!strlen(params) || !isNumeric(params))
  123.         return SendClientMessage(playerid, -1, "-INFO- > /VoteKick [playerid]");
  124.  
  125.     if(!IsPlayerConnected(strval(params)))
  126.         return SendClientMessage(playerid, -1, "-ERRO- Jogador offline.");
  127.  
  128.     if(strval(params) == playerid)
  129.         return SendClientMessage(playerid, -1, "-ERRO- Você não pode kickar você mesmo.");
  130.  
  131.     new
  132.         String[100]
  133.     ;
  134.  
  135.     format(String, sizeof(String), "{F8F8FF} Desejá kickar o jogador {32CD32}%s{F8F8FF}, por qual motivo?", rNome(strval(params)));
  136.  
  137.     ShowPlayerDialog(playerid, rdMotivo, DIALOG_STYLE_INPUT, "(@r) Vote Kick", String, "Abrir", "Cancelar");
  138.  
  139.     pID = strval(params);
  140.     return true;
  141. }
  142.  
  143.  
  144. stock CriarTDs()
  145. {
  146.     rVote[0] = TextDrawCreate(10.000000, 159.000000, "~>~ Vote Kick");
  147.     TextDrawFont(rVote[0], 2);
  148.     TextDrawLetterSize(rVote[0], 0.220000, 2.200000);
  149.     TextDrawSetOutline(rVote[0], 1);
  150.  
  151.     rVote[1] = TextDrawCreate(10.000000, 181.000000, "Nome_Player");
  152.     TextDrawLetterSize(rVote[1], 0.380000, 1.999999);
  153.     TextDrawSetOutline(rVote[1], 1);
  154.  
  155.     rVote[2] = TextDrawCreate(13.000000, 200.000000, "Motivo: ~b~~h~MOTIVO");
  156.     TextDrawFont(rVote[2], 2);
  157.     TextDrawLetterSize(rVote[2], 0.200000, 1.299999);
  158.     TextDrawSetOutline(rVote[2], 1);
  159.  
  160.     rVote[3] = TextDrawCreate(11.000000, 240.000000, "~w~~h~Pressione ~y~Y~w~~h~ para ~y~SIM");
  161.     TextDrawFont(rVote[3], 1);
  162.     TextDrawLetterSize(rVote[3], 0.350000, 1.799999);
  163.     TextDrawSetOutline(rVote[3], 1);
  164.  
  165.     rVote[4] = TextDrawCreate(11.000000, 258.000000, "~w~~h~Pressione ~r~N~w~~h~ para ~r~NAO");
  166.     TextDrawLetterSize(rVote[4], 0.350000, 1.799999);
  167.     TextDrawSetOutline(rVote[4], 1);
  168.  
  169.     rVote[5] = TextDrawCreate(11.000000, 221.000000, "Tempo restante:");
  170.     TextDrawLetterSize(rVote[5], 0.220000, 1.300000);
  171.     TextDrawSetOutline(rVote[5], 1);
  172.  
  173.     rVote[6] = TextDrawCreate(78.000000, 216.000000, "~g~~h~- segundos");
  174.     TextDrawFont(rVote[6], 2);
  175.     TextDrawLetterSize(rVote[6], 0.220000, 2.100000);
  176.     TextDrawSetOutline(rVote[6], 1);
  177.  
  178.     rVote[7] = TextDrawCreate(14.000000, 259.000000, "Nome_Player foi kickado.");
  179.     TextDrawLetterSize(rVote[7], 0.250000, 1.599999);
  180.     TextDrawColor(rVote[7], -65281);
  181.     TextDrawSetOutline(rVote[7], 1);
  182.  
  183.     rVote[8] = TextDrawCreate(11.000000, 221.000000, "Votos positivos: ~y~-");
  184.     TextDrawFont(rVote[8], 2);
  185.     TextDrawLetterSize(rVote[8], 0.250000, 1.500000);
  186.     TextDrawSetOutline(rVote[8], 1);
  187.  
  188.     rVote[9] = TextDrawCreate(11.000000, 239.000000, "Votos negativos: ~r~~h~-");
  189.     TextDrawFont(rVote[9], 2);
  190.     TextDrawLetterSize(rVote[9], 0.250000, 1.500000);
  191.     TextDrawSetOutline(rVote[9], 1);
  192.     return true;
  193. }
  194.  
  195.  
  196. stock rNome(id)
  197. {
  198.     new pnome[MAX_PLAYER_NAME];
  199.     GetPlayerName(id, pnome, sizeof(pnome));
  200.     return pnome;
  201. }
  202.  
  203. stock isNumeric(const string[])
  204. {
  205.     new length=strlen(string);
  206.     if (length==0) return false;
  207.     for (new i = 0; i < length; i++)
  208.     {
  209.         if (
  210.             (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+')
  211.             || (string[i]=='-' && i!=0)
  212.             || (string[i]=='+' && i!=0)
  213.         ) return false;
  214.     }
  215.     if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
  216.     return true;
  217. }
  218.  
  219. forward VoteKickTempo();
  220. public VoteKickTempo()
  221. {
  222.     new tString[60];
  223.    
  224.     rTempo -= 1;
  225.     format(tString, sizeof(tString), "~g~~h~%02d segundos", rTempo);
  226.     TextDrawSetString(rVote[6], tString);
  227.    
  228.     if (rTempo == 0)
  229.     {
  230.         KillTimer(VoteKickEx);
  231.        
  232.         format(tString, sizeof(tString), "Votos positivos: ~y~%02d", rVotosPos);
  233.         TextDrawSetString(rVote[8], tString);
  234.  
  235.         format(tString, sizeof(tString), "Votos negativos: ~r~%02d", rVotosNeg);
  236.         TextDrawSetString(rVote[9], tString);
  237.        
  238.         if(rVotosPos > rVotosNeg)
  239.         {
  240.             format(tString, sizeof(tString), "%s foi kickado.", rNome(pID));
  241.             TextDrawSetString(rVote[7], tString);
  242.             if(rVotosPos > 1) SetTimerEx("PlayerKick", 100, false, "i", pID);
  243.                         else TextDrawSetString(rVote[7], "Tentativa de vote kick, falhou.");
  244.         }
  245.         else if(rVotosNeg > rVotosPos)
  246.         {
  247.             TextDrawSetString(rVote[7], "Tentativa de vote kick, falhou.");
  248.         }
  249.         else if(rVotosPos == rVotosNeg)
  250.         {
  251.             TextDrawSetString(rVote[7], "Tentativa de vote kick, falhou.");
  252.         }
  253.         for (new r = 0; r <MAX_PLAYERS; r++)
  254.         {
  255.             if(IsPlayerConnected(r))
  256.             {
  257.                 for (new rr = 0; rr <sizeof(rVote); rr++)
  258.                 {
  259.                     TextDrawShowForPlayer(r, rVote[rr]);
  260.                 }
  261.                 TextDrawHideForPlayer(r, rVote[3]);
  262.                 TextDrawHideForPlayer(r, rVote[4]);
  263.                 TextDrawHideForPlayer(r, rVote[5]);
  264.                 TextDrawHideForPlayer(r, rVote[6]);
  265.             }
  266.         }
  267.         SetTimer("ExcluirTDs", 5000, false);
  268.     }
  269.     return true;
  270. }
  271.  
  272. forward ExcluirTDs();
  273. public ExcluirTDs()
  274. {
  275.     for (new r = 0; r <MAX_PLAYERS; r++)
  276.     {
  277.         if(IsPlayerConnected(r))
  278.         {
  279.             for (new rr = 0; rr <sizeof(rVote); rr++)
  280.             {
  281.                 TextDrawHideForPlayer(r, rVote[rr]);
  282.             }
  283.             rVotou[r] = false;
  284.         }
  285.     }
  286.     rVotosPos = 0;
  287.     rVotosNeg = 0;
  288.     pID = EOS;
  289.     rTempo = kSegundos;
  290.     return true;
  291. }
  292.  
  293. forward PlayerKick(id); public PlayerKick(id) return Kick(id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement