[SOLVED] Random
#1

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!
Reply
#2

Doesnt anybody know this?
Reply
#3

pawn Код:
#define TEAM 0
#define TEAM 1
?
Reply
#4

Woops i typed that wrong
Should be not used teams (facepalm)
Reply
#5

pawn Код:
format(stringy, sizeof(stringy), "Team: %d", stringy, rand);
Change it to

pawn Код:
format(stringy, sizeof(stringy), "Team: %d", rand);
and then try again
Reply
#6

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.
Reply
#7

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.
Reply
#8

you are correct. But random returns a float.
Reply
#9

Quote:
Originally Posted by mansonh
you are correct. But random returns a float.
no it doesn't
Reply
#10

Sooo... Which of you is right? :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)