RANDOM NUMBER! *REP+* -
_GHT_MarK445 - 19.03.2016
Hey guys, i need a little help.
I maybe have an idea, how to do it, but not sure, how in terms of scripting. What i need, is for example ten-digit number, which will consist of random numbers. And than these random generated numbers will assign to playerid and if he writes them wrong to the dialog, it will do action, the same as if he writes them right. If one of you guys would be enable to chart me an example of this or explain, what exactly i need to do, i would give him rep+.
Re: RANDOM NUMBER! *REP+* -
zPain - 19.03.2016
This might help you:
PHP код:
stock GenerateNumber(digits)
{
if(digits <= 0) return -1;
new number = 0;
while(digits > 1) {
digits -= 1;
number += (random(9) + 1) * floatround(floatpower(10, digits));
}
number += random(10);
return number;
}
10-digit numbers may be a problem because of
cellmax. There are workarounds though.
Re: RANDOM NUMBER! *REP+* -
SickAttack - 19.03.2016
pawn Код:
stock RandomBetween(minimum_value, maximum_value)
{
return (random(maximum_value - minimum_value) + minimum_value);
}
printf("%d", RandomBetween(1000000000, 9999999999));
Re: RANDOM NUMBER! *REP+* -
_GHT_MarK445 - 19.03.2016
Nice! Thanks guys for help, but for me as newbie, could you guys please explain it a little bit more?
Note: I am not asking for copy/paste code, just for a little more explanation.
Re: RANDOM NUMBER! *REP+* -
introzen - 19.03.2016
Use on of the functions given above and wherever you need a random number in your code, put RandomBetween/GenerateNumber along with params.
If you need a number between 0-10, just put
pawn Код:
new rNumber = RandomBetween(0,10);
Re: RANDOM NUMBER! *REP+* -
SickAttack - 19.03.2016
It's simple to understand with a little common sense.
pawn Код:
(random(maximum_value - minimum_value) + minimum_value)
random - Selects a random number, starting from 0. e.g. random(3), this would select a random number equal or between 0 and 2.
maximum_value - The returned value won't go over this value.
minimum_value - The returned value won't go below this value.
e.g.
RandomBetween(10, 20)
It would return a number equal or between 10 and 20.
minimum_value = 10 - maximum_value = 20
Now (random(maximum_value - minimum_value) + minimum_value) would do the following while respecting the parentheses:
(maximum_value - minimum_value)
20 - 10 = 10
random(10) - e.g. 5
5 + minimum_value
5 + 10 ->
15
Re: RANDOM NUMBER! *REP+* -
_GHT_MarK445 - 22.03.2016
I know it may sound like a troll or something, but i still dont really understand what i need to do, how i need to do it and where to put it.
Can someone be really that kind and actually maybe chart me some example with explanation, so i can really learn from it and make it myself please? I would really appreciate it and REP+ him, couse that is what i need.
Then again i am not asking for whole code, but this guys what you gave me, i just dont understand it, cant explain it more.
Re: RANDOM NUMBER! *REP+* -
SyS - 22.03.2016
Hey if want to find random of ranges it is like this
random(upper lmit - lower limit+1)+lower limit
Re: RANDOM NUMBER! *REP+* -
_GHT_MarK445 - 22.03.2016
Yes, but than for example how can i work with it? For example add it into some variable and than check, whether player got it right or bad?
Re: RANDOM NUMBER! *REP+* -
SyS - 22.03.2016
let x be the variable and you want the players to type a ten digit number between 10 and 20
so assign x=random(20-10+1)+10;
or x=random(11)+10;
Now check this with inputext of of your dialog under ondialogresponse
like
Quote:
if(inputext == x)
{
//sendmessage correct
}
else
{
//send wrong message
}
|