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
#2

Bump with new data in the topic
Reply
#3

Bump with a new question. Look at first post!
Reply
#4

I don't think you can prevent the same value from being picked several times because it's random

But you can create a cool down timer for each item and check if it was picked recently, if it was, skip to the next one

I would help you out but i'm on my phone
Reply
#5

Quote:
Originally Posted by Hessu
Посмотреть сообщение
One simple question: How do i prevent random function to pick up the same value several times?
Well, try this:

PHP код:
new r_Random[5] = {-1,...};
stock getRealRandom(size)
{
    static 
last;
    new 
i,r=random(size);
    for(; 
i<sizeof r_Randomi++) if(== r_Random[i]) random(size),i=0;
    if(++
last == sizeof(r_Random)) last=0;
    
r_Random[last] = r;
    return 
r;

Greekz
Reply
#6

Okay, so this gives 5 values, and the "size" is the ammount of jobs? Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)