Posts: 116
Threads: 28
Joined: Feb 2015
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(playerid, 0xFF0000AA, "/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(playerid, 0xFF0000AA, "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(playerid, 0x33AA33AA, "You won it!!");// Winner message.
GivePlayerMoney(playerid, 1000000); // Cash (i am rich, i will give 1m :P)
SetPlayerScore(playerid, GetPlayerScore(playerid) + 1); // score for winning.
}
else
{
if( number != rand) // If his number is not same as the number which is randomly generated.
{
SendClientMessage(playerid, 0xFF0000AA, "You Lost"); // Loser message.
}
}
}
}
return 1;
}
Posts: 1,349
Threads: 194
Joined: Jan 2014
Reputation:
0
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
Posts: 116
Threads: 28
Joined: Feb 2015
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(playerid, cmdtext[])
{
if (strcmp("/lotto", cmdtext, true) == 0)
{
new tmp[256];
new Ergebniss;
GivePlayerMoney(playerid, -2000);
Jackpot = Jackpot + 2000;
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "Benutzung: /lotto [Choose a number 1-99]");
return 1;
}
if (GetPlayerMoney(playerid)>=0 && GetPlayerMoney(playerid)<=100000)
{
Ergebniss = 9;
Lottozahl = Lottozahl + Ergebniss;
if(Lottozahl >=100)
{
Lottozahl = 0 + Ergebniss;
}
}
if (GetPlayerMoney(playerid)>=100000 && GetPlayerMoney(playerid)<=1000000)
{
Ergebniss = 8;
Lottozahl = Lottozahl + Ergebniss;
if(Lottozahl >=100)
{
Lottozahl = 0 + Ergebniss;
}
}
if (GetPlayerMoney(playerid)>=1000000 && GetPlayerMoney(playerid)<=999999999)
{
Ergebniss = 7;
Lottozahl = Lottozahl + Ergebniss;
if(Lottozahl >=100)
{
Lottozahl = 0 + Ergebniss;
}
}
if(strval(tmp) == Lottozahl)
{
GivePlayerMoney(playerid, Jackpot);
}
return 1;
}
return 0;
}
PS: Here is also a tutorial
https://sampforum.blast.hk/showthread.php?tid=160025
Posts: 1,349
Threads: 194
Joined: Jan 2014
Reputation:
0
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.
Posts: 116
Threads: 28
Joined: Feb 2015
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);
}
Posts: 1,349
Threads: 194
Joined: Jan 2014
Reputation:
0
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.
Posts: 2,593
Threads: 34
Joined: Dec 2007
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);
}