Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //_______________________________________INCLUDES_________________________________________//
- #include <a_samp>
- #include <zcmd>
- #include <sscanf>
- #include <DOF2>
- #include <streamer>
- //_______________________________________DEFINES_______________________________________//
- //_________ARQUIVOS______//
- #define PASTA_USUARIOS "Jogadores/%s.ini"
- #define CANDIDATOS_ELEICAO "aElection/Candidatos/Candidato %d.ini"
- #define URNAS "aElection/Urnas/Urna %d.ini"
- #define ConfigEleicao "aElection/ConfigEleicao.ini"
- #define NumerosOcupados "aElection/NumerosOcupados.ini"
- //__________LIMITES_________//
- #define MAX_CANDIDATOS 31
- #define MAX_URNAS 11
- //__________DIALOGS_________//
- #define DIALOG_CONFIRMAR_VOTO 101
- #define DIALOG_INFO 102
- //___________CORES__________//
- #define COR_VERDE 0xADFF2FFF
- #define COR_AZUL 0x00BFFFFF
- #define COR_VERMELHO 0xFF0000FF
- enum iUrna
- {
- Float:PosX,
- Float:PosY,
- Float:PosZ,
- Obj,
- Text3D:TextUrna
- };
- new InfoUrnas[MAX_URNAS][iUrna];
- public OnFilterScriptInit()
- {
- print("\n---------------------------------------------------------------------");
- print("aElection (Sistema de Eleição) v3.0 By Aninhaah (humildadeforever) - ");
- print("---------------------------------------------------------------------\n");
- CarregarUrnas();
- return 1;
- }
- public OnFilterScriptExit()
- {
- DOF2_Exit();
- return 1;
- }
- //________________________________________________________COMANDOS______________________________
- //____________________ COMANDO INFORMATIVO
- CMD:aelection(playerid)
- {
- SendClientMessage(playerid, COR_AZUL,"|______________________________________ Créditos______________________________________|");
- SendClientMessage(playerid, -1, "Esse servidor utiliza o FilterScript {00BFFF}aElection v3.0{FFFFFF} criado por {00BFFF}Aninhaah{FFFFFF} ({00BFFF}humildadeforever{FFFFFF}).");
- SendClientMessage(playerid, COR_AZUL, "Comandos de jogadores: {FFFFFF}/Candidatos, /MeCandidatar, /Votar, /Propaganda, /ResultadoVotacao.");
- SendClientMessage(playerid, COR_AZUL, "Comandos de admins: {FFFFFF}/IniciarEleicao, /InterromperEleicao, /IniciarVotacao, /TerminarVotacao.");
- SendClientMessage(playerid, COR_AZUL, "Comandos de admins: {FFFFFF}/CriarUrna, /DeletarUrna e /ZerarCandidatos.");
- SendClientMessage(playerid, COR_AZUL,"|_____________________________________________________________________________________|");
- return 1;
- }
- //__________________ COMANDOS ADMINISTRATIVOS
- CMD:iniciareleicao(playerid)
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Sem permissão!");
- if(!DOF2_FileExists(ConfigEleicao)) { DOF2_CreateFile(ConfigEleicao); }
- if(DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == true) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: A eleição já começou. Para interrompê-la utilize \"{FFFFFF}/interrompereleicao{FF0000}\".");
- DOF2_SetBool(ConfigEleicao,"EleicaoAberta", true);
- DOF2_SetBool(ConfigEleicao,"VotacaoIniciada", false);
- DOF2_SaveFile();
- SendClientMessageToAll(COR_AZUL, "Foi iniciada a nova eleição! Se candidate (/mecandidatar)");
- return 1;
- }
- CMD:interrompereleicao(playerid)
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Sem permissão!");
- if(!DOF2_FileExists(ConfigEleicao) || DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == false) return SendClientMessage(playerid, COR_VERMELHO,"ERRO: Nenhuma eleição foi iniciada.");
- DOF2_SetBool(ConfigEleicao,"EleicaoAberta", false);
- DOF2_SetBool(ConfigEleicao,"VotacaoIniciada", false);
- DOF2_SaveFile();
- new str[90];
- format(str, sizeof(str),"%s interrompeu a eleição.", NomeJogador(playerid));
- SendClientMessageToAll(COR_AZUL, str);
- EncerrarEleicoes();
- return 1;
- }
- CMD:iniciarvotacao(playerid)
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Sem permissão!");
- if(!DOF2_FileExists(ConfigEleicao)) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Não foi iniciada nenhuma eleição!");
- if(DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == false) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Não está tendo eleição, comece uma eleição! (/iniciareleicao)");
- if(DOF2_GetBool(ConfigEleicao,"VotacaoIniciada") == true) return SendClientMessage(playerid,COR_VERMELHO,"ERRO: A votação já foi iniciada.");
- DOF2_SetBool(ConfigEleicao,"VotacaoIniciada", true);
- DOF2_SaveFile();
- SendClientMessageToAll(COR_AZUL, "O prazo para se candidatar acabou. A votação foi iniciada!");
- SendClientMessageToAll(COR_AZUL, "Para efetuar seu voto, vá até uma urna e digite \"{FFFFFF}/votar{00BFFF}\".");
- SendClientMessage(playerid,COR_AZUL,"<!> Digite \"{FFFFFF}/terminarvotacao{00BFFF}\" para terminar a votação.");
- CarregarUrnas();
- return 1;
- }
- CMD:terminarvotacao(playerid)
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Sem permissão!");
- if(!DOF2_FileExists(ConfigEleicao) || DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == false) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Nenhuma eleição foi iniciada.");
- if(DOF2_GetBool(ConfigEleicao,"VotacaoIniciada") == false) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Não está tendo votação. Comece uma digitando \"{FFFFFF}/IniciarVotacao{FF0000}\".");
- DOF2_SetBool(ConfigEleicao,"EleicaoAberta", false);
- DOF2_SetBool(ConfigEleicao,"VotacaoIniciada", false);
- DOF2_SetBool(ConfigEleicao,"Resultado", true);
- DOF2_SaveFile();
- new string[600], str[150], file[56];
- for(new c = 1; c < MAX_CANDIDATOS; c++)
- {
- format(file, sizeof(file),CANDIDATOS_ELEICAO, c);
- if(DOF2_FileExists(file) && DOF2_IsSet(file,"Nome") && DOF2_IsSet(file,"Votos"))
- {
- format(str, sizeof(str),"Candidato %s: \t\t%d votos\n", DOF2_GetString(file, "Nome"), DOF2_GetInt(file, "Votos"));
- strcat(string, str);
- }
- }
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- ShowPlayerDialog(i, DIALOG_INFO, DIALOG_STYLE_MSGBOX,"RESULTADO DAS ELEIÇÕES:", string, "Fechar","");
- }
- EncerrarEleicoes();
- return 1;
- }
- CMD:criarurna(playerid)
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Sem permissao!");
- if(!DOF2_FileExists(ConfigEleicao) || DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == false) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: As eleições não começaram!");
- new Float:Pos[3], arq[56];
- GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
- for(new u = 1; u < MAX_URNAS; u++)
- {
- format(arq, sizeof(arq), URNAS, u);
- if(!DOF2_FileExists(arq))
- {
- DOF2_CreateFile(arq);
- DOF2_SetFloat(arq, "PosX", Pos[0]);
- DOF2_SetFloat(arq, "PosY", Pos[1]);
- DOF2_SetFloat(arq, "PosZ", Pos[2]);
- DOF2_SaveFile();
- new string[100];
- format(string, sizeof(string),"Urna {ADFF2F}%d {FFFFFF}criada com sucesso!", u);
- SendClientMessage(playerid, -1, string);
- InfoUrnas[u][Obj] = CreateDynamicObject(2941, Pos[0], Pos[1], Pos[2], 0,0,0);
- InfoUrnas[u][TextUrna] = Create3DTextLabel("Urna de eleição!\nUse: /votar", -1, Pos[0], Pos[1], Pos[2], 14.0,0,0);
- InfoUrnas[u][PosX] = Pos[0];
- InfoUrnas[u][PosY] = Pos[1];
- InfoUrnas[u][PosZ] = Pos[2];
- break;
- }
- }
- return 1;
- }
- CMD:deletarurna(playerid, params[])
- {
- new idurna = 0, str[90], file[56];
- if(isnull(params))
- {
- for(new u = 1; u < MAX_URNAS; u++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 2.0, InfoUrnas[u][PosX], InfoUrnas[u][PosY], InfoUrnas[u][PosZ]))
- {
- idurna = u;
- break ;
- }
- }
- }
- else if(!isnull(params))
- {
- idurna = strval(params);
- }
- if(idurna == 0) return SendClientMessage(playerid, -1, "Use: /DeletarUrna [ID] ou digite o comando perto de uma urna.");
- format(file, sizeof(file), URNAS, idurna);
- if(!DOF2_FileExists(file)) return SendClientMessage(playerid, -1, "ERRO: O arquivo dessa urna não existe.");
- DOF2_RemoveFile(file);
- Delete3DTextLabel(InfoUrnas[idurna][TextUrna]);
- DestroyDynamicObject(InfoUrnas[idurna][Obj]);
- format(str, sizeof(str),"A urna {ADFF2F}%d {FFFFFF}foi deletada com sucesso!", idurna);
- SendClientMessage(playerid, -1, str);
- return 1;
- }
- CMD:zerarcandidatos(playerid)
- {
- new file[56];
- for(new c = 1; c < MAX_CANDIDATOS; c++)
- {
- format(file, sizeof(file),CANDIDATOS_ELEICAO, c);
- if(DOF2_FileExists(file))
- {
- DOF2_RemoveFile(file);
- }
- }
- DOF2_RemoveFile(ConfigEleicao);
- return 1;
- }
- //___________________________COMANDOS DE JOGADORES
- CMD:candidatos(playerid)
- {
- if(!DOF2_FileExists(ConfigEleicao) || DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == false) return SendClientMessage(playerid, COR_VERMELHO,"ERRO: Não é época de eleição.");
- new str[146], file[56], string[600], bool: count = false;
- for(new c = 1; c < MAX_CANDIDATOS; c++)
- {
- format(file, sizeof(file), CANDIDATOS_ELEICAO, c);
- if(DOF2_FileExists(file) && DOF2_IsSet(file,"Partido") && DOF2_IsSet(file,"Nome") && DOF2_IsSet(file,"Numero"))
- {
- format(str, sizeof(str),"{00BFFF}Candidato: {FFFFFF}%s\t{00BFFF}Partido: {FFFFFF}%s\t{00BFFF}Número: {FFFFFF}%d\n", DOF2_GetString(file,"Nome"), DOF2_GetString(file,"Partido"), DOF2_GetInt(file,"Numero"));
- strcat(string, str);
- count = true;
- }
- }
- if(count == false) return SendClientMessage(playerid, -1, "<!> Nenhum candidato até o momento.");
- ShowPlayerDialog(playerid, DIALOG_INFO, DIALOG_STYLE_MSGBOX,"[aElection] - Candidatos", string, "Fechar","");
- return 1;
- }
- CMD:mecandidatar(playerid, params[])
- {
- if(!DOF2_FileExists(ConfigEleicao) || DOF2_GetBool(ConfigEleicao,"VotacaoIniciada") == true || DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == false) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Não está na época de eleição ou a votação já foi iniciada.");
- if(!DOF2_FileExists(ContaJogador(playerid))) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Sua conta não está registrada.");
- if(DOF2_GetInt(ContaJogador(playerid),"Candidato") > 0) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Você já é candidato.");
- new numero, partido[30], string[180];
- if(sscanf(params,"ds", numero, partido)) return SendClientMessage(playerid, COR_AZUL, "Use: /MeCandidatar [Número pra votar] [Nome Partido]");
- if(numero < 10 || numero > 99) return SendClientMessage(playerid, COR_VERMELHO,"ERRO: O número deve conter 2 algarismos.");
- format(string, sizeof(string),"%d", numero);
- if(DOF2_FileExists(NumerosOcupados) && DOF2_IsSet(NumerosOcupados, string)) return SendClientMessage(playerid, COR_VERMELHO,"ERRO: Esse número já está sendo usado.");
- new file[56], bool: count = false;
- for(new c = 1; c < MAX_CANDIDATOS; c++)
- {
- format(file, sizeof(file), CANDIDATOS_ELEICAO, c);
- if(!DOF2_FileExists(file))
- {
- DOF2_CreateFile(file);
- DOF2_SetString(file,"Nome", NomeJogador(playerid));
- DOF2_SetString(file,"Partido", partido);
- DOF2_SetInt(file,"Numero", numero);
- DOF2_SetInt(file,"Votos", 0);
- DOF2_SaveFile();
- format(string, sizeof(string),"%d", numero);
- if(!DOF2_FileExists(NumerosOcupados)) { DOF2_CreateFile(NumerosOcupados); }
- DOF2_SetBool(NumerosOcupados, string, true);
- DOF2_SaveFile();
- DOF2_SetInt(ContaJogador(playerid),"Candidato", c);
- DOF2_SaveFile();
- count = true;
- break;
- }
- }
- if(count == false) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Não foi possível realizar a candidatura.");
- format(string, sizeof(string),"%s {FFFFFF}é o mais novo candidato! Partido: {FF0000}%s{FFFFFF}. Número: {FF0000} %d{FFFFFF}.", NomeJogador(playerid), partido, numero);
- SendClientMessageToAll(COR_VERMELHO, string);
- return 1;
- }
- CMD:propaganda(playerid, params[])
- {
- if(!DOF2_FileExists(ContaJogador(playerid)) || !DOF2_IsSet(ContaJogador(playerid),"Candidato") || DOF2_GetInt(ContaJogador(playerid),"Candidato") < 1) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Você não é um candidato.");
- if(DOF2_GetBool(ConfigEleicao,"VotacaoIniciada") == true) return SendClientMessage(playerid, COR_VERMELHO,"ERRO: A votação já foi iniciada. É proibido fazer propaganda.");
- if(isnull(params)) return SendClientMessage(playerid, COR_AZUL,"Use: /Propaganda [Texto]");
- new string[128], file[56];
- format(file, sizeof(file), CANDIDATOS_ELEICAO, DOF2_GetInt(ContaJogador(playerid),"Candidato"));
- format(string, sizeof(string),"[%s] %s: %s", DOF2_GetString(file,"Partido"), NomeJogador(playerid), params);
- SendClientMessageToAll(COR_AZUL, "|__________________________Propaganda Política__________________________|");
- SendClientMessageToAll(-1, string);
- SendClientMessageToAll(COR_AZUL,"|______________________________________________________________________|");
- return 1;
- }
- CMD:votar(playerid, params[])
- {
- if(!DOF2_FileExists(ConfigEleicao) || DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == false) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Não está na época de votação!");
- if(DOF2_GetBool(ConfigEleicao, "VotacaoIniciada") == false) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Ainda não começou a votação!");
- if(!DOF2_FileExists(ContaJogador(playerid))) return SendClientMessage(playerid, COR_VERMELHO,"ERRO: Você não é registrado.");
- new file[56], bool: counturna = false, bool: countcand = false;
- for(new u = 1; u < MAX_URNAS; u++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 2.0, InfoUrnas[u][PosX], InfoUrnas[u][PosY], InfoUrnas[u][PosZ]))
- {
- counturna = true;
- if(DOF2_GetBool(ContaJogador(playerid),"JaVotou") == true) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Você já votou.");
- if(isnull(params))
- {
- SendClientMessage(playerid, COR_AZUL,"Use: /Votar [Número].");
- SendClientMessage(playerid, COR_AZUL,"<!> Não sabe os números? Digite: \"{FFFFFF}/Candidatos{00BFFF}\".");
- return 1;
- }
- for(new c = 1; c < MAX_CANDIDATOS; c++)
- {
- format(file, sizeof(file), CANDIDATOS_ELEICAO, c);
- if(strval(params) == DOF2_GetInt(file,"Numero"))
- {
- SetPVarInt(playerid,"VotoCandidato", c);
- new string[170];
- format(string, sizeof(string),"{FFFFFF}Você está prestes a votar em {00BFFF}%s {FFFFFF}({00BFFF}%d{FFFFFF}). Partido {00BFFF}%s{FFFFFF}.\n\n{FFFFFF}Deseja confirmar esse voto?", DOF2_GetString(file, "Nome"), DOF2_GetInt(file,"Numero"), DOF2_GetString(file,"Partido"));
- ShowPlayerDialog(playerid, DIALOG_CONFIRMAR_VOTO, DIALOG_STYLE_MSGBOX,"[aElection] - Votação", string,"Votar","Cancelar");
- countcand = true;
- break;
- }
- }
- }
- }
- if(counturna == false) return SendClientMessage(playerid, -1, "ERRO: Nenhuma urna por perto.");
- if(countcand == false) return SendClientMessage(playerid, -1, "ERRO: Nenhum candidato com esse número.");
- return 1;
- }
- CMD:resultadovotacao(playerid)
- {
- if(!DOF2_FileExists(ConfigEleicao) || !DOF2_IsSet(ConfigEleicao, "Resultado") || DOF2_GetBool(ConfigEleicao,"Resultado") == false) return SendClientMessage(playerid, COR_VERMELHO, "ERRO: Nenhum resultado disponível.");
- new string[600], str[150], file[56];
- for(new c = 1; c < MAX_CANDIDATOS; c++)
- {
- format(file, sizeof(file),CANDIDATOS_ELEICAO, c);
- if(DOF2_FileExists(file) && DOF2_IsSet(file,"Nome") && DOF2_IsSet(file,"Votos"))
- {
- format(str, sizeof(str),"Candidato %s: \t\t%d votos\n", DOF2_GetString(file, "Nome"), DOF2_GetInt(file, "Votos"));
- strcat(string, str);
- }
- }
- ShowPlayerDialog(playerid, DIALOG_INFO, DIALOG_STYLE_MSGBOX,"RESULTADO DAS ELEIÇÕES:", string, "Fechar","");
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == DIALOG_CONFIRMAR_VOTO)
- {
- if(!response) return SendClientMessage(playerid, COR_VERDE, "<!> Você cancelou a votação!");
- new voto = GetPVarInt(playerid,"VotoCandidato"), file[56];
- format(file, sizeof(file), CANDIDATOS_ELEICAO, voto);
- new string[96];
- format(string, sizeof(string),"Você computou um voto para{FFFFFF} %s{00BFFF}. Obrigado por votar.", DOF2_GetString(file,"Nome"));
- SendClientMessage(playerid, COR_AZUL, string);
- DOF2_SetBool(ContaJogador(playerid),"JaVotou", true);
- DOF2_SaveFile();
- DOF2_SetInt(file, "Votos", DOF2_GetInt(file,"Votos")+1);
- DOF2_SaveFile();
- return 1;
- }
- return 1;
- }
- NomeJogador(playerid)
- {
- new nome[MAX_PLAYER_NAME];
- GetPlayerName(playerid, nome, sizeof(nome));
- return nome;
- }
- ContaJogador(playerid)
- {
- new file[56];
- format(file, sizeof(file),PASTA_USUARIOS, NomeJogador(playerid));
- return file;
- }
- CarregarUrnas()
- {
- new count = 0;
- for(new u = 0; u < MAX_URNAS; u++)
- {
- new file[56];
- format(file, sizeof(file), URNAS, u);
- if(DOF2_FileExists(file) && DOF2_FileExists(ConfigEleicao) && DOF2_GetBool(ConfigEleicao,"EleicaoAberta") == true)
- {
- InfoUrnas[u][PosX] = DOF2_GetFloat(file,"PosX");
- InfoUrnas[u][PosY] = DOF2_GetFloat(file,"PosY");
- InfoUrnas[u][PosZ] = DOF2_GetFloat(file,"PosZ");
- InfoUrnas[u][Obj] = CreateDynamicObject(2941, InfoUrnas[u][PosX], InfoUrnas[u][PosY], InfoUrnas[u][PosZ], 0,0,0);
- InfoUrnas[u][TextUrna] = Create3DTextLabel("Urna de eleição!\nUse: /votar", -1, InfoUrnas[u][PosX], InfoUrnas[u][PosY], InfoUrnas[u][PosZ], 14.0,0);
- count++;
- }
- }
- printf("%d urnas carregadas!", count);
- return 1;
- }
- EncerrarEleicoes()
- {
- //DOF2_RemoveFile(ConfigEleicao);
- DOF2_RemoveFile(NumerosOcupados);
- for(new u = 0; u < MAX_URNAS; u++)
- {
- DestroyDynamicObject(InfoUrnas[u][Obj]);
- Delete3DTextLabel(InfoUrnas[u][TextUrna]);
- }
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- if(DOF2_FileExists(ContaJogador(i)))
- {
- DOF2_Unset(ContaJogador(i),"JaVotou");
- DOF2_Unset(ContaJogador(i),"Candidato");
- DOF2_SaveFile();
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement