Serious help please
#1

So i am trying to create a lottery system and i am nearly done i just have one problem when it picks a number.

I want it to pick a number that a player already has.

For example.

I buy a ticket.
My friend buys a ticket.
My other friend buys a ticket.

I want it to choose out of our three numbers so there is always a number.

Please help.

This is when you buy a ticket.

pawn Код:
Player[playerid][RaffleTicket] = random(100);
This is when its picking the ticket.

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(canraffle == 0)
        {
            if(gettime() == Player[i][RaffleTime])
            {
                //Player[i][RaffleTime] = gettime() + 345600;
                new lotto = random(Player[i][RaffleTicket]);
                new Winnings = Player[i][JackPot];
                new string[128];
                if(lotto == Player[i][RaffleTicket])
                {
                    format(string, sizeof(string), "Congratulations %s has won the lottery of %d", GetNameNoUnderScore(i), Winnings);
                    SendClientMessageToAll(YELLOW, string);
                    format(string, sizeof(string), "Congratulations you have won the lottery of %d", Winnings);
                    SendClientMessage(i, YELLOW, string);
                    SendClientMessageToAll(YELLOW, "Remember to buy a another raffle ticket if you want to take part in the next lottery");
                    Player[i][RaffleTicket] = 0;
                    Player[i][Money] += Winnings;
                    canraffle = 1;
                }
                else
                {
                    Raffle();
                }
            }
        }
    }
That dont even get to sending the messages.

I think its something to do with

pawn Код:
new lotto = random(Player[i][RaffleTicket]);
How can i fix

Please help

Thanks
Reply
#2

Why does no one ever help me ?

PLEASE HELP ME.

PLEASE.

Thanks.
Reply
#3

try this rapid implementation, i think this can resolve the problem:


Put this in top of your code after includes

Код:
new Control_Tickets[MAX_PLAYERS];
new last_ticket_position = 0;
This is when you buy a ticket.

Код:
Player[playerid][RaffleTicket] = random(100);
Control_Tickets[last_ticket_position]=playerid;
last_ticket_position++;
This is when its picking the ticket.

Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
	if(canraffle == 0)
	{
		if(gettime() == Player[i][RaffleTime])
		{
			//Player[i][RaffleTime] = gettime() + 345600;
			new lotto= Player[Control_Tickets[random(last_ticket_position)]][RaffleTicket];
			new Winnings = Player[i][JackPot];
			new string[128];
			if(lotto == Player[i][RaffleTicket])
			{
				format(string, sizeof(string), "Congratulations %s has won the lottery of %d", GetNameNoUnderScore(i), Winnings);
				SendClientMessageToAll(YELLOW, string);
				format(string, sizeof(string), "Congratulations you have won the lottery of %d", Winnings);
				SendClientMessage(i, YELLOW, string);
				SendClientMessageToAll(YELLOW, "Remember to buy a another raffle ticket if you want to take part in the next lottery");
				Player[i][RaffleTicket] = 0;
				Player[i][Money] += Winnings;
				canraffle = 1;
				for(new i=0; i<last_ticket_position; i++)
				{
					Control_Tickets[i]=0;
				}
				last_ticket_position=0;
			}
			else
			{
				Raffle();
			}
		}
	}
}
Reply
#4

Quote:
Originally Posted by misticini
Посмотреть сообщение
try this rapid implementation, i think this can resolve the problem:


Put this in top of your code after includes

Код:
new Control_Tickets[MAX_PLAYERS];
new last_ticket_position = 0;
This is when you buy a ticket.

Код:
Player[playerid][RaffleTicket] = random(100);
Control_Tickets[last_ticket_position]=playerid;
last_ticket_position++;
This is when its picking the ticket.

Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
	if(canraffle == 0)
	{
		if(gettime() == Player[i][RaffleTime])
		{
			//Player[i][RaffleTime] = gettime() + 345600;
			new lotto= Player[Control_Tickets[random(last_ticket_position)]][RaffleTicket];
			new Winnings = Player[i][JackPot];
			new string[128];
			if(lotto == Player[i][RaffleTicket])
			{
				format(string, sizeof(string), "Congratulations %s has won the lottery of %d", GetNameNoUnderScore(i), Winnings);
				SendClientMessageToAll(YELLOW, string);
				format(string, sizeof(string), "Congratulations you have won the lottery of %d", Winnings);
				SendClientMessage(i, YELLOW, string);
				SendClientMessageToAll(YELLOW, "Remember to buy a another raffle ticket if you want to take part in the next lottery");
				Player[i][RaffleTicket] = 0;
				Player[i][Money] += Winnings;
				canraffle = 1;
				for(new i=0; i<last_ticket_position; i++)
				{
					Control_Tickets[i]=0;
				}
				last_ticket_position=0;
			}
			else
			{
				Raffle();
			}
		}
	}
}
That just made my compiler stop working.

PLEASE HELP I HAVE BEEN TRYING TO DO THIS FOR DAYS

Thanks.
Reply
#5

maybe do this

new aux = random(last_ticket_position);
new aux2 = Control_Tickets[aux];
new lotto= Player[aux2][RaffleTicket];
Reply
#6

https://sampforum.blast.hk/showthread.php?tid=361688
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)