Advertisement
nzt7

Sistema de Loteria | by nzt

Feb 13th, 2019
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.27 KB | None | 0 0
  1. #include < a_samp >
  2. #include < streamer >
  3. #include < sscanf2 >
  4. #include < zcmd >
  5. #include < dof2 >
  6.    
  7. #define DIALOG_LOTERIA          (5000)
  8. #define DIALOG_APOSTAR_LOTERIA  (5001)
  9. #define tempoLoteria            (30) //Colocar de quantos em quantos minutos deve ser realizado o sorteio
  10. #define valorAposta             300 //Colocar o valor do bilhete
  11. #define numMinAposta            1 //Colocar o numero minimo da aposta
  12. #define numMaxAposta            100 //Colocar o valor maximo da aposta
  13. #define valorMinRandom          10000 //Colocar o valor minimo do random
  14. #define valorMaxRandom          40000 //Colocar o valor maximo do random
  15.  
  16. new
  17.     checkpointLoteria,
  18.     numPlayer[MAX_PLAYERS],
  19.     bool:numValido[MAX_PLAYERS],
  20.     bool:apostouLoteria[MAX_PLAYERS],
  21.     ganhouLoteria,
  22.     timerLoteria,
  23.     valorAcumulado;
  24.  
  25. public OnFilterScriptInit()
  26. {
  27.     /* Algumas observações:
  28.         ** Players que forem sorteados e não estiverem on-line, não ganharão o prêmio.
  29.         ** Versão: 0.1
  30.     */
  31.  
  32.     print("                                ");
  33.     print("================================");
  34.     print(" LOTERIA carregado com sucesso. ");
  35.     print("--------------------------------");
  36.     print("     Desenvolvido por nzt       ");
  37.     print("--------------------------------");
  38.     print("          Versão 0.1            ");
  39.     print("--------------------------------");
  40.     print("     NÃO RETIRE OS CRÉDITOS!    ");
  41.     print("================================");
  42.     print("                                ");
  43.  
  44.     randomLoteria();
  45.     ganhouLoteria = -1;
  46.  
  47.     //Pickups
  48.     CreatePickup(1318, 1, 1631.8185, -1172.1533, 24.0781); //Pickup para entrar
  49.     CreatePickup(1318, 1, 834.2768, 7.4214, 1004.1870); //Pickup para sair
  50.  
  51.     //Checkpoint
  52.     checkpointLoteria = CreateDynamicCP(822.5777, 4.0582, 1004.1797, 1, -1, 3, -1); //Checkpoint para abrir dialog
  53.  
  54.     //Timer
  55.     timerLoteria = SetTimer("sortearLoteria", tempoLoteria * 60000, true); //Timer para chamar a public sortearLoteria
  56. }
  57.  
  58. public OnFilterScriptExit()
  59. {
  60.     for(new i; i < MAX_PLAYERS; i++)
  61.     {
  62.         numPlayer[i] = 0;
  63.         apostouLoteria[i] = false;
  64.     }
  65.     KillTimer(timerLoteria);
  66. }
  67.  
  68. public OnPlayerDisconnect(playerid, reason)
  69. {
  70.     numPlayer[playerid] = 0;
  71.     apostouLoteria[playerid] = false;
  72. }
  73.  
  74. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  75. {
  76.     if(newkeys == KEY_SECONDARY_ATTACK)
  77.     {
  78.         if(IsPlayerInRangeOfPoint(playerid, 2.0, 1631.8185, -1172.1533, 24.0781))
  79.         {
  80.             SetPlayerPos(playerid, 834.2768, 7.4214, 1004.1870);
  81.             SetPlayerInterior(playerid, 3);
  82.         }
  83.  
  84.         if(IsPlayerInRangeOfPoint(playerid, 2.0, 834.2768, 7.4214, 1004.1870))
  85.         {
  86.             SetPlayerPos(playerid, 1631.8185, -1172.1533, 24.0781);
  87.             SetPlayerInterior(playerid, 0);
  88.         }
  89.     }
  90. }
  91.  
  92. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  93. {
  94.     switch(dialogid)
  95.     {
  96.         case DIALOG_LOTERIA:
  97.         {
  98.             new str[256];
  99.             if(response)
  100.             {
  101.                 if(listitem == 0)
  102.                 {
  103.                     format(str, sizeof str, "{52EBD7}Loteria: {FFFFFF}$%d acumulado.", valorAcumulado);
  104.                     SendClientMessage(playerid, -1, str);
  105.                 }
  106.                 if(listitem == 1)
  107.                 {
  108.                     ShowPlayerDialog(playerid, DIALOG_APOSTAR_LOTERIA, DIALOG_STYLE_INPUT, "{52EBD7}Loteria", "Informe um número entre "#numMinAposta" e "#numMaxAposta".", "Confirmar", "Cancelar");
  109.                 }
  110.             }
  111.         }
  112.         case DIALOG_APOSTAR_LOTERIA:
  113.         {
  114.             new str[256];
  115.             if(response)
  116.             {
  117.                 if(apostouLoteria[playerid] == true)
  118.                     return SendClientMessage(playerid, -1, "{FE0000}<!>: {FFFFFF}Você já apostou!");
  119.  
  120.                 numPlayer[playerid] = strval(inputtext);
  121.  
  122.                 if(numPlayer[playerid] < numMinAposta || numPlayer[playerid] > numMaxAposta)
  123.                     return SendClientMessage(playerid, -1, "{FE0000}<!>: {FFFFFF}Informe um número entre "#numMinAposta" e "#numMaxAposta".");
  124.                
  125.                 if(GetPlayerMoney(playerid) < valorAposta)
  126.                     return SendClientMessage(playerid, -1, "{FE0000}<!>: {FFFFFF}Você precisa ter $"#valorAposta" para apostar.");
  127.  
  128.                 for(new i; i < MAX_PLAYERS; i++)
  129.                 {
  130.                     if(numPlayer[playerid] == numPlayer[i])
  131.                         numValido[playerid] = false;
  132.                     else
  133.                         numValido[playerid] = true;
  134.                 }
  135.  
  136.                 if(numValido[playerid] == true)
  137.                 {
  138.                     format(str, sizeof str, "{52EBD7}Loteria: {FFFFFF}Você apostou com sucesso no número %d.", numPlayer[playerid]);
  139.                     SendClientMessage(playerid, -1, str);
  140.                     apostouLoteria[playerid] = true;
  141.                     GivePlayerMoney(playerid, -valorAposta);
  142.  
  143.                 }
  144.                 else
  145.                 {
  146.                     SendClientMessage(playerid, -1, "{FE0000}<!>: {FFFFFF}O número informado já foi apostado.");
  147.                 }
  148.             }
  149.         }
  150.     }
  151.     return 1;
  152. }
  153.  
  154. public OnPlayerEnterDynamicCP(playerid, checkpointid)
  155. {
  156.     if(checkpointid == checkpointLoteria)
  157.     ShowPlayerDialog(playerid, DIALOG_LOTERIA, DIALOG_STYLE_LIST, "{52EBD7}Loteria", "Acumulado\nApostar", "Confirmar", "Cancelar");
  158.     return 1;
  159. }
  160.  
  161. randomLoteria()
  162. {
  163.     new rand = random(valorMaxRandom);
  164.     while(rand < valorMinRandom) {
  165.         rand = random(valorMaxRandom);
  166.     }
  167.  
  168.     valorAcumulado = rand;
  169.     return valorAcumulado; 
  170. }
  171.  
  172. forward sortearLoteria();
  173. public sortearLoteria()
  174. {
  175.     new numSorteado = random(numMaxAposta), str[256];
  176.  
  177.     for(new i; i < MAX_PLAYERS; i++)
  178.     {
  179.         if(apostouLoteria[i] == true)
  180.         {
  181.             if(numPlayer[i] == numSorteado)
  182.                 ganhouLoteria = i;
  183.         }
  184.         apostouLoteria[i] = false;
  185.         numPlayer[i] = 0;
  186.     }
  187.  
  188.     if(ganhouLoteria >= 0) //Caso tenha um ganhador
  189.     {
  190.         format(str, sizeof str, "{52EBD7}Loteria: {FFFFFF}O player %s (%d) ganhou $%d na loteria. (Número sorteado: %d)", pegarNome(ganhouLoteria), ganhouLoteria, valorAcumulado, numSorteado);
  191.         SendClientMessageToAll(-1, str);
  192.         GameTextForPlayer(ganhouLoteria, "~w~PARABENS!~n~~g~VOCE GANHOU NA LOTERIA!", 5000, 0);
  193.         GivePlayerMoney(ganhouLoteria, valorAcumulado);
  194.         valorAcumulado = randomLoteria();
  195.         ganhouLoteria = -1;
  196.     }
  197.     else //Caso não tenha um ganhador
  198.     {
  199.         format(str, sizeof str, "{52EBD7}Loteria: {FFFFFF}Não houve ganhadores no sorteio da loteria. (Número sorteado: %d)", numSorteado);
  200.         SendClientMessageToAll(-1, str);
  201.         valorAcumulado += randomLoteria();
  202.     }
  203.  
  204.     //Anotar no log do server
  205.     new d, m, a, h, mi, seg;
  206.     getdate(a, m, d);
  207.     gettime(h, mi, seg);
  208.     printf("Um sorteio foi realizado em %02d/%02d/%02d às %02d:%02d:%02d e o número sorteado foi %d", d, m, a, h, mi, seg, numSorteado);
  209. }
  210.  
  211. pegarNome(targetid)
  212. {
  213.     new name[MAX_PLAYER_NAME];
  214.     GetPlayerName(targetid, name, sizeof name);
  215.     return name;
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement