I am way out of practice, but looked over some other quests to refresh my memory. Not sure of the 'best' way, but one of the easy ways to make a random'ish drop is to give it a list to choose from. Here is an example with 8 items (cases 0-7). You could add the item, and various other items. That way it will randomly pick one item on the list. You can change the number (in this example 8). Just make sure you number them starting with zero. Simply edit "Item1", "Item2" etc with actual items.

switch ( Utility.Random( 8 ) )
{
case 0: mobile.AddToBackpack( new Item1() ); break;

case 1: mobile.AddToBackpack( new Item2() ); break;

case 2: mobile.AddToBackpack( new Item3() ); break;

case 3: mobile.AddToBackpack( new Item4() ); break;

case 4: mobile.AddToBackpack( new Item5() ); break;

case 5: mobile.AddToBackpack( new Item6() ); break;

case 6: mobile.AddToBackpack( new Item7() ); break;

case 7: mobile.AddToBackpack( new Item8() ); break;
}



Similarly, sometimes to drop an item, but in random amounts, you can use the Utility.RandomDouble. I use this on collections, to get a bunch of special scrolls/gems etc. This example is taken straight from the Ludwig Quest. Not sure who wrote it, or where I got it.

public override void GenerateLoot()
{
AddLoot(LootPack.FilthyRich);
if (Utility.RandomDouble() <= 0.40)
PackItem(new SheetMusic() );
}



To go a step further, you can combine them, as in the Jupiter Armor Quest (again, not my script). you can change the utility random, so it does not always drop anything. Then edit the list to give it a 'random' item IF it drops. Hopefully someone will correct me if my memory fails... if 1 > is 100%,


{
if( 1 > Utility.RandomDouble() ) // 1 = 100% = chance to drop
switch ( Utility.Random( 8 ))
{
case 0: mobile.AddToBackpack( new Armsofjupiter() ); break;
case 1: mobile.AddToBackpack( new Chestofjupiter() ); break;
case 2: mobile.AddToBackpack( new Gorgetofjupiter() ); break;
case 3: mobile.AddToBackpack( new Helmetofjupiter() ); break;
case 4: mobile.AddToBackpack( new Leggingsofjupiter() ); break;
case 5: mobile.AddToBackpack( new Glovesofjupiter() ); break;
case 6: mobile.AddToBackpack( new FemaleChestofjupiter() ); break;
case 7: mobile.AddToBackpack( new Skirtofjupiter() ); break;

}

~Edit~ Here is an old thread, but I think Punkte's example is still good.
 
Last edited:
I am way out of practice, but looked over some other quests to refresh my memory. Not sure of the 'best' way, but one of the easy ways to make a random'ish drop is to give it a list to choose from. Here is an example with 8 items (cases 0-7). You could add the item, and various other items. That way it will randomly pick one item on the list. You can change the number (in this example 8). Just make sure you number them starting with zero. Simply edit "Item1", "Item2" etc with actual items.

switch ( Utility.Random( 8 ) )
{
case 0: mobile.AddToBackpack( new Item1() ); break;

case 1: mobile.AddToBackpack( new Item2() ); break;

case 2: mobile.AddToBackpack( new Item3() ); break;

case 3: mobile.AddToBackpack( new Item4() ); break;

case 4: mobile.AddToBackpack( new Item5() ); break;

case 5: mobile.AddToBackpack( new Item6() ); break;

case 6: mobile.AddToBackpack( new Item7() ); break;

case 7: mobile.AddToBackpack( new Item8() ); break;
}



Similarly, sometimes to drop an item, but in random amounts, you can use the Utility.RandomDouble. I use this on collections, to get a bunch of special scrolls/gems etc. This example is taken straight from the Ludwig Quest. Not sure who wrote it, or where I got it.

public override void GenerateLoot()
{
AddLoot(LootPack.FilthyRich);
if (Utility.RandomDouble() <= 0.40)
PackItem(new SheetMusic() );
}



To go a step further, you can combine them, as in the Jupiter Armor Quest (again, not my script). you can change the utility random, so it does not always drop anything. Then edit the list to give it a 'random' item IF it drops. Hopefully someone will correct me if my memory fails... if 1 > is 100%,


{
if( 1 > Utility.RandomDouble() ) // 1 = 100% = chance to drop
switch ( Utility.Random( 8 ))
{
case 0: mobile.AddToBackpack( new Armsofjupiter() ); break;
case 1: mobile.AddToBackpack( new Chestofjupiter() ); break;
case 2: mobile.AddToBackpack( new Gorgetofjupiter() ); break;
case 3: mobile.AddToBackpack( new Helmetofjupiter() ); break;
case 4: mobile.AddToBackpack( new Leggingsofjupiter() ); break;
case 5: mobile.AddToBackpack( new Glovesofjupiter() ); break;
case 6: mobile.AddToBackpack( new FemaleChestofjupiter() ); break;
case 7: mobile.AddToBackpack( new Skirtofjupiter() ); break;

}

~Edit~ Here is an old thread, but I think Punkte's example is still good.

Awesome! Very good explanation. And, better yet, it works great!
 
Back