Lemke

Member
Hello!
Im just trying to get drop chance of custom items based on players luck,and trying that:

C#:
if (mob.Luck <= 499)
double random = 0.01;
if (mob.Luck >= 500 && mob.Luck < 999)
double random = 0.02;
if (mob.Luck >= 999&& mob.Luck < 1999)
double random = 0.03;
if (mob.Luck >= 1999 && mob.Luck < 2999)
double random = 0.04;
if (mob.Luck > 2999)
double random = 0.05;
    if ( mob.Player )
     {
     if (Utility.RandomDouble() <= random)
     {
Getting error when loading:

An embedded statement cannot be a declaration or a tagged statement.
What im doing wrong?Thank you!
 
Last edited:
Can you post the entire script and the entire error? Not sure based on your error where exactly the error is happening. Also, if you run in debug mode it will give the exact line number in the error.
 
Sure!
Full script:
C#:
using System;
using Server.Items;
using Server.Mobiles;
using System.Collections;
using Server.Network;
using VitaNex.Modules.Discord;

namespace Server.Mobiles
{
    [CorpseName( "remains of DaemonicCrafter" )]
    public class DaemonicCrafter : BaseCreature
    {
        public override bool ShowFameTitle{ get{ return false; } }
        
        public override int GetIdleSound()
        {
            return 0x482;
        }

        public override int GetDeathSound()
        {
            return 0x485;
        }

        public override int GetAttackSound()
        {
            return 0x47F;
        }

        public override int GetHurtSound()
        {
            if (this.Hits > 1000)
            {
                return 0x480; //play hurt sound
            }
            else if (this.Hits > 500)
            {
                return 0x484; //play hurt sound
            }
            else if (this.Hits > 100)
            {
                return 0x44A; //play hurt sound
            }
            else
            {
                return 0x486; //play hurt sound
            }
        }

        public override int GetAngerSound()
        {
            return 0x481;
        }

        [Constructable]       
        public DaemonicCrafter() : base( AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4 )
        {
            Name = "Daemonic crafter";
            Body = 185;
            BaseSoundID = 0x47F;
            Hue = 0x4001;
            
            this.SetStr(796, 825);
            this.SetDex(86, 105);
            this.SetInt(436, 475);

            this.SetHits(3000, 6000);

            this.SetDamage(16, 22);

            this.SetDamageType(ResistanceType.Physical, 100);

            this.SetResistance(ResistanceType.Physical, 55, 65);
            this.SetResistance(ResistanceType.Fire, 60, 70);
            this.SetResistance(ResistanceType.Cold, 30, 40);
            this.SetResistance(ResistanceType.Poison, 25, 35);
            this.SetResistance(ResistanceType.Energy, 35, 45);

            this.SetSkill(SkillName.EvalInt, 30.1, 40.0);
            this.SetSkill(SkillName.Magery, 30.1, 40.0);
            this.SetSkill(SkillName.MagicResist, 99.1, 100.0);
            this.SetSkill(SkillName.Tactics, 97.6, 100.0);
            this.SetSkill(SkillName.Wrestling, 90.1, 92.5);

            this.Fame = 15000;
            this.Karma = -15000;

            this.VirtualArmor = 60;

            PlateChest chest = new PlateChest();
            chest.Hue = 2176;
            chest.Movable = false;
            AddItem( chest );
            
            PlateArms arms = new PlateArms();
            arms.Hue = 2176;
            arms.Movable = false;
            AddItem( arms );
            
            PlateGloves gloves = new PlateGloves();
            gloves.Hue = 2176;
            gloves.Movable = false;
            AddItem( gloves );
            
            PlateGorget gorget = new PlateGorget();
            gorget.Hue = 2176;
            gorget.Movable = false;
            AddItem( gorget );
            
            PlateLegs legs = new PlateLegs();
            legs.Hue = 2176;
            legs.Movable = false;
            AddItem( legs );

            Cloak cloak = new Cloak();
            cloak.Hue = 2176;
            cloak.Movable = false;
            AddItem( cloak );
            
            Scimitar weapon = new Scimitar();
            weapon.Movable = false;
            weapon.Hue = 2176;
            AddItem( weapon );
            
            ChaosShield lantern = new ChaosShield();
            lantern.Movable = false;
            AddItem( lantern );           
            
            ThighBoots boots = new ThighBoots();
            boots.Movable = false;
            AddItem( boots );
            
            AddItem( new Gold( 500, 1000 ));
            

            new Beetle().Rider = this;
        }
        
        //public override bool BardImmune{ get{ return true; } }
        public override bool AutoDispel{ get{ return true; } }
        //public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
        public override bool AlwaysMurderer{ get{ return true; } }
        
        public override void GenerateLoot()
        {
            
            AddLoot( LootPack.Average );
        }

        private static bool m_InHere;
        
        

public override void OnKilledBy( Mobile mob )
{
//double random = chance;

if (mob.Luck <= 499)
double random = 0.01;
if (mob.Luck >= 500 && mob.Luck < 999)
double random = 0.02;
if (mob.Luck >= 999 && mob.Luck < 1999)
double random = 0.03;
if (mob.Luck >= 1999 && mob.Luck < 2999)
double random = 0.04;
if (mob.Luck > 2999)
double random = 0.05;
     if ( mob.Player )
     {
     if (Utility.RandomDouble() < 0.05)
     {
     mob.AddToBackpack(new RandomRunicToolDeed());
     mob.PlaySound(0x5B4);
     mob.PublicOverheadMessage( MessageType.Regular, 1153, true, "ayyy caramba,got a random runic tool!!!" );
     VitaNex.Modules.Discord.DiscordBot.SendMessage("Dadabooom!,"+mob.Name+" got a random runic tool deed from damonic crafters!");
     }
     }
base.OnKilledBy( mob );
}

        public override void AddNameProperties(ObjectPropertyList list)
        {
            base.AddNameProperties(list);
            list.Add("Chance to get: Random runic tool deed.[Chance is 5%].");
        }   
        public override void OnDoubleClick( Mobile from )
        {
        from.SendMessage(33, String.Format("You an get a random runic tool deed with 1-3 uses."));
        base.OnDoubleClick( from );
        }

        public DaemonicCrafter( Serial serial ) : base( serial )
        {
        }

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
            writer.Write( (int) 0 );
        }

        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
        }

    }
}
Error picture:
Sin título.png

Debug mode dont say about this error.
 
The problem was declaring random multiple times.

OK try this:

C#:
double random;

if (mob.Luck <= 499)
    random = 0.01;
if (mob.Luck >= 500 && mob.Luck < 999)
    random = 0.02;
if (mob.Luck >= 999 && mob.Luck < 1999)
    random = 0.03;
if (mob.Luck >= 1999 && mob.Luck < 2999)
    random = 0.04;
if (mob.Luck > 2999)
    random = 0.05;


     if ( mob.Player )
     {
     if (Utility.RandomDouble() < random)
     {
 
Ok,just getting error in line:
C#:
if (Utility.RandomDouble() < random)
"Using the unassigned local variable 'random'"
 
It's telling you to assign a value to random that isn't part of an if statement.

instead of:
double random;
use:
double random = 0;
 
Btw if you reorder your ifs, you can simplify it. Besides with your code the player is kind of screwed if his Luck is exactly 2999 since then his random value would be 0. Also you should use else and else if in your case there

C#:
if (mob.Luck <= 499)
    random = 0.01;
if (mob.Luck >= 500 && mob.Luck < 999)
    random = 0.02;
if (mob.Luck >= 999 && mob.Luck < 1999)
    random = 0.03;
if (mob.Luck >= 1999 && mob.Luck < 2999)
    random = 0.04;
if (mob.Luck > 2999)
    random = 0.05;

Here is an example to make it simpler

C#:
double random = 0.01;

if (mob.Luck >= 3000)
    random = 0.05;
else if(mob.Luck >= 2000)
    random = 0.04;
else if(mob.Luck >= 1000)
    random = 0.03;
else if(mob.Luck >= 500)
    random = 0.02;
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back