Items spawn on same coords
#2

You need to do the random after everytime you created the item, or else it will spawn in same positions with same amount.

Код:
forward LootRespawn();
public LootRespawn()
{
	new res = randomEx(1, 2);
	new ItemRes[][4] =
	{
		{1580, 1577, 373, 348}, // items for res == 1
		{2806, 2663, 335, 2358} // items for res == 2
	};
	for(new i = 0; i < sizeof(ItemRes); i++) // This will do loop 4 times
	{
		if((res == 1 && i == 3) || (res == 2 && i == 2)) amount = 1;
		// The 4th (i+1) item (res == 1) which is model 348 should only have 1 amount.
		// OR the 3rd (i+1) item (res == 2) which is model 335 should only have 1 amount too.
		
		else amount = randomEx(1, 10); // Otherwise, randomize the amount.
		Locs = random(sizeof(TestSpawns));
		CreateItem(ItemRes[res][i], amount, 1, TestSpawns[Locs][0], TestSpawns[Locs][1], TestSpawns[Locs][2], 0, 0);
		/* res is already randomized so no need to check if it's equal to one or two since
			the function is mostly doing the same for both res, which is just differences with the items
			that we have to separate it in ItemRes array now. */
	}
If you don't really mean the amount get randomized or you want the amount for each "res" is same, then just put the if-else check for amount to outside the loop.
Код:
forward LootRespawn();
public LootRespawn()
{
	new res = randomEx(1, 2);
	new ItemRes[][4] =
	{
		{1580, 1577, 373, 348}, // items for res == 1
		{2806, 2663, 335, 2358} // items for res == 2
	};
	// THIS WILL ONLY DO ONCE
	if((res == 1 && i == 3) || (res == 2 && i == 2)) amount = 1;
	// The 4th (i+1) item (res == 1) which is model 348 should only have 1 amount.
	// OR the 3rd (i+1) item (res == 2) which is model 335 should only have 1 amount too.
	
	else amount = randomEx(1, 10); // Otherwise, randomize the amount.
	for(new i = 0; i < sizeof(ItemRes); i++) // This will do loop 4 times
	{
		Locs = random(sizeof(TestSpawns));
		CreateItem(ItemRes[res][i], amount, 1, TestSpawns[Locs][0], TestSpawns[Locs][1], TestSpawns[Locs][2], 0, 0);
		/* res is already randomized so no need to check if it's equal to one or two since
			the function is mostly doing the same for both res, which is just differences with
			the items that we have to separated it in ItemRes array now. */
	}
If it's not working like what you want, then you need to explain more how the items should be spawned with that callback by pointing out what is "res" for.
Reply


Messages In This Thread
Items spawn on same coords - by DTV - 10.05.2015, 02:57
Re: Items spawn on same coords - by RoboN1X - 10.05.2015, 04:04
Re: Items spawn on same coords - by DTV - 10.05.2015, 05:00
Re: Items spawn on same coords - by RoboN1X - 10.05.2015, 07:09
Re: Items spawn on same coords - by DTV - 10.05.2015, 12:22
Re: Items spawn on same coords - by DTV - 10.05.2015, 20:53
Re: Items spawn on same coords - by DTV - 12.05.2015, 02:24
Re: Items spawn on same coords - by Joe Staff - 12.05.2015, 03:19
Re: Items spawn on same coords - by Joe Staff - 12.05.2015, 04:12
Re: Items spawn on same coords - by DTV - 12.05.2015, 06:18

Forum Jump:


Users browsing this thread: 2 Guest(s)