Advertisement
Aninhaah

aLottery by Aninhaah

Sep 2nd, 2012
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.43 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <dof2>
  4.  
  5. #define MAX_BILHETES 4//Máximo de bilhetes permitido por player, aqui vai dar 3 bilhetes (tem que ser o máximo +1)
  6. #define TEMPO_SORTEIO 60//Coloca o tempo em minutos
  7.  
  8. #define MAIOR_NUMERO 100 //Maior numero que vai poder ser sorteado
  9. #define PRECO_BILHETE 2 //Preço do bilhete
  10. #define ARQUIVO_JOGADOR "Contas/%s.ini" // Pasta onde fica salvo os jogadores
  11. #define ArqPremio "LoteriaPremio.ini" // Onde vai ficar o arquivo com o premio, aqui tá na pasta scriptfiles, mas pode ser mudada a pasta
  12.  
  13. #define COR_VERDE 0x7CFC00FF
  14. #define COR_AMARELO 0xFFFF00FF
  15.  
  16. new Bilhetes[MAX_PLAYERS][MAX_BILHETES];
  17. new Premio;
  18.  
  19. forward Sorteio();
  20.  
  21. randomminimo(min, max)
  22. {
  23.     return random(max-min) +min;
  24. }
  25.  
  26.  
  27. public OnFilterScriptInit()
  28. {
  29.     print("\n--------------------------------------");
  30.     print("aLoteric v1.0 by Aninhaah/HumildadeForever");
  31.     print("--------------------------------------\n");
  32.     CarregarPremio();
  33.     SetTimer("Sorteio", TEMPO_SORTEIO*60000, true);
  34.     return 1;
  35. }
  36.  
  37. public OnFilterScriptExit()
  38. {
  39.     DOF2_Exit();
  40.     return 1;
  41. }
  42.  
  43. public OnPlayerConnect(playerid)
  44. {
  45.     CarregarBilhetes(playerid);
  46.     return 1;
  47. }
  48. public OnPlayerDisconnect(playerid, reason)
  49. {
  50.     SalvarBilhetes(playerid);
  51.     return 1;
  52. }
  53.  
  54. CMD:bilhete(playerid, params[])
  55. {
  56.     new bool:contar = false;
  57.     for(new b = 1; b < MAX_BILHETES; b++)
  58.     {
  59.         if(Bilhetes[playerid][b] == strval(params)) return SendClientMessage(playerid, COR_AMARELO, "Você já tem um bilhete com esse número.");
  60.         if(Bilhetes[playerid][b] < 1)
  61.         {
  62.             if(isnull(params) || !strval(params)) return SendClientMessage(playerid, COR_AMARELO, "Use: /Bilhete [Numero (Não vale o 0)]");
  63.             if(GetPlayerMoney(playerid) < PRECO_BILHETE) return SendClientMessage(playerid, COR_AMARELO, "Você não tem dinheiro suficiente.");
  64.             if(strval(params) > MAIOR_NUMERO) return SendClientMessage(playerid, COR_AMARELO, "Bilhete invalido, escolha um numero menor.");
  65.             Bilhetes[playerid][b] = strval(params);
  66.             new string[90];
  67.             format(string, sizeof(string),"Você comprou o bilhete número %d por R$%d.", strval(params), PRECO_BILHETE);
  68.             SendClientMessage(playerid, COR_VERDE, string);
  69.             GivePlayerMoney(playerid, -PRECO_BILHETE);
  70.             Premio += PRECO_BILHETE;
  71.             SalvarPremio();
  72.             SalvarBilhetes(playerid);
  73.             contar = true;
  74.             break;
  75.         }
  76.     }
  77.     if(contar == false) return SendClientMessage(playerid, COR_AMARELO, "Você já comprou o máximo de bilhetes.");
  78.     return 1;
  79. }
  80. CMD:meusbilhetes(playerid)
  81. {
  82.     new bool:contar = false;
  83.     for(new b = 1; b < MAX_BILHETES; b++)
  84.     {
  85.         if(Bilhetes[playerid][b] >= 1)
  86.         {
  87.             new string[120];
  88.             format(string,sizeof(string),"Bilhete %d. Número: %d\n", b, Bilhetes[playerid][b]);
  89.             SendClientMessage(playerid, COR_VERDE, string);
  90.             contar = true;
  91.         }
  92.     }
  93.     if(contar == false) return SendClientMessage(playerid, COR_AMARELO, "Você não tem nenhum bilhete.");
  94.     return 1;
  95. }
  96.        
  97. public Sorteio()
  98. {
  99.     new bilhete = randomminimo(1, MAIOR_NUMERO);
  100.     new string[100], string2[90], bool: contar = false;
  101.     format(string2, sizeof(string2),"O próximo sorteio será daqui %d minutos!", TEMPO_SORTEIO);
  102.     for(new p = 0; p < MAX_PLAYERS; p++)
  103.     {
  104.         for(new b = 1; b < MAX_BILHETES; b++)
  105.         {
  106.             if(Bilhetes[p][b] == bilhete)
  107.             {
  108.                 format(string, sizeof(string),"%s ganhou na loteria R$ %d.", Nome(p), Premio);
  109.                 GivePlayerMoney(p, Premio);
  110.                 Premio = 0;
  111.                 SalvarPremio();
  112.                 contar = true;
  113.             }
  114.             if(contar == false)
  115.             {
  116.                 format(string, sizeof(string),"Ninguém ganhou na loteria! Premio acumulado para R$ %d", Premio);
  117.             }
  118.             Bilhetes[p][b] = 0;
  119.         }
  120.     }
  121.     SendClientMessageToAll(COR_VERDE, string);
  122.     SendClientMessageToAll(COR_VERDE, string2);
  123.     print(string);
  124.     print(string2);
  125.     return 1;
  126. }
  127. Nome(playerid)
  128. {
  129.     new nome[MAX_PLAYER_NAME];
  130.     GetPlayerName(playerid, nome, sizeof(nome));
  131.     return nome;
  132. }
  133.  
  134. SalvarBilhetes(playerid)
  135. {
  136.     new file[56];
  137.     format(file, sizeof(file), ARQUIVO_JOGADOR, Nome(playerid));
  138.     if(DOF2_FileExists(file))
  139.     {
  140.         for(new b = 1; b < MAX_BILHETES; b++)
  141.         {
  142.             new tag[25];
  143.             format(tag, sizeof(tag),"Bilhete %d", b);
  144.             DOF2_SetInt(file,tag, Bilhetes[playerid][b]);
  145.             DOF2_SaveFile();
  146.         }
  147.     }
  148.     return 1;
  149. }
  150. CarregarBilhetes(playerid)
  151. {
  152.     new file[56];
  153.     format(file, sizeof(file), ARQUIVO_JOGADOR, Nome(playerid));
  154.     if(DOF2_FileExists(file))
  155.     {
  156.         for(new b = 1; b < MAX_BILHETES; b++)
  157.         {
  158.             new tag[25];
  159.             format(tag, sizeof(tag),"Bilhete %d", b);
  160.             if(DOF2_IsSet(file, tag))
  161.             {
  162.                 Bilhetes[playerid][b] = DOF2_GetInt(file, tag);
  163.                 SendClientMessage(playerid, COR_VERDE, "Seus bilhetes foram carregados! Use: /MeusBilhetes.");
  164.             }
  165.         }
  166.     }
  167.     return 1;
  168. }
  169. CarregarPremio()
  170. {
  171.     if(DOF2_FileExists(ArqPremio))
  172.     {
  173.         Premio = DOF2_GetInt(ArqPremio,"Premio");
  174.         print("Premio da loteria carregado com sucesso!");
  175.     }
  176.     else if(!DOF2_FileExists(ArqPremio))
  177.     {
  178.         DOF2_CreateFile(ArqPremio);
  179.         DOF2_SetInt(ArqPremio,"Premio", 0);
  180.         DOF2_SaveFile();
  181.         Premio = 0;
  182.     }
  183.     return 1;
  184. }
  185. SalvarPremio()
  186. {
  187.     if(DOF2_FileExists(ArqPremio))
  188.     {
  189.         DOF2_SetInt(ArqPremio,"Premio", Premio);
  190.         DOF2_SaveFile();
  191.         print("Premio da loteria salvo com sucesso!");
  192.     }
  193.     else if(!DOF2_FileExists(ArqPremio))
  194.     {
  195.         DOF2_CreateFile(ArqPremio);
  196.         DOF2_SetInt(ArqPremio,"Premio", 0);
  197.         DOF2_SaveFile();
  198.     }
  199.     return 1;
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement