SA-MP Forums Archive
Giving random questions. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Giving random questions. (/showthread.php?tid=385139)



Giving random questions. - Calabresi - 14.10.2012

Hello there. I have a little problem out there... I have a script that asks ten questions to players in order to play on server. I want these messages to appear randomly but if a message has already been asked before by the system, it shouldn't ask it again.

It's like, I have numbers from 1 to 10 and I randomly pick one, but I don't want my next random selection to be previous random selection. If system selected 1, it shouldn't select 1 again on next question.

Waiting for the help, thanks.


Re: Giving random questions. - Calabresi - 26.10.2012

Bump.


Re: Giving random questions. - Peach - 26.10.2012

You'll have to create a saving variable which logs what player has answered the questions.


Re: Giving random questions. - Calabresi - 26.10.2012

Quote:
Originally Posted by Peach
Посмотреть сообщение
You'll have to create a saving variable which logs what player has answered the questions.
Only thing I need is giving out ten random numbers, from 0 to 9. But these numbers must not be equal to each other and must change for each player.


Re: Giving random questions. - Peach - 26.10.2012

I suggest you use this function with foreach.

PHP код:
stock randomEx(minnum cellminmaxnum cellmax)
{
    return 
random(maxnum minnum 1) + minnum;




Re: Giving random questions. - Calabresi - 26.10.2012

Quote:
Originally Posted by Peach
Посмотреть сообщение
I suggest you use this function with foreach.

PHP код:
stock randomEx(minnum cellminmaxnum cellmax)
{
    return 
random(maxnum minnum 1) + minnum;

I don't think that'll work because it will add or subtract the minnum and then will add it again with one point more, but I just want it to stay between 0-9.


Re: Giving random questions. - Peach - 26.10.2012

The +1 is used for 0.

If you do RandomEx(0,10); then it'll only go up to 0 and 9 because of it counting 0 as a number.


Re: Giving random questions. - Calabresi - 26.10.2012

Quote:
Originally Posted by Peach
Посмотреть сообщение
The +1 is used for 0.

If you do RandomEx(0,10); then it'll only go up to 0 and 9 because of it counting 0 as a number.
I'll try that and write again to here, thanks.