pawn Код:
CMD:lotto(playerid, params[])
{
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;
}
This code works, but u can make a better one. It is just an example code, try to be differ