30.01.2015, 16:45
I am trying to select a random box that has not been selected already.
Well, I have an array of spawn positions for objects(a box). I want a random number to be chosen from 3 to 10, this will be the number of boxes that will spawn. then I want to select that many number of boxes from an array randomly but not a box that has already been chosen.
here is what i have so far:
array:
Code to run to select boxes and create them
Well, I have an array of spawn positions for objects(a box). I want a random number to be chosen from 3 to 10, this will be the number of boxes that will spawn. then I want to select that many number of boxes from an array randomly but not a box that has already been chosen.
here is what i have so far:
array:
Код:
new Float:RandomBoxSpawn[][6] =
{
// Positions, (X, Y, Z, rX, rY, rZ)
{2783.76,-2450.73,14.596,0,0,0},
{2783.67,-2449.26,13.797,0,0,0},
{2791.95,-2461.6,13.796,0,0,0},
{2791.87,-2487.78,14.593,0,0,0},
{2797.43,-2487.67,13.793,0,0,0},
{2783.74,-2499.64,14.659,0,0,0},
{2783.75,-2407.97,13.827,0,0,0},
{2791.9,-2426.13,14.633,0,0,0},
{2783.83,-2424.59,13.055,0,0,0},
{2791.93,-2447.75,13.044,0,0,0}
};
Код:
public Createboxes(playerid)
{
new ammountofboxes = randomEx(3,10);
while (i <= ammountofboxes)
{
for(new index=1; index<11; index++)
{
if(!IsValidObject(PlayerInfo[playerid][TempoObject][index]))
{
new randbox = random(sizeof(RandomBoxSpawn));
//HERE IS WHERE I WANT A RANDOM BOX TO BE SELECTED BUT WHERE IT CANNOT BE SELECTED TWICE
i++;
}
}
}
return 1;
}

