Guest User

Sistema de Evento com Salvamento de Votos

a guest
Oct 24th, 2011
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. //Sistema de Votacao com Salvamento de Enquete e Votos
  2. #include a_samp
  3. #include DOF2
  4. #include zcmd
  5. #include sscanf2
  6. #define QuerVotar 1234
  7. #define Opcao 1243
  8. new strvote[256];
  9. new bool:VotacaoIniciada;
  10. new Sim,Nao,Votou[MAX_PLAYERS];
  11. new Votacao[128];
  12. stock GetVotacao() return Votacao;
  13. forward IniciarVotacao(playerid, pergunta[]);
  14. forward EncerrarVotacao(playerid, pergunta[]);
  15. public IniciarVotacao(playerid, pergunta[])
  16. {
  17. VotacaoIniciada = true;
  18. Sim = 0;
  19. Nao = 0;
  20. strmid(Votacao,pergunta,0,strlen(pergunta),255);
  21. format(strvote,sizeof(strvote),"Votacoes/%s.ini",pergunta);
  22. DOF2_CreateFile(strvote);
  23. DOF2_SetString(strvote,"Criador",pNome(playerid));
  24. for(new i = 0; i < MAX_PLAYERS; i++)
  25. {
  26. format(strvote,sizeof(strvote),"Votacao Iniciada Por %s\nPergunta: %s?",pergunta);
  27. ShowPlayerDialog(i,QuerVotar,DIALOG_STYLE_MSGBOX,"Votacao",strvote,"VOTAR","NAO VOTAR");
  28. }
  29. return 1;
  30. }
  31. public EncerrarVotacao(playerid, pergunta[])
  32. {
  33. format(strvote,sizeof(strvote),"~r~Votacao Encerrada~r~~n~~b~Pergunta: ~w~%s~n~~g~Sim: ~w~%d~n~~r~Nao: ~w~%d",GetVotacao(),Sim,Nao);
  34. GameTextForAll(strvote,10000,1);
  35. VotacaoIniciada = false;
  36. format(strvote,sizeof(strvote),"Votacoes/%s.ini",GetVotacao());
  37. DOF2_SetInt(strvote,"Sim",Sim);
  38. DOF2_SetInt(strvote,"Nao",Nao);
  39. DOF2_SetString(strvote,"Encerrada_Por",pNome(playerid));
  40. DOF2_SaveFile();
  41. return 1;
  42. }
  43. CMD:votacao(playerid, params[])
  44. {
  45. if(VotacaoIniciada == false)
  46. {
  47. new pergunta[96];
  48. if(sscanf(params,"s[96]",pergunta))
  49. return SendClientMessage(playerid,-1,"Use /Votacao [Pergunta]");
  50. IniciarVotacao(playerid, pergunta);
  51. }
  52. else return SendClientMessage(playerid,-1,"Ja Esta Havendo uma Votacao");
  53. return 1;
  54. }
  55. CMD:encerrar(playerid, params[])
  56. {
  57. if(VotacaoIniciada == true)
  58. {
  59. #pragma unused params
  60. EncerrarVotacao(playerid, GetVotacao());
  61. }
  62. else return SendClientMessage(playerid,-1,"Nenhuma Votacao em Andamento!");
  63. return 1;
  64. }
  65. public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[])
  66. {
  67. if(dialogid == QuerVotar)
  68. {
  69. if(response)
  70. {
  71. format(strvote,sizeof(strvote),"Pergunta: %s",GetVotacao());
  72. ShowPlayerDialog(playerid,Opcao,DIALOG_STYLE_MSGBOX,"Votacao",strvote,"SIM","NAO");
  73. return 1;
  74. }
  75. }
  76. if(dialogid == Opcao)
  77. {
  78. if(!response)
  79. {
  80. if(VotacaoIniciada == true)
  81. {
  82. if(Votou[playerid] == 1)
  83. return SendClientMessage(playerid,-1,"Voce Ja Votou!");
  84. Nao ++;
  85. Votou[playerid] = 1;
  86. SendClientMessage(playerid,0xE31919,"Voto Computado Com Sucesso!");
  87. }
  88. else return SendClientMessage(playerid,-1,"Nenhuma Votacao Esta Ocorrendo.");
  89. return 1;
  90. }
  91. if(response)
  92. {
  93. if(VotacaoIniciada == true)
  94. {
  95. if(Votou[playerid] == 1)
  96. return SendClientMessage(playerid,-1,"Voce Ja Votou!");
  97. Sim ++;
  98. Votou[playerid] = 1;
  99. SendClientMessage(playerid,0x007700,"Voto Computado Com Sucesso!");
  100. }
  101. else return SendClientMessage(playerid,-1,"Nenhuma Votacao Esta Ocorrendo.");
  102. return 1;
  103. }
  104. }
  105. return 1;
  106. }
  107. public OnFilterScriptInit()
  108. {
  109. print(" ");
  110. print("==> Sistema de Votacao com Salvamento by Pedro Miranda Iniciado <==");
  111. print(" ");
  112. Sim = 0;
  113. Nao = 0;
  114. return 1;
  115. }
  116. public OnFilterScriptExit()
  117. {
  118. print("Sistema de Votacao com Salvamento by Pedro Miranda Finalizado");
  119. DOF2_Exit();
  120. return 1;
  121. }
  122. stock pNome(playerid)
  123. {
  124. new name[24];
  125. GetPlayerName(playerid, name, 24);
  126. return name;
  127. }
  128. //Qualquer BUG Reporte em MP
  129.  
Advertisement
Add Comment
Please, Sign In to add comment