Random missions in specific area - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Random missions in specific area (
/showthread.php?tid=579829)
Random missions in specific area [+1Reputation] -
Hessu - 30.06.2015
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.
Re: Random missions in specific area -
Hessu - 01.07.2015
Bump with new data in the topic
Re: Random missions in specific area -
Hessu - 02.07.2015
Bump with a new question. Look at first post!
Re: Random missions in specific area -
Diovis - 02.07.2015
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
AW: Random missions in specific area [+1Reputation] -
Kaliber - 02.07.2015
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_Random; i++) if(r == r_Random[i]) r = random(size),i=0;
if(++last == sizeof(r_Random)) last=0;
r_Random[last] = r;
return r;
}
Greekz
Re: AW: Random missions in specific area [+1Reputation] -
Hessu - 03.07.2015
Okay, so this gives 5 values, and the "size" is the ammount of jobs? Thanks!