SA-MP Forums Archive
Generating a Random Number, | Rep++ - 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: Generating a Random Number, | Rep++ (/showthread.php?tid=476322)



Generating a Random Number, | Rep++ - Mr.Faqahat - 17.11.2013

Hello.
I'm don't know much about random Function
Well.
I want to make something like when player request class It shows him different teams every time he requests,
Like i joined the server it shows me Team A First next time i join it shows me Team C First.
I heard about A "random" Is it possible to make Something like this if we Define A Number as a Team ID ?


Re: Generating a Random Number, | Rep++ - 420Scripter - 17.11.2013

pawn Код:
stock randomEx(min, max)
{    
    //Credits to ******    
    new rand = random(max-min)+min;    
    return rand;
}
You can use that for random numbers, but I'm not sure how to define teams as a number.


Re: Generating a Random Number, | Rep++ - Mr.Faqahat - 17.11.2013

Thats the problem i am having ....


Re: Generating a Random Number, | Rep++ - dominik523 - 17.11.2013

well define one variable for a team, for example:
Код:
new pTeam[MAX_PLAYERS];
// for example you have 4 teams
and you can do something like this under onPlayerRequestClass
Код:
new team;
team = Random(4);
pTeam[playerid] = team;



Re: Generating a Random Number, | Rep++ - Mr.Faqahat - 18.11.2013

Quote:
Originally Posted by dominik523
Посмотреть сообщение
well define one variable for a team, for example:
Код:
new pTeam[MAX_PLAYERS];
// for example you have 4 teams
and you can do something like this under onPlayerRequestClass
Код:
new team;
team = Random(4);
pTeam[playerid] = team;
Thank You.
But
team = Random(4);
Error on this line
error 010: invalid function or declaration


Re: Generating a Random Number, | Rep++ - DeStunter - 18.11.2013

random() not Random()


Re: Generating a Random Number, | Rep++ - Mr.Faqahat - 18.11.2013

Quote:
Originally Posted by DeStunter
Посмотреть сообщение
random() not Random()
Still having the error.


Re: Generating a Random Number, | Rep++ - Mr.Faqahat - 18.11.2013






Re: Generating a Random Number, | Rep++ - dominik523 - 18.11.2013

I tried to compile this
Код:
new rteam;
rteam = random(11);
and I don't have any errors. Where did you put that text?


Re: Generating a Random Number, | Rep++ - Mr.Faqahat - 18.11.2013

Quote:
Originally Posted by dominik523
Посмотреть сообщение
I tried to compile this
Код:
new rteam;
rteam = random(11);
and I don't have any errors. Where did you put that text?
Well. I put It Under where the Teams are defined. On the Top of the Script