[SOLVED] Random - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [SOLVED] Random (
/showthread.php?tid=122876)
[SOLVED] Random -
Rzzr - 23.01.2010
I'm trying to put a player in a random team OnPlayerConnect.
So I have this:
pawn Код:
// On top of script
new gTeam[MAX_PLAYERS];
new Float: TEAMS[2] = {
{0},
{1}
};
pawn Код:
public OnPlayerConnect(playerid)
{
new rand = random(sizeof(TEAMS));
gTeam[playerid] = rand;
new stringy[10];
format(stringy, sizeof(stringy), "Team: %d", stringy, rand);
GameTextForPlayer(playerid, stringy, 5000, 3);
return 1;
}
But this gives me the warning not used TEAMS: and it always gives me team 0
How can I fix this?
Thanks!
Re: [NOT SOLVED] Random -
Rzzr - 24.01.2010
Doesnt anybody know this?
Re: [NOT SOLVED] Random -
*ToM* - 24.01.2010
pawn Код:
#define TEAM 0
#define TEAM 1
?
Re: [NOT SOLVED] Random -
Rzzr - 24.01.2010
Woops i typed that wrong
Should be not used teams (facepalm)
Re: [NOT SOLVED] Random -
MadeMan - 24.01.2010
pawn Код:
format(stringy, sizeof(stringy), "Team: %d", stringy, rand);
Change it to
pawn Код:
format(stringy, sizeof(stringy), "Team: %d", rand);
and then try again
Re: [NOT SOLVED] Random -
mansonh - 24.01.2010
random returns a float, in your case between 0 an 1.
However you are turning it into an int which means you will always get 0.
So you need to do
new rand = floatround(random(sizeof(TEAMS)), floatround_floor);
You use floatround_floor because sizeof(teams) will be 2, and you want 0 or 1.
Re: [NOT SOLVED] Random -
MadeMan - 24.01.2010
Quote:
Originally Posted by mansonh
random returns a float, in your case between 0 an 1.
However you are turning it into an int which means you will always get 0.
So you need to do
new rand = floatround(random(sizeof(TEAMS)), floatround_floor);
You use floatround_floor because sizeof(teams) will be 2, and you want 0 or 1.
|
sizeof isn't a float.
Re: [NOT SOLVED] Random -
mansonh - 24.01.2010
you are correct. But random returns a float.
Re: [NOT SOLVED] Random -
dice7 - 24.01.2010
Quote:
Originally Posted by mansonh
you are correct. But random returns a float.
|
no it doesn't
Re: [NOT SOLVED] Random -
Rzzr - 24.01.2010
Sooo... Which of you is right? :P