Random missions in specific area
#1

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.

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;
}
Thanks. +1 rep for a good try ofc.
Reply


Messages In This Thread
Random missions in specific area [+1Reputation] - by Hessu - 30.06.2015, 09:30
Re: Random missions in specific area - by Hessu - 01.07.2015, 03:54
Re: Random missions in specific area - by Hessu - 02.07.2015, 13:28
Re: Random missions in specific area - by Diovis - 02.07.2015, 13:32
AW: Random missions in specific area [+1Reputation] - by Kaliber - 02.07.2015, 13:35
Re: AW: Random missions in specific area [+1Reputation] - by Hessu - 03.07.2015, 03:52

Forum Jump:


Users browsing this thread: 4 Guest(s)