Advertisement
Aninhaah

aElection (Sistema de Eleição) by Aninhaah/HumildadeForever

Aug 27th, 2012
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.75 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <sscanf>
  4. #include <DOF2>
  5. #include <streamer>
  6.  
  7. #define PASTA_USUARIOS "Contas/%s.ini"
  8. #define ConfigEleicao "Info Eleicao/Eleicao.ini"
  9. #define CANDIDATOS_ELEICAO "Info Eleicao/Candidatos.ini"
  10. #define VOTOS_CANDIDATOS "Info Eleicao/Votos.ini"
  11. #define ID_CANDIDATO "Info Eleicao/ID.ini"
  12. #define URNAS "Info Eleicao/Urna %d.ini"
  13. #define ID_URNA "Info Eleicao/IDUrnas.ini"
  14.  
  15. #define MAX_CANDIDATOS 31
  16. #define MAX_URNAS 11
  17.  
  18. #define DIALOG_VOTAR 40
  19. #define DIALOG_RESULTADO_VOTACAO 41
  20.  
  21.  
  22. enum iUrna
  23. {
  24.     Float:PosX,
  25.     Float:PosY,
  26.     Float:PosZ,
  27.     Obj,
  28.     Text3D:TextUrna
  29. };
  30. new InfoUrnas[MAX_URNAS][iUrna];
  31. public OnFilterScriptInit()
  32. {
  33.     print("\n--------------------------------------");
  34.     print(" By Aninhaah  - ");
  35.     print("--------------------------------------\n");
  36.  
  37.     CarregarUrnas();
  38.     return 1;
  39. }
  40.  
  41. public OnFilterScriptExit()
  42. {
  43.     DOF2_Exit();
  44.     return 1;
  45. }
  46.  
  47. CMD:mecandidatar(playerid, params[])
  48. {
  49.     new file[56];
  50.     format(file, sizeof(file),PASTA_USUARIOS, Nome(playerid));
  51.     if(!DOF2_FileExists(ConfigEleicao) || DOF2_GetBool(ConfigEleicao,"VotacaoIniciada") == true || DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == false) return SendClientMessage(playerid, -1, "Não está na época de eleição ou a votação já foi iniciada.");
  52.     if(DOF2_FileExists(file))
  53.     {
  54.         if(DOF2_GetBool(file,"Candidato") == true) return SendClientMessage(playerid, -1, "Você já é candidato.");
  55.         if(isnull(params) || strval(params)) return SendClientMessage(playerid, -1, "Use: /MeCandidatar [Nome Partido (sem números)]");
  56.         DOF2_SetBool(file,"Candidato", true);
  57.         DOF2_SetString(file, "Partido", params);
  58.         DOF2_SaveFile();
  59.         if(!DOF2_FileExists(CANDIDATOS_ELEICAO)) { DOF2_CreateFile(CANDIDATOS_ELEICAO); }
  60.         if(!DOF2_FileExists(ID_CANDIDATO))
  61.         {
  62.             DOF2_CreateFile(ID_CANDIDATO);
  63.             DOF2_SetInt(ID_CANDIDATO,"ID", 1);
  64.             DOF2_SaveFile();
  65.         }
  66.         new tag[28];
  67.         format(tag, sizeof(tag),"Candidato %d", DOF2_GetInt(ID_CANDIDATO,"ID"));
  68.         DOF2_SetString(CANDIDATOS_ELEICAO, tag, Nome(playerid));
  69.         DOF2_SaveFile();
  70.         if(!DOF2_FileExists(VOTOS_CANDIDATOS)) { DOF2_CreateFile(VOTOS_CANDIDATOS); }
  71.         DOF2_SetInt(VOTOS_CANDIDATOS,tag,0);
  72.         DOF2_SaveFile();
  73.         DOF2_SetInt(ID_CANDIDATO,"ID", DOF2_GetInt(ID_CANDIDATO,"ID") +1);
  74.         DOF2_SaveFile();
  75.         new string[110];
  76.         format(string, sizeof(string),"%s é o mais novo candidato! Partido: %s", Nome(playerid), params);
  77.         SendClientMessageToAll(-1, string);
  78.     }
  79.     else return SendClientMessage(playerid, -1, "Sua conta não está registrada.");
  80.     return 1;
  81. }
  82. CMD:votar(playerid)
  83. {
  84.     if(!DOF2_FileExists(ConfigEleicao) || DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == false) return SendClientMessage(playerid, -1, "Não está na época de votação!");
  85.     if(DOF2_GetBool(ConfigEleicao, "VotacaoIniciada") == false) return SendClientMessage(playerid, -1, "Ainda não começou a votação!");
  86.     new file[56];
  87.     format(file, sizeof(file),PASTA_USUARIOS, Nome(playerid));
  88.     if(DOF2_FileExists(file))
  89.     {
  90.         for(new u = 0; u  < MAX_URNAS; u++)
  91.         {
  92.             if(IsPlayerInRangeOfPoint(playerid, 2.0, InfoUrnas[u][PosX], InfoUrnas[u][PosY], InfoUrnas[u][PosZ]))
  93.             {
  94.                 if(DOF2_GetBool(file,"JaVotou") == true) return SendClientMessage(playerid, -1, "Você já votou.");
  95.                 new str[50],string[500];
  96.                 for(new c = 0; c < MAX_CANDIDATOS; c++)
  97.                 {
  98.                     new tag[25];
  99.                     format(tag, sizeof(tag),"Candidato %d", c);
  100.                     if(!DOF2_FileExists(CANDIDATOS_ELEICAO))  return SendClientMessage(playerid, -1, "Ainda não tem nenhum candidato!");
  101.                     if(DOF2_IsSet(CANDIDATOS_ELEICAO, tag))
  102.                     {
  103.                         format(str, sizeof(str),"%s\n", DOF2_GetString(CANDIDATOS_ELEICAO, tag));
  104.                         strcat(string, str);
  105.                     }
  106.                 }
  107.                 ShowPlayerDialog(playerid, DIALOG_VOTAR, DIALOG_STYLE_LIST,"Escolha alguém para votar", string, "Votar","Cancelar");
  108.             }
  109.         }
  110.     }
  111.     return 1;
  112. }
  113. CMD:iniciareleicao(playerid)
  114. {
  115.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Sem permissão!");
  116.     if(!DOF2_FileExists(ConfigEleicao))
  117.     {
  118.         DOF2_CreateFile(ConfigEleicao);
  119.         DOF2_SetBool(ConfigEleicao,"EleicaoAberta", true);
  120.         DOF2_SetBool(ConfigEleicao,"VotacaoIniciada", false);
  121.         DOF2_SaveFile();
  122.         DOF2_CreateFile(CANDIDATOS_ELEICAO);
  123.         DOF2_SetString(CANDIDATOS_ELEICAO,"Candidato 0", "Voto Branco");
  124.         DOF2_SaveFile();
  125.         DOF2_CreateFile(VOTOS_CANDIDATOS);
  126.         DOF2_SetInt(VOTOS_CANDIDATOS,"Candidato 0", 0);
  127.         DOF2_SaveFile();
  128.         SendClientMessageToAll(-1, "Foi iniciada a nova eleição! Se candidate (/mecandidatar)");
  129.     }
  130.     else
  131.     {
  132.         if(DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == true) return SendClientMessage(playerid, -1, "A eleição já começou, termine essa eleição! (/terminareleicao)");
  133.         DOF2_SetBool(ConfigEleicao,"EleicaoAberta", true);
  134.         DOF2_SetBool(ConfigEleicao,"VotacaoIniciada", false);
  135.         DOF2_SaveFile();
  136.         DOF2_CreateFile(CANDIDATOS_ELEICAO);
  137.         DOF2_SetString(CANDIDATOS_ELEICAO,"Candidato 0", "Voto Branco");
  138.         DOF2_SaveFile();
  139.         DOF2_CreateFile(VOTOS_CANDIDATOS);
  140.         DOF2_SetInt(VOTOS_CANDIDATOS,"Candidato 0", 0);
  141.         DOF2_SaveFile();
  142.         SendClientMessageToAll(-1, "Foi iniciada a nova eleição! Se candidate (/mecandidatar)");
  143.     }
  144.     return 1;
  145. }
  146. CMD:terminareleicao(playerid)
  147. {
  148.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Sem permissão!");
  149.     if(!DOF2_FileExists(ConfigEleicao)) return SendClientMessage(playerid, -1, "Não foi iniciada nenhuma eleição!");
  150.     if(DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == false) return SendClientMessage(playerid, -1, "Não está tendo eleição, comece uma eleição! (/iniciareleicao)");
  151.     if(DOF2_GetBool(ConfigEleicao,"VotacaoIniciada") == true) return SendClientMessage(playerid,-1,"A votação já foi iniciada.");
  152.     DOF2_SetBool(ConfigEleicao,"EleicaoAberta", true);
  153.     DOF2_SetBool(ConfigEleicao,"VotacaoIniciada", true);
  154.     DOF2_SaveFile();
  155.     SendClientMessageToAll(-1, "O prazo para se candidatar acabou. As votações já começaram!");
  156.     SendClientMessage(playerid,-1,"Use: /terminarvotacao para terminar.");
  157.     return 1;
  158. }
  159. CMD:terminarvotacao(playerid)
  160. {
  161.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Sem permissão!");
  162.     if(!DOF2_FileExists(ConfigEleicao)) return SendClientMessage(playerid, -1, "Não foi iniciada nenhuma eleição!");
  163.     if(DOF2_GetBool(ConfigEleicao,"VotacaoIniciada") == false) return SendClientMessage(playerid, -1, "Não está tendo votação, comece uma eleição! (/iniciareleicao)");
  164.     DOF2_SetBool(ConfigEleicao,"EleicaoAberta", false);
  165.     DOF2_SetBool(ConfigEleicao,"VotacaoIniciada", false);
  166.     DOF2_SaveFile();
  167.     new string[500], str[70];
  168.     for(new c = 0; c < MAX_CANDIDATOS; c++)
  169.     {
  170.         new tag[25];
  171.         format(tag, sizeof(tag),"Candidato %d", c);
  172.         if(DOF2_IsSet(CANDIDATOS_ELEICAO, tag) && DOF2_IsSet(VOTOS_CANDIDATOS, tag))
  173.         {
  174.             format(str, sizeof(str),"Candidato %s: %d votos\n", DOF2_GetString(CANDIDATOS_ELEICAO, tag), DOF2_GetInt(VOTOS_CANDIDATOS, tag));
  175.             strcat(string, str);
  176.         }
  177.     }
  178.     for(new i = 0; i < MAX_PLAYERS; i++)
  179.     {
  180.         ShowPlayerDialog(i, DIALOG_RESULTADO_VOTACAO, DIALOG_STYLE_MSGBOX,"RESULTADO DAS ELEIÇÕES!", string, "Fechar","");
  181.     }
  182.     DOF2_RemoveFile(ConfigEleicao);
  183.     DOF2_RemoveFile(ID_CANDIDATO);
  184.     DOF2_RemoveFile(VOTOS_CANDIDATOS);
  185.     DOF2_RemoveFile(CANDIDATOS_ELEICAO);
  186.     DOF2_RemoveFile(ID_URNA);
  187.     for(new u = 1; u < MAX_URNAS; u++)
  188.     {
  189.         DestroyDynamicObject(InfoUrnas[u][Obj]);
  190.         Delete3DTextLabel(InfoUrnas[u][TextUrna]);
  191.     }
  192.     for(new i = 0; i < MAX_PLAYERS; i++)
  193.     {
  194.         new file[56];
  195.         format(file, sizeof(file),PASTA_USUARIOS, Nome(i));
  196.         if(DOF2_FileExists(file))
  197.         {
  198.             DOF2_Unset(file,"JaVotou");
  199.             DOF2_Unset(file,"Candidato");
  200.             DOF2_Unset(file,"Partido");
  201.             DOF2_SaveFile();
  202.         }
  203.     }
  204.     return 1;
  205. }
  206. CMD:criarurna(playerid)
  207. {
  208.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Sem permissao!");
  209.     if(!DOF2_FileExists(ConfigEleicao) || DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == false) return SendClientMessage(playerid, -1, "As eleições não começaram!");
  210.     new Float:Pos[3];
  211.     GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  212.     if(!DOF2_FileExists(ID_URNA))
  213.     {
  214.         DOF2_CreateFile(ID_URNA);
  215.         DOF2_SetInt(ID_URNA,"ID", 0);
  216.         DOF2_SaveFile();
  217.     }
  218.     new arq[25], IDU = DOF2_GetInt(ID_URNA,"ID");
  219.     format(arq, sizeof(arq),URNAS, IDU);
  220.     if(!DOF2_FileExists(arq))
  221.     {
  222.         DOF2_CreateFile(arq);
  223.         DOF2_SetFloat(arq, "PosX", Pos[0]);
  224.         DOF2_SetFloat(arq, "PosY", Pos[1]);
  225.         DOF2_SetFloat(arq, "PosZ", Pos[2]);
  226.         DOF2_SaveFile();
  227.         new string[100];
  228.         format(string, sizeof(string),"Urna %d criada com sucesso!", IDU);
  229.         SendClientMessage(playerid, -1, string);
  230.         InfoUrnas[IDU][Obj] = CreateDynamicObject(3013, Pos[0], Pos[1], Pos[2], 0,0,0);
  231.         InfoUrnas[IDU][TextUrna] = Create3DTextLabel("Urna de eleição!\nUse: /votar", -1, Pos[0], Pos[1], Pos[2], 14.0,0,0);
  232.         InfoUrnas[IDU][PosX] = Pos[0];
  233.         InfoUrnas[IDU][PosY] = Pos[1];
  234.         InfoUrnas[IDU][PosZ] = Pos[2];
  235.     }
  236.     DOF2_SetInt(ID_URNA,"ID", DOF2_GetInt(ID_URNA,"ID") +1);
  237.     DOF2_SaveFile();
  238.     return 1;
  239. }
  240. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  241. {
  242.     if(dialogid == DIALOG_VOTAR)
  243.     {
  244.         if(!response) return SendClientMessage(playerid, -1, "Você cancelou a votação!");
  245.         new cand = listitem;
  246.         new tag[25];
  247.         format(tag, sizeof(tag),"Candidato %d", cand);
  248.         if(DOF2_IsSet(VOTOS_CANDIDATOS,tag))
  249.         {
  250.             DOF2_SetInt(VOTOS_CANDIDATOS, tag, DOF2_GetInt(VOTOS_CANDIDATOS,tag)+1);
  251.             DOF2_SaveFile();
  252.         }
  253.         new string[90];
  254.         format(string, sizeof(string),"Você votou em %s!", DOF2_GetString(CANDIDATOS_ELEICAO,tag));
  255.         SendClientMessage(playerid, -1, string);
  256.         new file[56];
  257.         format(file, sizeof(file),PASTA_USUARIOS, Nome(playerid));
  258.         if(!DOF2_FileExists(file)) return 1;
  259.         DOF2_SetBool(file,"JaVotou", true);
  260.         DOF2_SaveFile();
  261.         return 1;
  262.     }
  263.     return 1;
  264. }
  265.  
  266.  
  267. Nome(playerid)
  268. {
  269.     new nome[MAX_PLAYER_NAME];
  270.     GetPlayerName(playerid, nome, sizeof(nome));
  271.     return nome;
  272. }
  273.  
  274. stock CarregarUrnas()
  275. {
  276.     new count;
  277.     for(new u = 0; u  < MAX_URNAS; u++)
  278.     {
  279.         new file[56];
  280.         format(file, sizeof(file), URNAS, u);
  281.         if(DOF2_FileExists(file) && DOF2_FileExists(ConfigEleicao) && DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == true)
  282.         {
  283.             InfoUrnas[u][PosX] = DOF2_GetFloat(file,"PosX");
  284.             InfoUrnas[u][PosY] = DOF2_GetFloat(file,"PosY");
  285.             InfoUrnas[u][PosZ] = DOF2_GetFloat(file,"PosZ");
  286.             InfoUrnas[u][Obj] = CreateDynamicObject(3013, InfoUrnas[u][PosX], InfoUrnas[u][PosY], InfoUrnas[u][PosZ], 0,0,0);
  287.             InfoUrnas[u][TextUrna] = Create3DTextLabel("Urna de eleição!\nUse: /votar", -1, InfoUrnas[u][PosX], InfoUrnas[u][PosY], InfoUrnas[u][PosZ], 14.0,0);
  288.             count++;
  289.         }
  290.     }
  291.     printf("%d urnas carregadas!", count);
  292.     return 1;
  293. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement