Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include < a_samp >
- #include < streamer >
- #include < sscanf2 >
- #include < zcmd >
- #include < dof2 >
- #define DIALOG_LOTERIA (5000)
- #define DIALOG_APOSTAR_LOTERIA (5001)
- #define tempoLoteria (30) //Colocar de quantos em quantos minutos deve ser realizado o sorteio
- #define valorAposta 300 //Colocar o valor do bilhete
- #define numMinAposta 1 //Colocar o numero minimo da aposta
- #define numMaxAposta 100 //Colocar o valor maximo da aposta
- #define valorMinRandom 10000 //Colocar o valor minimo do random
- #define valorMaxRandom 40000 //Colocar o valor maximo do random
- new
- checkpointLoteria,
- numPlayer[MAX_PLAYERS],
- bool:numValido[MAX_PLAYERS],
- bool:apostouLoteria[MAX_PLAYERS],
- ganhouLoteria,
- timerLoteria,
- valorAcumulado;
- public OnFilterScriptInit()
- {
- /* Algumas observações:
- ** Players que forem sorteados e não estiverem on-line, não ganharão o prêmio.
- ** Versão: 0.1
- */
- print(" ");
- print("================================");
- print(" LOTERIA carregado com sucesso. ");
- print("--------------------------------");
- print(" Desenvolvido por nzt ");
- print("--------------------------------");
- print(" Versão 0.1 ");
- print("--------------------------------");
- print(" NÃO RETIRE OS CRÉDITOS! ");
- print("================================");
- print(" ");
- randomLoteria();
- ganhouLoteria = -1;
- //Pickups
- CreatePickup(1318, 1, 1631.8185, -1172.1533, 24.0781); //Pickup para entrar
- CreatePickup(1318, 1, 834.2768, 7.4214, 1004.1870); //Pickup para sair
- //Checkpoint
- checkpointLoteria = CreateDynamicCP(822.5777, 4.0582, 1004.1797, 1, -1, 3, -1); //Checkpoint para abrir dialog
- //Timer
- timerLoteria = SetTimer("sortearLoteria", tempoLoteria * 60000, true); //Timer para chamar a public sortearLoteria
- }
- public OnFilterScriptExit()
- {
- for(new i; i < MAX_PLAYERS; i++)
- {
- numPlayer[i] = 0;
- apostouLoteria[i] = false;
- }
- KillTimer(timerLoteria);
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- numPlayer[playerid] = 0;
- apostouLoteria[playerid] = false;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(newkeys == KEY_SECONDARY_ATTACK)
- {
- if(IsPlayerInRangeOfPoint(playerid, 2.0, 1631.8185, -1172.1533, 24.0781))
- {
- SetPlayerPos(playerid, 834.2768, 7.4214, 1004.1870);
- SetPlayerInterior(playerid, 3);
- }
- if(IsPlayerInRangeOfPoint(playerid, 2.0, 834.2768, 7.4214, 1004.1870))
- {
- SetPlayerPos(playerid, 1631.8185, -1172.1533, 24.0781);
- SetPlayerInterior(playerid, 0);
- }
- }
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case DIALOG_LOTERIA:
- {
- new str[256];
- if(response)
- {
- if(listitem == 0)
- {
- format(str, sizeof str, "{52EBD7}Loteria: {FFFFFF}$%d acumulado.", valorAcumulado);
- SendClientMessage(playerid, -1, str);
- }
- if(listitem == 1)
- {
- ShowPlayerDialog(playerid, DIALOG_APOSTAR_LOTERIA, DIALOG_STYLE_INPUT, "{52EBD7}Loteria", "Informe um número entre "#numMinAposta" e "#numMaxAposta".", "Confirmar", "Cancelar");
- }
- }
- }
- case DIALOG_APOSTAR_LOTERIA:
- {
- new str[256];
- if(response)
- {
- if(apostouLoteria[playerid] == true)
- return SendClientMessage(playerid, -1, "{FE0000}<!>: {FFFFFF}Você já apostou!");
- numPlayer[playerid] = strval(inputtext);
- if(numPlayer[playerid] < numMinAposta || numPlayer[playerid] > numMaxAposta)
- return SendClientMessage(playerid, -1, "{FE0000}<!>: {FFFFFF}Informe um número entre "#numMinAposta" e "#numMaxAposta".");
- if(GetPlayerMoney(playerid) < valorAposta)
- return SendClientMessage(playerid, -1, "{FE0000}<!>: {FFFFFF}Você precisa ter $"#valorAposta" para apostar.");
- for(new i; i < MAX_PLAYERS; i++)
- {
- if(numPlayer[playerid] == numPlayer[i])
- numValido[playerid] = false;
- else
- numValido[playerid] = true;
- }
- if(numValido[playerid] == true)
- {
- format(str, sizeof str, "{52EBD7}Loteria: {FFFFFF}Você apostou com sucesso no número %d.", numPlayer[playerid]);
- SendClientMessage(playerid, -1, str);
- apostouLoteria[playerid] = true;
- GivePlayerMoney(playerid, -valorAposta);
- }
- else
- {
- SendClientMessage(playerid, -1, "{FE0000}<!>: {FFFFFF}O número informado já foi apostado.");
- }
- }
- }
- }
- return 1;
- }
- public OnPlayerEnterDynamicCP(playerid, checkpointid)
- {
- if(checkpointid == checkpointLoteria)
- ShowPlayerDialog(playerid, DIALOG_LOTERIA, DIALOG_STYLE_LIST, "{52EBD7}Loteria", "Acumulado\nApostar", "Confirmar", "Cancelar");
- return 1;
- }
- randomLoteria()
- {
- new rand = random(valorMaxRandom);
- while(rand < valorMinRandom) {
- rand = random(valorMaxRandom);
- }
- valorAcumulado = rand;
- return valorAcumulado;
- }
- forward sortearLoteria();
- public sortearLoteria()
- {
- new numSorteado = random(numMaxAposta), str[256];
- for(new i; i < MAX_PLAYERS; i++)
- {
- if(apostouLoteria[i] == true)
- {
- if(numPlayer[i] == numSorteado)
- ganhouLoteria = i;
- }
- apostouLoteria[i] = false;
- numPlayer[i] = 0;
- }
- if(ganhouLoteria >= 0) //Caso tenha um ganhador
- {
- format(str, sizeof str, "{52EBD7}Loteria: {FFFFFF}O player %s (%d) ganhou $%d na loteria. (Número sorteado: %d)", pegarNome(ganhouLoteria), ganhouLoteria, valorAcumulado, numSorteado);
- SendClientMessageToAll(-1, str);
- GameTextForPlayer(ganhouLoteria, "~w~PARABENS!~n~~g~VOCE GANHOU NA LOTERIA!", 5000, 0);
- GivePlayerMoney(ganhouLoteria, valorAcumulado);
- valorAcumulado = randomLoteria();
- ganhouLoteria = -1;
- }
- else //Caso não tenha um ganhador
- {
- format(str, sizeof str, "{52EBD7}Loteria: {FFFFFF}Não houve ganhadores no sorteio da loteria. (Número sorteado: %d)", numSorteado);
- SendClientMessageToAll(-1, str);
- valorAcumulado += randomLoteria();
- }
- //Anotar no log do server
- new d, m, a, h, mi, seg;
- getdate(a, m, d);
- gettime(h, mi, seg);
- 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);
- }
- pegarNome(targetid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(targetid, name, sizeof name);
- return name;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement