Vanquisher

Initiate
//public override void OnDeath( Container c )
//{
//base.OnDeath( c );

//if ( Utility.RandomDouble() > 40 )
//{
//switch ( Utility.Random( 3 ) )
//{
// case 0: PackItem( new PowerScroll (SkillName.AnimalTaming, 140 ) ); break;
// case 1: PackItem( new PowerScroll (SkillName.AnimalLore, 140 ) ); break;
// case 2: PackItem( new TamerSkillMount () ); break;

//}
//}
//}



Im wanting to know how to set this up for like 1 out of 5 chance to get one of the items im wanting to know what the variables mean exactly im abit confused.
 
Sure thing.

Basically in that entire block of code you provided, you are overriding the OnDeath method from BaseCreature in whatever file your editing.

Inside the method, the first line:

base.OnDeath(c);
Basically your calling the method that handles all monsters deaths, and then adding more stuff to that method when you override it.

If you want to see an example of this, go to BaseCreature.cs. You'll notice there is the same looking OnDeath method there too.

As far as the rest,

Your saying if Utility.RandomDouble() > 40, call the rest of the code sitting inside those curly braces.
Utility.RandomDouble gives you a random number from 0 to 1. Meaning .1, .55, .32, .99, all acceptable.

The number your comparing it to, you'd want to change to .40. Meaning...
If the random number generated is greater than .40, than do this... (Its basically a 60% chance of succeeding.)

Afterwards, the switch, Utility.Random(3) basically just means, switch between one of these lines of code. The utility.random is telling it to pick a random number between 0 and 2. Even though it shows, 3, doesn't mean 1-3. The random number generator starts at 0, unless you specifically tell it not to. So the 3 numbers its going to randomize are 0, 1, and 2.

Thats why the cases are set up as such, case 0, case 1, case 2.
So whatever number is picked there, lets say two for this instance, it will automatically run the code for ONLY case 2 and ignore the rest.
case 2: PackItem( new TamerSkillMount () ) will be run.


If you are trying to set up a 20% chance to get any of the items listed below, than all you'd have to do is this.
if (Utility.RandomDouble() > .80))
{
//DO the rest of the code here
}
or
if (Utility.RandomDouble() < .20))
{
//DO the rest of the code here
}
 
If the goal is just to get a 1 in 5 chance for one of those items would it be easier to just do a switch with 5 cases, 3 cases being those items, and 2 being some base item (or a bit of gold). So it would always give 1 of the items... It is how I usually run my quest rewards.
Something like this (needs the code, of course)

switch ( Utility.Random( 5 )
case 0 taming scroll
case 1 lore scroll
case 2 skillmount
case 3 plain seed
case 4 plain seed
 
If the goal is just to get a 1 in 5 chance for one of those items would it be easier to just do a switch with 5 cases, 3 cases being those items, and 2 being some base item (or a bit of gold). So it would always give 1 of the items... It is how I usually run my quest rewards.
Something like this (needs the code, of course)

switch ( Utility.Random( 5 )
case 0 taming scroll
case 1 lore scroll
case 2 skillmount
case 3 plain seed
case 4 plain seed

Doign this would be a 60% chance to get one of the items, not 20%.
Yes, you'll have a 20% chance to get any item overall, but I think at least from I read, he wanted a 20% chance of spawning one of those items.

Could be wrong.
 
Reading his question again, I think you may be right. In any case... you made a very good explanation of how that works :)
(I am taking notes ha ha)
 
If you are trying to set up a 20% chance to get any of the items listed below, than all you'd have to do is this.
if (Utility.RandomDouble() > .80))
{
//DO the rest of the code here
}
or
if (Utility.RandomDouble() < .20))
{
//DO the rest of the code here
}
Just to expand on that awesome explanation a tad more, you can put multiple sets of loot in more than one section, i.e.
Code:
if (Utility.RandomDouble() > .30))
{switch ( Utility.Random( 2 ) )
     {
          case 0: PackItem( new PowerScroll (SkillName.AnimalTaming, 140 ) ); break;
          case 1: PackItem( new PowerScroll (SkillName.AnimalLore, 140 ) ); break;
     }
}
if (Utility.RandomDouble() >.10))
{switch (Utility.Random( 2 ) )
     {
          case 0: PackItem( new BankCheck (5000) ); break;
          case 1: PackItem( new TamerSkillMount () ); break;
     }
}
This is a nice way to create more rare drops from individual mobs. Every time you add another if (Utility.RandomDouble() >, just give it a lower value than the one above it. I have come across some pretty complex loot methods, but this seems to be the simplest and easiest.
 
Last edited:

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back