Advertisement
Hardware

Sistema de votação - Texdraw e dialog

Sep 15th, 2011
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.90 KB | None | 0 0
  1. /*
  2.                 Sistema de votação - TextDraw e dialog
  3.                 Autor: Hardware - Bryan.
  4.                 Qualquer um poderá usar esse sistema, desde que use os créditos.
  5. */
  6.  
  7.  
  8.  
  9. #include <a_samp>
  10. #define Votacao                     20
  11.  
  12. new
  13.     bool:ECriada,
  14.     sim,
  15.     nao,
  16.     nick[MAX_PLAYER_NAME],
  17.     bool:jvotou,
  18.     adminmsg[128]
  19. ;
  20. new
  21.     Text:R,
  22.     Text:S,
  23.     Text:N,
  24.     Text:T,
  25.     Text:RF
  26. ;
  27.  
  28. forward VSair(playerid);
  29. public OnGameModeInit()
  30. {
  31.     R = TextDrawCreate(2.000000, 155.000000, "- Numero de votos:");
  32.     TextDrawBackgroundColor(R, 255);
  33.     TextDrawFont(R, 1);
  34.     TextDrawLetterSize(R, 0.500000, 1.000000);
  35.     TextDrawColor(R, 9127423);
  36.     TextDrawSetOutline(R, 0);
  37.     TextDrawSetProportional(R, 1);
  38.     TextDrawSetShadow(R, 1);
  39.  
  40.     S = TextDrawCreate(2.000000, 183.000000, "Sim:");
  41.     TextDrawBackgroundColor(S, 255);
  42.     TextDrawFont(S, 1);
  43.     TextDrawLetterSize(S, 0.500000, 1.000000);
  44.     TextDrawColor(S, -2686721);
  45.     TextDrawSetOutline(S, 0);
  46.     TextDrawSetProportional(S, 1);
  47.     TextDrawSetShadow(S, 1);
  48.  
  49.     N = TextDrawCreate(52.000000, 182.000000, "Nao:");
  50.     TextDrawBackgroundColor(N, 255);
  51.     TextDrawFont(N, 1);
  52.     TextDrawLetterSize(N, 0.500000, 1.000000);
  53.     TextDrawColor(N, -2686721);
  54.     TextDrawSetOutline(N, 0);
  55.     TextDrawSetProportional(N, 1);
  56.     TextDrawSetShadow(N, 1);
  57.  
  58.     T = TextDrawCreate(106.000000, 183.000000, "Total:");
  59.     TextDrawBackgroundColor(T, 255);
  60.     TextDrawFont(T, 1);
  61.     TextDrawLetterSize(T, 0.500000, 1.000000);
  62.     TextDrawColor(T, -2686721);
  63.     TextDrawSetOutline(T, 0);
  64.     TextDrawSetProportional(T, 1);
  65.     TextDrawSetShadow(T, 1);
  66.  
  67.     RF = TextDrawCreate(1.000000, 211.000000, "Resultado Final:");
  68.     TextDrawBackgroundColor(RF, 255);
  69.     TextDrawFont(RF, 1);
  70.     TextDrawLetterSize(RF, 0.500000, 1.000000);
  71.     TextDrawColor(RF, 1618709503);
  72.     TextDrawSetOutline(RF, 0);
  73.     TextDrawSetProportional(RF, 1);
  74.     TextDrawSetShadow(RF, 1);
  75.  
  76. }
  77.  
  78. public OnPlayerCommandText(playerid, cmdtext[])
  79. {
  80.     new texto[128];
  81.     if(!strcmp(cmdtext,"/votacao",true))
  82.     {
  83.         if(!IsPlayerAdmin(playerid))
  84.                 return SendClientMessage(playerid, -1, "Você não é administrador!");
  85.         if(ECriada == true)
  86.                 return SendClientMessage(playerid, -1,"Já existe uma votação iniciada!");
  87.         ShowPlayerDialog(playerid,Votacao,DIALOG_STYLE_INPUT,"Iniciando a votação","Digite a pergunta para iniciar a votação:","Ok","Cancelar");
  88.         return 1;
  89.     }
  90.     if(!strcmp(cmdtext,"/votar",true))
  91.     {
  92.         if(ECriada == false)
  93.                 return SendClientMessage(playerid, -1,"Não existe nenhuma votação feita!");
  94.         if(jvotou == true)
  95.                 return SendClientMessage(playerid, -1,"Desculpe, mas você já votou e não poderá votar novamente!");
  96.         format(texto,sizeof texto,"%s",adminmsg);
  97.         ShowPlayerDialog(playerid,Votacao+1,DIALOG_STYLE_MSGBOX,"Escolha a sua resposta para a pergunta.",texto,"Sim","Não");
  98.         return 1;
  99.     }
  100.     if(!strcmp(cmdtext,"/fecharv",true))
  101.     {
  102.         new msgvotos[128],msg2[128],msg3[128];
  103.         if(!IsPlayerAdmin(playerid))
  104.                 return SendClientMessage(playerid, -1, "Você não é administrador!");
  105.         if(ECriada == false)
  106.                 return SendClientMessage(playerid, -1,"Não existe nenhuma votação feita!");
  107.  
  108.         new totalvotos = (sim + nao);
  109.         format(msgvotos,sizeof msgvotos,"Sim:%d",sim);
  110.         format(msg2,sizeof msgvotos,"Nao:%d",nao);
  111.         format(msg3,sizeof msgvotos,"Total:%d",totalvotos);
  112.         for(new i; i<MAX_PLAYERS; i++)
  113.         {
  114.             TextDrawShowForPlayer(i,R);
  115.             TextDrawShowForPlayer(i,S);
  116.             TextDrawShowForPlayer(i,N);
  117.             TextDrawShowForPlayer(i,T);
  118.             TextDrawShowForPlayer(i,RF);
  119.             TextDrawSetString(S,msgvotos);
  120.             TextDrawSetString(N,msg2);
  121.             TextDrawSetString(T,msg3);
  122.             SetTimerEx("VSair",5000,false,"i",i);
  123.             if(jvotou == true)
  124.             {
  125.                 jvotou = false;
  126.             }
  127.         }
  128.         if(sim == nao) return TextDrawSetString(RF,"A votacao empatou!");
  129.         if(sim > nao)
  130.         {
  131.             TextDrawSetString(RF,"A maioria votou em 'Sim'.");
  132.  
  133.         }
  134.         else
  135.         {
  136.             TextDrawSetString(RF,"A maioria votou em 'Nao'");
  137.         }
  138.         sim = 0;
  139.         nao = 0;
  140.         ECriada = false;
  141.     }
  142.     return 1;
  143. }
  144.  
  145. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  146. {
  147.     if(dialogid == Votacao)
  148.     {
  149.         if(!response)
  150.             return SendClientMessage(playerid, -1, "Você cancelou a criação da votação.");
  151.         GetPlayerName(playerid, nick,MAX_PLAYER_NAME);
  152.         SendClientMessageToAll(-1,"• ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ •");
  153.         format(adminmsg,sizeof adminmsg,"» O administrador %s, criou uma enquete.",nick);
  154.         SendClientMessageToAll(-1,adminmsg);
  155.         format(adminmsg,sizeof adminmsg,"» Pergunta: %s",inputtext);
  156.         SendClientMessageToAll(-1,adminmsg);
  157.         SendClientMessageToAll(-1,"• ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ •");
  158.         ECriada = true;
  159.         return 1;
  160.     }
  161.     if(dialogid == Votacao+1)
  162.     {
  163.         if(response)
  164.         {
  165.             sim++;
  166.             jvotou = true;
  167.             SendClientMessage(playerid,-1,"Você votou na opção 'Sim'");
  168.         }
  169.         else
  170.         {
  171.             nao++;
  172.             jvotou = true;
  173.             SendClientMessage(playerid, -1, "Você votou na opção 'Não'");
  174.         }
  175.     }
  176.     return 1;
  177. }
  178.  
  179. public VSair(playerid)
  180. {
  181.     for(new i; i<MAX_PLAYERS; i++)
  182.     {
  183.         TextDrawHideForPlayer(i,R);
  184.         TextDrawHideForPlayer(i,S);
  185.         TextDrawHideForPlayer(i,N);
  186.         TextDrawHideForPlayer(i,T);
  187.         TextDrawHideForPlayer(i,RF);
  188.     }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement