Auto Select a free number from 1 - 30
#1

Lottery number between 1 - 30
What i want to do it that it selects any number that is free for the player
here
PlayerInfo[i][pLottoNumber] this stores players lotto number

I can't really make the logic for it tired of thinking how it will work.
pawn Код:
for(new b=1; b < 30; b++)
                {
                    number = b;
                    for(new i=0,j=GetPlayerPoolSize(); i <= j; i++)
                    {
                        if(IsPlayerConnected(i))
                        {
                            if(PlayerInfo[i][pLottoNumber] == number)
                            {
                                numbertaken=true;
                                continue;
                            }
                            else
                            {
                                numbertaken=false;
                                break;
                            }
                        }
                    }
                    if(!numbertaken) break;
                }
                if(numbertaken)
                {
                    SendClientMessage(playerid,COLOR_ERROR,"Sorry All Lottery Numbers Haven Been Booked Already.");
                }
                else
                {
                    PlayerInfo[playerid][pLottoNumber] = number;
                    format(string,sizeof(string),"You Have Successfully Taken Number "YELLOW"%d"WHITE", For Daily "GREEN"Lottery"WHITE" Draw At "YELLOW"18:00",number);
                    SendClientMessage(playerid,COLOR_WHITE,string);
                    GivePlayerCash(playerid,-500);
                }
Reply
#2

