Advertisement
Larceny

ES

Sep 18th, 2011
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.12 KB | None | 0 0
  1. /*                 
  2.                     ********************************
  3.                         ES - Eleição Sys.
  4.                     ********************************
  5. Descrição:
  6.     Permite que os jogadores concorram a eleições, como prefeitura, administração ou qualquer coisa que desejar.
  7. Versão:
  8.     1.0
  9. Developer:
  10.     Luke "Larceny" G.
  11.     "Lós" .
  12. ChangeLOG:
  13.     18/09/2011:
  14.         Primeira versão.
  15. Thanks To:
  16.     ZeeX            - ZCMD Command Processor.
  17.     Double-O-Seven  - DOF2 Fast INI file system.
  18.     Ryder`          - rBits fast and easy method to use Bits.
  19.     SA-MP Team      - For All.
  20.     Shickcard       - Idea.
  21. */
  22.  
  23. #define FILTERSCRIPT
  24. // Settings
  25. #define DIALOG_MSG 358
  26. #define DIALOG_CAN 359
  27. #define DIALOG_VOT 360
  28. #define MAX_CANDID 3
  29. #define CAND_PLACE 358.4222,186.2485,1008.3828
  30. #define VOTE_PLACE 358.2370,182.5879,1008.3828
  31.  
  32. #include <a_samp>
  33. #include <rBits>
  34. #include <zcmd>
  35. #include <DOF2>
  36.  
  37. forward ResetClientStats(clientid);
  38.  
  39. new CANDPICK;
  40. new VOTEPICK;
  41.  
  42. new isEleicaoStarted;
  43.  
  44. enum eBit1_pData
  45. {
  46.     isContestant,
  47.     isVoted
  48.     // ...
  49. };
  50.  
  51. new
  52.     Bit1:g_iBit1_pData[eBit1_pData] <MAX_PLAYERS>
  53. ;
  54.  
  55. stock GetPlayerNameEx(playerid)
  56. {
  57.     new string[MAX_PLAYER_NAME];
  58.     GetPlayerName(playerid, string, MAX_PLAYER_NAME);
  59.     return string;
  60. }
  61.  
  62. public ResetClientStats(clientid)
  63. {
  64.     Bit1_Set(g_iBit1_pData[isContestant], clientid, false);
  65.     Bit1_Set(g_iBit1_pData[isVoted], clientid, false);
  66.     return 1;
  67. }
  68.  
  69. public OnFilterScriptInit()
  70. {
  71.     print("\n--------------------------------------");
  72.     print(" Eleicao Sys. carregado com sucesso.");
  73.     print(" Larceny & Shickcard & Los.");
  74.     print("--------------------------------------\n");
  75.     // ...
  76.     CANDPICK = CreatePickup(1239, 2, CAND_PLACE, -1);
  77.     VOTEPICK = CreatePickup(1239, 2, VOTE_PLACE, -1);
  78.     // ...
  79.     new FileToRead[] = "ESettings/Settings.ini";
  80.     if(DOF2_GetInt(FileToRead, "CandidatesTotal") > MAX_CANDID){DOF2_SetInt(FileToRead, "CandidatesTotal", MAX_CANDID);}
  81.     if(DOF2_GetInt(FileToRead, "CandidatesTotal") == 0){DOF2_SetInt(FileToRead, "CandidatesTotal", 0);}
  82.     isEleicaoStarted = DOF2_GetInt(FileToRead, "EleicaoStarted");
  83.     DOF2_SaveFile();
  84.     return 1;
  85. }
  86.  
  87. public OnFilterScriptExit()
  88. {
  89.     DOF2_SetInt("ESettings/Settings.ini", "EleicaoStarted", isEleicaoStarted);
  90.     DOF2_Exit();
  91.     return 1;
  92. }
  93.  
  94. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  95. {
  96.     switch(dialogid)
  97.     {
  98.         case DIALOG_CAN:
  99.         {
  100.             if(!response) return 1;
  101.             new FileToRead[] = "ESettings/Settings.ini";
  102.             if(DOF2_GetInt(FileToRead, "CandidatesTotal") >= MAX_CANDID) return SendClientMessage(playerid, 0xB11D21AA, "(*) Não há mais vagas para candidatos.");
  103.             Bit1_Set(g_iBit1_pData[isContestant], playerid, true);
  104.             SendClientMessage(playerid, 0x1B12BCFF, "(*) Você agora é um candidato, use /candidatos para manter-se informado.");
  105.             new
  106.                 KeyToRead[32],
  107.                 Key2ToRead[32],
  108.                 StrToWrite[32];
  109.             format(KeyToRead, sizeof(KeyToRead), "Candidato%i", DOF2_GetInt(FileToRead, "CandidatesTotal"));
  110.             format(Key2ToRead, sizeof(Key2ToRead), "CandidatoVote%i", DOF2_GetInt(FileToRead, "CandidatesTotal"));
  111.             strmid(StrToWrite, DOF2_GetString(FileToRead, KeyToRead), 0, strlen(DOF2_GetString(FileToRead, KeyToRead)), 255);
  112.             //
  113.             DOF2_SetInt(FileToRead, "CandidatesTotal", DOF2_GetInt(FileToRead, "CandidatesTotal")+1);
  114.             DOF2_SetString(FileToRead, KeyToRead, GetPlayerNameEx(playerid));
  115.             DOF2_SetInt(FileToRead, Key2ToRead, 0);
  116.             DOF2_SaveFile();
  117.             new FileToWrite[64];
  118.             format(FileToWrite, sizeof(FileToWrite), "ESettings/%s.ini", GetPlayerNameEx(playerid));
  119.             DOF2_SetInt(FileToWrite, "isContestant", 1);
  120.             DOF2_SaveFile();
  121.         }
  122.         case DIALOG_VOT:
  123.         {
  124.             if(!response) return 1;
  125.             new FileToRead[] = "ESettings/Settings.ini";
  126.             new StrToShow[256];
  127.             for(new var=0;var<MAX_CANDID;var++)
  128.             {
  129.                 new
  130.                     KeyToRead[32],
  131.                     StrToWrite[32];
  132.                 format(KeyToRead, sizeof(KeyToRead), "Candidato%i", var);
  133.                 strmid(StrToWrite, DOF2_GetString(FileToRead, KeyToRead), 0, strlen(DOF2_GetString(FileToRead, KeyToRead)), 255);
  134.                 if(!strcmp(StrToWrite, " ", true)){strins(StrToShow, "Nenhum - 0 Votos\n", strlen(StrToShow));}
  135.                 else
  136.                 {
  137.                     new StrToConvert[64], StrToGet[32], VoteToGet[32];
  138.                     format(VoteToGet, sizeof(VoteToGet), "CandidatoVote%i", var);
  139.                     new MyVote;
  140.                     MyVote = DOF2_GetInt(FileToRead, VoteToGet);
  141.                     strmid(StrToGet, DOF2_GetString(FileToRead, KeyToRead), 0, strlen(DOF2_GetString(FileToRead, KeyToRead)), 255);
  142.                     format(StrToConvert, sizeof(StrToConvert), "%s - %i Votos\n", StrToGet, MyVote);
  143.                     strins(StrToShow, StrToConvert, strlen(StrToShow));
  144.                 }
  145.             }
  146.             ShowPlayerDialog (playerid, DIALOG_VOT+1, DIALOG_STYLE_LIST, "Candidatos", StrToShow, "Votar", "");
  147.         }
  148.         case DIALOG_VOT+1:
  149.         {
  150.             new FileToRead[] = "ESettings/Settings.ini";
  151.             new
  152.                 KeyToRead[32],
  153.                 StrToWrite[32];
  154.             format(KeyToRead, sizeof(KeyToRead), "Candidato%i", listitem);
  155.             strmid(StrToWrite, DOF2_GetString(FileToRead, KeyToRead), 0, strlen(DOF2_GetString(FileToRead, KeyToRead)), 255);
  156.             if(!strcmp(StrToWrite, " ", true)){ SendClientMessage(playerid, 0xB11D21AA, "(*) Candidato inválido."); }
  157.             else
  158.             {
  159.                 new VoteToGet[32];
  160.                 format(VoteToGet, sizeof(VoteToGet), "CandidatoVote%i", listitem);
  161.                 new MyVote;
  162.                 MyVote = DOF2_GetInt(FileToRead, VoteToGet);
  163.                 DOF2_SetInt(FileToRead, VoteToGet, MyVote+1);
  164.                 SendClientMessage(playerid, 0x1B12BCAA, "(*) Voto computado com sucesso.");
  165.                 Bit1_Set(g_iBit1_pData[isVoted], playerid, true);
  166.                 new FileToWrite[64];
  167.                 format(FileToWrite, sizeof(FileToWrite), "ESettings/%s.ini", GetPlayerNameEx(playerid));
  168.                 DOF2_SetInt(FileToWrite, "isVoted", 1);
  169.                 DOF2_SaveFile();
  170.             }
  171.         }
  172.     }
  173.     return 1;
  174. }
  175.  
  176. public OnPlayerConnect(playerid)
  177. {
  178.     ResetClientStats(playerid);
  179.     new UserFile[64];
  180.     format(UserFile, sizeof(UserFile), "ESettings/%s.ini", GetPlayerNameEx(playerid));
  181.     if(DOF2_FileExists(UserFile))
  182.     {
  183.         Bit1_Set(g_iBit1_pData[isContestant], playerid, DOF2_GetInt(UserFile, "isContestant"));
  184.         Bit1_Set(g_iBit1_pData[isVoted], playerid, DOF2_GetInt(UserFile, "isVoted"));
  185.         DOF2_SaveFile();
  186.     }
  187.     return 1;
  188. }
  189.  
  190. public OnPlayerPickUpPickup(playerid, pickupid)
  191. {
  192.     if (pickupid == CANDPICK)
  193.     {
  194.         if(isEleicaoStarted == 0) return SendClientMessage(playerid, -1, "(*) Não há nenhuma eleição ocorrendo.");
  195.         if(!Bit1_Get(g_iBit1_pData[isContestant], playerid))
  196.         {
  197.             ShowPlayerDialog (playerid, DIALOG_CAN, DIALOG_STYLE_MSGBOX, "Candidatação", "Você não é candidato,\n deseja candidatar-se?", "Sim", "Não");
  198.         }
  199.         else
  200.         {
  201.             ShowPlayerDialog (playerid, DIALOG_MSG, DIALOG_STYLE_MSGBOX, "Atenção", "Você já é um candidato.", "Fechar", "");
  202.         }
  203.     }
  204.     else if (pickupid == VOTEPICK)
  205.     {
  206.         if(isEleicaoStarted == 0) return SendClientMessage(playerid, -1, "(*) Não há nenhuma eleição ocorrendo.");
  207.         if(!Bit1_Get(g_iBit1_pData[isVoted], playerid))
  208.         {
  209.             ShowPlayerDialog (playerid, DIALOG_VOT, DIALOG_STYLE_MSGBOX, "Voto", "Você ainda não votou,\n deseja votar?", "Sim", "Não");
  210.         }
  211.         else
  212.         {
  213.             ShowPlayerDialog (playerid, DIALOG_MSG, DIALOG_STYLE_MSGBOX, "Atenção", "Você já votou.", "Fechar", "");
  214.         }
  215.     }
  216.     return 1;
  217. }
  218.  
  219. CMD:iniciareleicao(playerid, params[])
  220. {
  221.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "(*) Você não é um administrador conectado na RCON.");
  222.     if(isEleicaoStarted == 1) return SendClientMessage(playerid, -1, "(*) A eleição já está ocorrendo.");
  223.     SendClientMessageToAll(-1, "As eleições foram abertas pelo administrador.");
  224.     isEleicaoStarted = 1;
  225.     return 1;
  226. }
  227.  
  228. CMD:encerrareleicao(playerid, params[])
  229. {
  230.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "(*) Você não é um administrador conectado na RCON.");
  231.     if(isEleicaoStarted == 0) return SendClientMessage(playerid, -1, "(*) Não há nenhuma eleição ocorrendo.");
  232.     SendClientMessageToAll(-1, "As eleições foram ecerradas pelo administrador.");
  233.     isEleicaoStarted = 0;
  234.     new CVotes;
  235.     new CID;
  236.     for(new var=0;var<MAX_CANDID;var++)
  237.     {
  238.         new VoteToGet[32];
  239.         format(VoteToGet, sizeof(VoteToGet), "CandidatoVote%i", var);
  240.         new MyVote;
  241.         MyVote = DOF2_GetInt("ESettings/Settings.ini", VoteToGet);
  242.         if(MyVote > CVotes)
  243.         {
  244.             CVotes = MyVote;
  245.             CID = var;
  246.         }
  247.     }
  248.     new NameToGet[32], STR[64];
  249.     format(NameToGet, sizeof(NameToGet), "Candidato%i", CID);
  250.     strmid(STR, DOF2_GetString("ESettings/Settings.ini", NameToGet), 0, strlen(DOF2_GetString("ESettings/Settings.ini", NameToGet)), 255);
  251.     new MySTR[128];
  252.     format(MySTR, sizeof(MySTR), "O Vencedor da eleição foi: %s com %i votos.", STR, CVotes);
  253.     SendClientMessageToAll(-1, MySTR);
  254.     DOF2_RemoveFile("ESettings/Settings.ini");
  255.     if(!DOF2_FileExists("ESettings/LogEleicao.ini")) DOF2_CreateFile("ESettings/LogEleicao.ini");
  256.     // ...
  257.     new pYear, pMonth, pDay, pHour, pMinute, pSecond, pDate[128];
  258.     getdate(pYear, pMonth, pDay),gettime(pHour, pMinute, pSecond);
  259.     format(pDate, sizeof pDate, "%s venceu a eleição no dia %02d:%02d:%02d às %02d/%02d/%02d.", STR, pHour, pMinute, pSecond , pDay, pMonth, pYear);
  260.     DOF2_SetString("ESettings/LogEleicao.ini", STR, pDate);
  261.     return 1;
  262. }
  263.  
  264. CMD:candidatos(playerid, params[])
  265. {
  266.     if(isEleicaoStarted == 0) return SendClientMessage(playerid, -1, "(*) Não há nenhuma eleição ocorrendo.");
  267.     new FileToRead[] = "ESettings/Settings.ini";
  268.     new StrToShow[256];
  269.     for(new var=0;var<MAX_CANDID;var++)
  270.     {
  271.         new
  272.             KeyToRead[32],
  273.             StrToWrite[32];
  274.         format(KeyToRead, sizeof(KeyToRead), "Candidato%i", var);
  275.         strmid(StrToWrite, DOF2_GetString(FileToRead, KeyToRead), 0, strlen(DOF2_GetString(FileToRead, KeyToRead)), 255);
  276.         if(!strcmp(StrToWrite, " ", true)){strins(StrToShow, "Nenhum - 0 Votos\n", strlen(StrToShow));}
  277.         else
  278.         {
  279.             new StrToConvert[64], StrToGet[32], VoteToGet[32];
  280.             format(VoteToGet, sizeof(VoteToGet), "CandidatoVote%i", var);
  281.             new MyVote;
  282.             MyVote = DOF2_GetInt(FileToRead, VoteToGet);
  283.             strmid(StrToGet, DOF2_GetString(FileToRead, KeyToRead), 0, strlen(DOF2_GetString(FileToRead, KeyToRead)), 255);
  284.             format(StrToConvert, sizeof(StrToConvert), "%s - %i Votos\n", StrToGet, MyVote);
  285.             strins(StrToShow, StrToConvert, strlen(StrToShow));
  286.         }
  287.     }
  288.     ShowPlayerDialog (playerid, DIALOG_MSG, DIALOG_STYLE_MSGBOX, "Candidatos", StrToShow, "Fechar", "");
  289.     return 1;
  290. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement