OP
Xeno

Xeno

Member
ServUO Version
Publish 58
Ultima Expansion
Endless Journey
I am trying to adjust this so there is a 30% chance that one of these items will drop. I am using this:
C#:
 public override bool OnBeforeDeath()
        {
            if (Utility.Random() < 30) // 30% chance to drop
                    switch (Utility.Random(4))
                    {
                        case 0: PackItem(new BarbarianGloves()); break;
                        case 1: PackItem(new BarbarianArms()); break;
                        case 2: PackItem(new BarbarianLegs()); break;
                        case 3: PackItem(new BarbarianChest()); break;
                    }

            return base.OnBeforeDeath();
        }

I am getting this error:
F:\Games\Electronic Arts\Dark Karma Trials\Dark Karma Trial 1\Scripts\CUSTOM SCRIPTS PnP\Barbarians Lava\BarbarianRider.cs(86,16): error CS1501: No overload for method 'Random' takes 0 arguments [F:\Games\Electronic Arts\Dark Karma Trials\Dark Karma Trial 1\Scripts\Scripts.csproj]

What am I missing?

Is it wanting something in here like if (Utility.Random(5) < 30) // 30% chance to drop
 
Code:
 public override bool OnBeforeDeath()
{
switch (Utility.Random(12))
{
case 0: PackItem(new BarbarianGloves()); break;
case 1: PackItem(new BarbarianArms()); break;
case 2: PackItem(new BarbarianLegs()); break;
case 3: PackItem(new BarbarianChest()); break;
default : break;
 }

return base.OnBeforeDeath();
}

I would set the random beyond your case count by what ever the x to % you want, only having the cases that drop items used as above 0 - 3, then by overloading and using default to return nothing in the cases exceeding the switch cases used!
 
Utility.Random() wants a value in the parentheses... so "Utility.Random(100)" in your case.
The error message is stating that the method Random does not have any entries to know what to do when no parameters are passed to it.
 
I am not entirely sure I understand. I initially had this in place
C#:
public override void GenerateLoot()
        {
            AddLoot(LootPack.Rich);
            //AddLoot(LootPack.MageryRegs, 10, 15);
            AddLoot(LootPack.LootItem<MoltenBerry>(10.0, true));
            AddLoot(LootPack.LootItem<EnhancedBandage>(5, 15));
            AddLoot(LootPack.LootItem<SeveredHumanEars>(75.0, 1));

            switch (Utility.Random(10))
            {
                case 0: PackItem(new BarbarianGloves()); break;
                case 1: PackItem(new BarbarianArms()); break;
                case 2: PackItem(new BarbarianLegs()); break;
                case 3: PackItem(new BarbarianChest()); break;
            }
        }

but it seemed to drop one quite often. After doing some google searching, I found that other method but it was from 2017 so I was not sure it would work. Initially I thought the 10 in here meant 10% of the time: switch (Utility.Random(10)) but then when I found the previous listed method, it seemed like the number stood for how many items there were to choose from. I am very confused by this.

It also did not say anything about before death though not entirely sure that mattered since I was still getting the drops without it. With all of the changes over the years, I am often confused by what is needed now and what still worked from before though it is not the best way to do it but someone modified something old to make it work.
 
Treat this code,
Code:
switch (Utility.Random(10))
            {
                case 0: PackItem(new BarbarianGloves()); break;
                case 1: PackItem(new BarbarianArms()); break;
                case 2: PackItem(new BarbarianLegs()); break;
                case 3: PackItem(new BarbarianChest()); break;
            }

Like this,
Code:
switch (Utility.Random(10))
            {
                case 0: PackItem(new BarbarianGloves()); break;
                case 1: PackItem(new BarbarianArms()); break;
                case 2: PackItem(new BarbarianLegs()); break;
                case 3: PackItem(new BarbarianChest()); break;
                case 4: break;
                case 5: break;
                case 6: break;
                case 7: break;
                case 8: break;
                case 9: break;
            }

They are the same!
 
Your initial logic structure (after fixing the references) would be more like:
30% of the time drop one if the items 25% of those instances (balanced drop of pieces over time). Roughly 7.5% (30 / 4 = 7.5 ) of the time would give 1 specific piece.

Using the "Random(10)" gives when the number generated is 0-3 (4 times) out of 10 one of those would drop, so 40% (4 / 10) of the time getting one of those. Roughly 10% (1/10) of all the times would give 1 specific piece.

GoldDraco13 suggested "Random(12)" which would generate loot 33% (4/12 = .33) of the time and 8.25% (33% / 4) of the time 1 specific piece.
 
Some things to get your head around, 0 is always the starting value or position, but as for the math it is count 1, hence the switch with a random 10 has 9 cases, but counts 10 with 0!

Switch statements make a case for each item going in, so if you give it a min max number set, the cases will match the set, in this case, 1-10, but any number can be used, and to save space, you leave empty cases out as they will fall through without a break;

so with out a break; case 1: (if nothing here) will fall to case 2: and see if there is code until it hits the switch limit, in your case 10 and then breaks out!
I should also add, the fall through matters as if you put your code on cases 6-9 and did not use breaks on the previous cases, the code then would allow the first item in case 6 to hit 70% and the other 3 will share the 30% for 10% each!
 
Can you do the same thing in the same script but with different items. Lets say there are 4 items that you would like to drop 30% of the time and then 1 item you would like to see drop 10% of the time. For example:
C#:
switch (Utility.Random(12))
            {
                case 0: PackItem(new BarbarianGloves()); break;
                case 1: PackItem(new BarbarianArms()); break;
                case 2: PackItem(new BarbarianLegs()); break;
                case 3: PackItem(new BarbarianChest()); break;
            }
switch switch (Utility.Random(5))
            {
                case 0: PackItem(new BarbarianChiefHelm()); break;
            }
 
yep
but understand, they both are on there own then, so you might have a item from both switches dropping at the same time!
you could do a switch within a switch but not sure you'll catch on to that yet!
 
you could do a switch within a switch but not sure you'll catch on to that yet!

That would probably be over my head at this point but something to work towards. Yes, I knew there would be a chance for one from the first switch and one from the second switch to drop at the same time but better than the alternative. The helm is quite a bit nicer than the other 4 items so I want it to drop less.

Once again, I greatly appreciate everyone's patience and assistance. This has been a lot of fun and I am learning so much.
 
You can also do something like this to get the main items to drop 3x more often than the BarbarianChiefHelm

C#:
            switch (Utility.Random(40)) //a guesstimate on around 30% you could use a calculator to be more exact.
            {
                case 0: PackItem(new BarbarianGloves()); break;
                case 1: PackItem(new BarbarianArms()); break;
                case 2: PackItem(new BarbarianLegs()); break;
                case 3: PackItem(new BarbarianChest()); break;
                case 4: PackItem(new BarbarianGloves()); break;
                case 5: PackItem(new BarbarianArms()); break;
                case 6: PackItem(new BarbarianLegs()); break;
                case 7: PackItem(new BarbarianChest()); break;
                case 8: PackItem(new BarbarianGloves()); break;
                case 9: PackItem(new BarbarianArms()); break;
                case 10: PackItem(new BarbarianLegs()); break;
                case 11: PackItem(new BarbarianChest()); break;
                case 12: PackItem(new BarbarianChiefHelm()); break;
            }
 
This is a really nice topic for folks to see!
Good ask, @Xeno ! ;)

Just wanted to touch on what GD said:
yep
but understand, they both are on there own then, so you might have a item from both switches dropping at the same time!
you could do a switch within a switch but not sure you'll catch on to that yet!

A lot of the things we work with, code, files, folder structure, etc., etc. is all about hierarchy, structure. Utility and Switch cases are also a part of that, but usually when coding it is called "nesting".
The structure all comes from the root, or the main Utility/Switch case and then *inside* that root you can keep going deeper into the structure by adding another Switch/Utility just inside the root and then keep doing that....

Switch
->Utility
--->Switch
----->Switch
------->Utility
--------->Utility

You can go deeper with more cases and you can have multiple cases at each level too, but it might be helpful to determine why you would need to do all that in the first place. For example, some vendors have a pretty complex Case structures (as well as if/then statements) that look at "gender", "location", "race", "stats", and determine which items from each Case the vendor has equipped. Those are all separate Cases though and not nested, but you could nest them if you changed the structure a bit.

The longer you are in this community, the more likely you are to run across a hundred different ways, different people coded the same thing. Maybe not a hundred, but a lot. ;)

Lots of knowledge in this whole thread though! Thanks, everybody! :cool: :)
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back