Advertisement
Aninhaah

aElection v1.5 by Aninhaah

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