30.06.2015, 09:30
(
Последний раз редактировалось Hessu; 02.07.2015 в 13:28.
Причина: Updated the data of help
)
One simple question: How do i prevent random function to pick up the same value several times?
This is importat, cuz im doing random trucking missions, and i want to show the players a dialog of 4 do-able missions, and i do not want 2 or more same loads in the list (obviously).
This is the code i'm going to use to get the list of 4 random missions. Right now it just listes all the missions. Edit it if you can/bother.
Thanks. +1 rep for a good try ofc.
This is importat, cuz im doing random trucking missions, and i want to show the players a dialog of 4 do-able missions, and i do not want 2 or more same loads in the list (obviously).
This is the code i'm going to use to get the list of 4 random missions. Right now it just listes all the missions. Edit it if you can/bother.
pawn Код:
stock Product_RandomGetList(PCV_Needed, &NumProducts)
{
// Setup local variables
new ProductList[50];
// Loop through all products
for (new i; i < sizeof(ALoads); i++)
{
new value = random(sizeof(NumProducts));
// Check if there aren't 50 products found (and added to the ProductList) yet
if (NumProducts < 3)
{
// Check if the current product has the same PCV_Needed
if (ALoads[i][PCV_Required] == PCV_Needed)
{
// Add the ProductID to the ProductList
ProductList[value] = i;
// Increase the counter NumProducts
NumProducts++;
}
}
}
// Return the ProductList
return ProductList;
}