Hey, here you go and please +1rep
PHP код:
{
    new 
rand random(10) + 1// As i said above
    
new number// a new variable Named "number" to store the data of the input the player typed.
    
    
if(sscanf(params,"i"number)) // sscanf.
    
{
         
SendClientMessage(playerid0xFF0000AA"/lotto [1-10]"); // if the player typed a Not-Numeric Number, it shows this msg (even if he didnt type a thing)
    
}
    else 
// if he didnt make a mistake in typing the code, it passes the code.
    

        if ( 
number 10 || number 1)  // if he typed /lotto 11 or /lotto 0 or /lotto 1243
        
{
            
SendClientMessage(playerid0xFF0000AA"choose a number From 1-10"); // the error message.
        
}
        else 
// If his number is between 1 and 10, it passes the code.
        
{
            if (
number == rand)  // If he won, if the randomly generated number is   same as the number he typed.                        
            
{
                
SendClientMessage(playerid0x33AA33AA"You won it!!");// Winner message.
                
GivePlayerMoney(playerid1000000); // Cash  (i am rich, i will give 1m :P)
                
SetPlayerScore(playeridGetPlayerScore(playerid) + 1); // score for winning.
            
}
            else
            {
                if( 
number != rand// If his number is not same as the number which is randomly generated.
                
{
                    
SendClientMessage(playerid0xFF0000AA"You Lost"); // Loser message.
                
}
            }
        }
    }
    return 
1;

Reply
#3

No that's not what i am trying to do i have a lottery system with a draw at certain time we need to buy tickets for it. There are 3 options to buy tickets 1 select number our own self, 2 get a random number and 3 get a number that is free starting from 1 - 30 in sequence.
So the part i can't figure out is 3rd one i tried that code i posted up
Reply
#4

Quote:
Originally Posted by AroseKhanNiazi
Посмотреть сообщение
Lottery number between 1 - 30
What i want to do it that it selects any number that is free for the player
here
PlayerInfo[i][pLottoNumber] this stores players lotto number

I can't really make the logic for it tired of thinking how it will work.
pawn Код:
for(new b=1; b < 30; b++)
                {
                    number = b;
                    for(new i=0,j=GetPlayerPoolSize(); i <= j; i++)
                    {
                        if(IsPlayerConnected(i))
                        {
                            if(PlayerInfo[i][pLottoNumber] == number)
                            {
                                numbertaken=true;
                                continue;
                            }
                            else
                            {
                                numbertaken=false;
                                break;
                            }
                        }
                    }
                    if(!numbertaken) break;
                }
                if(numbertaken)
                {
                    SendClientMessage(playerid,COLOR_ERROR,"Sorry All Lottery Numbers Haven Been Booked Already.");
                }
                else
                {
                    PlayerInfo[playerid][pLottoNumber] = number;
                    format(string,sizeof(string),"You Have Successfully Taken Number "YELLOW"%d"WHITE", For Daily "GREEN"Lottery"WHITE" Draw At "YELLOW"18:00",number);
                    SendClientMessage(playerid,COLOR_WHITE,string);
                    GivePlayerCash(playerid,-500);
                }
Quote:
Originally Posted by AroseKhanNiazi
Посмотреть сообщение
No that's not what i am trying to do i have a lottery system with a draw at certain time we need to buy tickets for it. There are 3 options to buy tickets 1 select number our own self, 2 get a random number and 3 get a number that is free starting from 1 - 30 in sequence.
So the part i can't figure out is 3rd one i tried that code i posted up
Oh well,
I have one!

PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
 if (
strcmp("/lotto"cmdtexttrue) == 0)
    {
   new 
tmp[256];
    new   
Ergebniss;
    
GivePlayerMoney(playerid, -2000);
    
Jackpot Jackpot 2000;
      
tmp strtok(cmdtextidx);
   if(!
strlen(tmp))
      {
         
SendClientMessage(playeridCOLOR_WHITE"Benutzung: /lotto [Choose a number 1-99]");
         return 
1;
      }
    if (
GetPlayerMoney(playerid)>=&& GetPlayerMoney(playerid)<=100000)
      {
         
Ergebniss 9;
         
Lottozahl Lottozahl Ergebniss;
         if(
Lottozahl >=100)
            {
               
Lottozahl Ergebniss;
            }
      }
    if (
GetPlayerMoney(playerid)>=100000 && GetPlayerMoney(playerid)<=1000000)
      {
         
Ergebniss 8;
         
Lottozahl Lottozahl Ergebniss;
         if(
Lottozahl >=100)
            {
               
Lottozahl Ergebniss;
            }
      }
    if (
GetPlayerMoney(playerid)>=1000000 && GetPlayerMoney(playerid)<=999999999)
      {
         
Ergebniss 7;
         
Lottozahl Lottozahl Ergebniss;
         if(
Lottozahl >=100)
            {
               
Lottozahl Ergebniss;
            }
      }
   if(
strval(tmp) == Lottozahl)
      {
      
GivePlayerMoney(playeridJackpot);
      }
   return 
1;
   }
return 
0;

PS: Here is also a tutorial https://sampforum.blast.hk/showthread.php?tid=160025
Reply
#5

No this also won't select a number that is free from 1 - 30.
In other words this script won't check weather number 1 is taken or not if yes will move to 2 if even then taken then too 3 ...... BTW wait i think i got how it will work i will try it tomorrow and if it does not work i will be posting a new post in this thread.
Reply
#6

This is my attempt at your code..
I think this should work.

You should also check if the player has 500 cash or people would abuse your lotto game

pawn Код:
for(new b=1; b < 30; b++)
{
number = b;
for(new i=0,j=GetPlayerPoolSize() ; i <= j ; i++)
 {
  if(IsPlayerConnected(i) == 1)
  {
   if(PlayerInfo[i][pLottoNumber] == number)
   {
    numbertaken = 0; //true = 0
    break;
   }
    else
   {
    numbertaken = 1; //false = 1
    break;
   }
 }
} //for loop end

if(numbertaken == 0)
{
SendClientMessage(playerid,COLOR_ERROR,"Sorry All Lottery Numbers Haven Been Booked Already.");
}
else
{
PlayerInfo[playerid][pLottoNumber] = number;
format(string,sizeof(string),"You Have Successfully Taken Number "YELLOW"%d"WHITE", For Daily "GREEN"Lottery"WHITE" Draw At "YELLOW"18:00",number);
SendClientMessage(playerid,COLOR_WHITE,string);
GivePlayerCash(playerid,-500);
}
Oh and ignore the guy who posted after me, he just copies stuff
Reply
#7

Try this,

should work!


Код HTML:
                     for(new b=1; b < 30; b++)
				{
					number = b;
					for(new i=0,j=GetPlayerPoolSize() ; i <= j ; i++)
					{
						if(IsPlayerConnected(i) == 1)
						{
							if(PlayerInfo[i][pLottoNumber] == number)
							{
								numbertaken = 0; //true = 0
								break;
							}
							else
							{
								numbertaken = 1; //false = 1
								break;
							}
						}
					}
				} 

				if(numbertaken == 0)
				{
					SendClientMessage(playerid,COLOR_ERROR,"Sorry All Lottery Numbers Haven Been Booked Already.");
				}
				else
				{
					PlayerInfo[playerid][pLottoNumber] = number;
					format(string,sizeof(string),"You Have Successfully Taken Number "YELLOW"%d"WHITE", For Daily "GREEN"Lottery"WHITE" Draw At "YELLOW"18:00",number);
					SendClientMessage(playerid,COLOR_WHITE,string);
					GivePlayerCash(playerid,-500);
				}
Reply
#8

well no these codes will only work when 1 player is online because this code will check 1 player only for that number if he has or not the loop will end with break.
Reply
#9

pawn Код:
new temp_numbers[30] = {1,2,3, ...},numbersout;
for(new i=0, j=GetPlayerPoolSize(); i <= j; i++)
    if(IsPlayerConnected(i) && 0 < PlayerInfo[i][pLottoNumber] < sizeof(numbers)+1)
    {
        temp_numbers[ PlayerInfo[i][pLottoNumber] - 1] = 0;
        numbersout++;
    }

if(numbersout >= sizeof(numbers)) SendClientMessage(playerid,COLOR_ERROR,"Sorry All Lottery Numbers Haven Been Booked Already.");
else{
    new num[30];
    numbersout = 0;
    for(new i=0; i < sizeof(temp_numbers); i++)
        if(temp_numbers[i])
            num[numbersout++] = temp_numbers[i];

    if(numbersout == 1) number = num[0];
    else number = num[random(numbersout)];

    PlayerInfo[playerid][pLottoNumber] = number;
    format(string,sizeof(string),"You Have Successfully Taken Number "YELLOW"%d"WHITE", For Daily "GREEN"Lottery"WHITE" Draw At "YELLOW"18:00",number);
    SendClientMessage(playerid,COLOR_WHITE,string);
    GivePlayerCash(playerid,-500);
}
Reply
#10

Quote:
Originally Posted by AroseKhanNiazi
Посмотреть сообщение
well no these codes will only work when 1 player is online because this code will check 1 player only for that number if he has or not the loop will end with break.
Just add continue instead of break after numbertaken = 0;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)