Advertisement
DraKiNs

[FS] Sistema de Votação 2.0

Sep 17th, 2011
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.48 KB | None | 0 0
  1. //==============================================================================
  2.  
  3. #include a_samp
  4.  
  5. //==============================================================================
  6.  
  7. #define D_VOTOS     (0000009998)
  8.  
  9. //==============================================================================
  10.  
  11. enum E_VOTOS
  12. {
  13.     positivos,
  14.     negativos,
  15.     bool:inicializado,
  16.     perguntaVotacao[128]
  17. }
  18.  
  19.  
  20. new
  21.    g_Votos[E_VOTOS],
  22.    bool:pVotou[MAX_PLAYERS char];
  23.  
  24. //==============================================================================
  25.  
  26. public OnFilterScriptInit()
  27. {
  28.     print("Sistema de votação por \x22 Bruno da Silva \x22 carregado com sucesso.");
  29.     return true;
  30. }
  31.  
  32.  
  33. public OnFilterScriptExit()
  34. {
  35.     print("Sistema de votação por \x22 Bruno da Silva \x22 descarregado com sucesso.");
  36.     return true;
  37. }
  38.  
  39.  
  40. public OnPlayerCommandText(playerid, cmdtext[])
  41. {
  42.     if(!strcmp(cmdtext, "/votar", true)) {
  43.         return ShowPlayerDialog(playerid, D_VOTOS, DIALOG_STYLE_MSGBOX, "Votar na Enquete", g_Votos[E_VOTOS:3], "Sim", "Não");
  44.     }
  45.  
  46.     if(!strcmp(cmdtext, "/iniciar", true, 8)) {
  47.         if(strlen(cmdtext) < 8) {
  48.             return SendClientMessage(playerid, 0xFFFFFFFF, "[Erro] Digite a pergunta");
  49.         }
  50.  
  51.         if(!IsPlayerAdmin(playerid)) {
  52.             return SendClientMessage(playerid, 0xFFFFFFFF, "[Erro] Você não é administrador");
  53.         }
  54.  
  55.         static
  56.             string[128]
  57.         ;
  58.  
  59.         GetPlayerName(playerid, string, MAX_PLAYER_NAME);
  60.  
  61.         format(g_Votos[E_VOTOS:3], 128, cmdtext[8]);
  62.  
  63.         format(string, sizeof string, "[NOVA ENQUETE] %s: %s", string, cmdtext[8]);
  64.  
  65.         g_Votos[E_VOTOS:2] = true;
  66.  
  67.         return SendClientMessageToAll(0xFFFFFFFF, string);
  68.     }
  69.  
  70.     if(!strcmp(cmdtext, "/fechar", true)) {
  71.         if(!IsPlayerAdmin(playerid)) {
  72.             return SendClientMessage(playerid, 0xFFFFFFFF, "[Erro] Você não é administrador");
  73.         }
  74.  
  75.         static
  76.             string[128]
  77.         ;
  78.  
  79.         if(g_Votos[E_VOTOS:0] > g_Votos[E_VOTOS:1]) {
  80.             format(string, 128, "[Enquete] A grande maioria concorda com a opção sim (%d sim) (%d não)", g_Votos[E_VOTOS:0], g_Votos[E_VOTOS:1]);
  81.             SendClientMessage(playerid, 0xFFFFFFFF, string);
  82.         }
  83.  
  84.         else {
  85.             format(string, 128, "[Enquete] A grande maioria concorda com a opção não (%d sim) (%d não)", g_Votos[E_VOTOS:0], g_Votos[E_VOTOS:1]);
  86.             SendClientMessage(playerid, 0xFFFFFFFF, string);
  87.         }
  88.  
  89.         string[0] = 0xFFFFFFFF;
  90.  
  91.         do {
  92.             g_Votos[E_VOTOS:++string[0]] = _:0 ;
  93.         }
  94.  
  95.         while(string[0] != sizeof(g_Votos));
  96.  
  97.         for(new i = 0; i != sizeof(pVotou); ++i)
  98.         {
  99.             pVotou{i} = false;
  100.         }
  101.  
  102.         return  SendClientMessage(playerid, 0xFFFFFFFF, "[Enquete] Enquete finalizada");
  103.     }
  104.  
  105.     return  false;
  106. }
  107.  
  108.  
  109. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  110. {
  111.     if(dialogid == D_VOTOS) {
  112.         if(!g_Votos[E_VOTOS:2]) {
  113.             SendClientMessage(playerid, 0xFFFFFFFF, "[Erro] Nenhuma votação iniciada");
  114.             return true;
  115.         }
  116.  
  117.         if(pVotou{playerid}) {
  118.             SendClientMessage(playerid, 0xFFFFFFFF, "[Erro] Você já votou");
  119.             return true;
  120.         }
  121.  
  122.         SendClientMessage(playerid, 0xFFFFFFFF, "[Erro] Voto computado com sucesso");
  123.  
  124.         pVotou{playerid} = true, ++g_Votos[E_VOTOS:response];
  125.     }
  126.     return true;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement