How to check from arrays?
#1

Forexample i have a Float Array:

Код:
new Float:Array [][4] =
{x,y,z,a},
{x,y,z,a},
{x,y,z,a}
}
Actually i am making a derby system,I want to check if a player is spawned at one of these cords or not.
Reply
#2

I don't get what you actually mean but why not just check it with a variable? When a player joins a derby set a var to true/1 right when you spawn them using one of those coord(s).
Reply
#3

I mean,how will i check if one of these coords are used? I want to avoid 2 players spawning is 1 place
Reply
#4

Using another array with the same size and set accordingly (to true when the spot is taken or to false when not). To me though, the best way would be an iterator from foreach/y_iterate. When a derby match is starting, add all the free slots to the iterator and when a player joins, pick up a random slot and remove it from the iterator afterwards.
Reply
#5

Can i do like this?:

Код:
new Used[5];

OnPlayerSpawn(playerid)
{
new spawn = random(sizeof(Array));
if(Used[spawn] == 0)
{
SetPlayerPos(playerid, Array[spawn][0].....);
for(new i = 0; i < sizeof(Array); i++)
{
Used[i] == 1;
}
}
return 1;
}
Reply
#6

The loop has no meaning, all you have to do is:
pawn Код:
SetPlayerPos(playerid, Array[spawn][0].....);
Used[spawn] = 1;
but again, for random slots and without loops to retrieve a random free slot foreach/y_iterate is the best option.
Reply
#7

Are you actually asking if the spawn is used or if the player is using one of those spawns?
Because if you want to check if the player is using one of those spawns, you need to make a 2d array.
(Used[playerid][spawnid] -- spawnid is the spawns array slot)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)