Random Loot question

sheivan

Citizen
Jul 17, 2019
35
1
8
If I wanted to make monsters drop randomly one of 50 items, would there be an easier way than doing


{
base.OnDeath( c );

if ( Utility.RandomDouble() < 0.95 )
c.DropItem( new EmberStaff() );

if ( Utility.RandomDouble() < 0.55 )
c.DropItem( new DeathsHead() );

}


etc..
?
 

PyrO

Moderator
Jan 27, 2015
1,355
195
63
You can do something like this.

First add
C#:
        private static readonly Type[] rewards = new Type[]
        {
            typeof(EmberStaff), typeof(DeathsHead), typeof(StaffOfTheMagi)
        };
inside your code.

Then where you want to drop the item, you can simply do.
C#:
            c.DropItem(Activator.CreateInstance(rewards[Utility.Random(rewards.Length)]) as Item);
This way you will get 1 random Item of the types you defined in the rewards array
 

sheivan

Citizen
Jul 17, 2019
35
1
8
Exactly what I was looking for, thanks alot (again lol)
I was trying to do something similar in the loot codes but couldnt find exactly how :)