10.05.2015, 04:04
You need to do the random after everytime you created the item, or else it will spawn in same positions with same amount.
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.
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.
Код:
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. */ }
Код:
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. */ }