Yvan Major

Member
Hi, i am trying to create the spike head, it load correctly but it tell me

CS1729: Line 94: 'Server.Items.SpikeHead' does not contain a constructor tha
t takes 0 arguments

This is when i try to add it to a monster.

Thanks for any help.
 

Attachments

  • SpikeHead.cs
    1.2 KB · Views: 4
The error is correct, the only constructor you have has 1 argument, which is a string. It is expecting you to call it like this:

Code:
this.AddToBackPack( new SpikeHead("Billy Bob Thornton") ); //or whatever name you want to give the SpikeHead.

If you are expecting to add it with just this:

Code:
new SpikeHead();

Then in the SpikeHead.cs script, you need to create a zero argument constructor. It might look something like this:

Code:
        [Constructable]
        public SpikeHead()
            : this( "Billy Bob Thornton" )
        {
        }
 
Helpful Little Tip Thanks Lokai. Really like how u explain things have learned a lot from your post :)
 
The error is correct, the only constructor you have has 1 argument, which is a string. It is expecting you to call it like this:

Code:
this.AddToBackPack( new SpikeHead("Billy Bob Thornton") ); //or whatever name you want to give the SpikeHead.
[/code]

The thing is that it is supposed to give the killer's (player) name of the mob.

public SpikeHead(string name)

// ~1_NAME~'s Head on a Spike
 
Anyone can point me somewhere to add the "killer's" name in front of the name like the cliloc: ~1_NAME~'s Head on a Spike


Thanks in advance for any help.
 
You might have to override the OnDeath method. Add something like this:


Code:
PlayerMobile killer = this.FindMostRecentDamager;

if (killer != null) this.AddToBackPack( new SpikeHead(killer.Name) );
 
Got it to load and compile but it seems something getting in conflict cause when one Spike Head drop it crash the server, maybe you can help ?

Code:
using System;

namespace Server.Items
{
    public class SpikeHead : Item
    {
        private static readonly int[] m_ItemIDs = new int[]
        {
            0x9956, 0x9957, 0x9958, 0x9959
        };
        private string m_Name;
        [Constructable]
        public SpikeHead(string name)
            : base(Utility.RandomList(m_ItemIDs))
        {
            this.m_Name = name;
        }

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

        public override void OnSingleClick(Mobile from)
        {
            this.LabelTo(from, Name, 1154355);
        }// ~1_NAME~'s Head on a Spike

        public override void GetProperties(ObjectPropertyList list)
        {
            base.GetProperties(list);

            list.Add(Name, 1154355);
        }
        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);

            writer.Write((int)0); // version
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();
            this.m_Name = Utility.Intern(reader.ReadString());
        }
    }
}

Code:
using System;
using System.Collections.Generic;
using Server;
using Server.Items;
using Server.Misc;
using Server.Spells;
using Server.Targeting;

namespace Server.Mobiles
{
    [CorpseName("an orcish corpse")]
    public class OrcGeneral : BaseCreature
    {
        [Constructable]
        public OrcGeneral()
            : base(AIType.AI_OrcScout, FightMode.Closest, 10, 7, 0.2, 0.4)
        {
            Name = "an orc general";
            this.Body = 0xB5;
            this.Hue = 2221;
            this.BaseSoundID = 0x45A;

            this.SetStr(986, 1185);
            this.SetDex(177, 255);
            this.SetInt(151, 250);

            this.SetHits(592, 711);

            this.SetDamage(22, 29);

            this.SetDamageType(ResistanceType.Physical, 50);
            this.SetDamageType(ResistanceType.Fire, 25);
            this.SetDamageType(ResistanceType.Energy, 25);

            this.SetResistance(ResistanceType.Physical, 65, 80);
            this.SetResistance(ResistanceType.Fire, 60, 80);
            this.SetResistance(ResistanceType.Cold, 50, 60);
            this.SetResistance(ResistanceType.Poison, 100);
            this.SetResistance(ResistanceType.Energy, 40, 50);

            this.SetSkill(SkillName.Anatomy, 25.1, 50.0);
            this.SetSkill(SkillName.EvalInt, 90.1, 100.0);
            this.SetSkill(SkillName.Magery, 95.5, 100.0);
            this.SetSkill(SkillName.Meditation, 25.1, 50.0);
            this.SetSkill(SkillName.MagicResist, 100.5, 150.0);
            this.SetSkill(SkillName.Tactics, 90.1, 100.0);
            this.SetSkill(SkillName.Wrestling, 90.1, 100.0);

            this.Fame = 24000;
            this.Karma = -24000;

            this.VirtualArmor = 90;

            PackItem(new Apple(Utility.RandomMinMax(3, 5)));
            PackItem(new Arrow(Utility.RandomMinMax(60, 70)));
            PackItem(new Bandage(Utility.RandomMinMax(1, 15)));
        }

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

        public override InhumanSpeech SpeechType { get { return InhumanSpeech.Orc; } }
        public override OppositionGroup OppositionGroup { get { return OppositionGroup.SavagesAndOrcs; } }
        public override bool CanHeal { get { return true; } }
        public override bool CanRummageCorpses { get { return true; } }
        public override int Meat { get { return 1; } }

        public override int TreasureMapLevel
        {
            get
            {
                return 5;
            }
        }

        public override void GenerateLoot()
        {
            this.AddLoot(LootPack.FilthyRich, 2);
            this.AddLoot(LootPack.Rich);
        }

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

            if (Utility.RandomDouble() < 0.15)
               c.DropItem( new SpikeHead(Combatant.Name) );

            if (Utility.RandomDouble() < 0.25)
                c.DropItem(new MaulOfOrigin());
        }


        public override bool IsEnemy(Mobile m)
        {
            if (m.Player && m.FindItemOnLayer(Layer.Helm) is OrcishKinMask)
            {
                return false;
            }

            return base.IsEnemy(m);
        }

        public override void AggressiveAction(Mobile aggressor, bool criminal)
        {
            base.AggressiveAction(aggressor, criminal);

            Item item = aggressor.FindItemOnLayer(Layer.Helm);

            if (item is OrcishKinMask)
            {
                AOS.Damage(aggressor, 50, 0, 100, 0, 0, 0);
                item.Delete();
                aggressor.FixedParticles(0x36BD, 20, 10, 5044, EffectLayer.Head);
                aggressor.PlaySound(0x307);
            }
        }

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

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

        }



        private Mobile FindTarget()
        {
            foreach (Mobile m in GetMobilesInRange(10))
            {
                if (m.Player && m.Hidden && m.IsPlayer())
                {
                    return m;
                }
            }

            return null;
        }

        private void TryToDetectHidden()
        {
            Mobile m = FindTarget();

            if (m != null)
            {
                if (Core.TickCount >= NextSkillTime && UseSkill(SkillName.DetectHidden))
                {
                    Target targ = Target;

                    if (targ != null)
                    {
                        targ.Invoke(this, this);
                    }

                    Effects.PlaySound(Location, Map, 0x340);
                }
            }
        }
    }
}

Thanks again for your help :)
 
So the server also crashes when you add the spikehead manually without it being dropped?
 
No but it doesn't either show any name on it. :(

I think I know. You are calling base.OnDeath(c) before dropping the spikehead. The base method is probably clearing the Combatant value. Try using a Try-Catch clause to prevent instability, and drop the spikehead BEFORE you call the base.OnDeath method.
 
I think I know. You are calling base.OnDeath(c) before dropping the spikehead. The base method is probably clearing the Combatant value. Try using a Try-Catch clause to prevent instability, and drop the spikehead BEFORE you call the base.OnDeath method.

What is a try-catch clause ? :) and thanks for your help.

Code:
        public override void OnDeath(Container c)
        {
            if (Utility.RandomDouble() < 0.15)
               c.DropItem( new SpikeHead(Combatant.Name) );
            if (Utility.RandomDouble() < 0.25)
                c.DropItem(new MaulOfOrigin());

            base.OnDeath(c);
        }

Even like this it crash.

It look like the server try to double write name on it but i really dont know witch one to remove.
 
Last edited:
What is a try-catch clause ? :) and thanks for your help.

Try-Catch is basic safety net for unknown code problems.

Try { to do something here }
Catch( Exception e) { Print error defined by 'e' but don't crash }

Even like this it crash.

It look like the server try to double write name on it but i really dont know witch one to remove.

Please copy the error and paste it here. (Not an image, but as Text preferably.)
 
Code:
Server Crash Report
===================

RunUO Version 0.5, Build 5918.34084
Operating System: Microsoft Windows NT 6.1.7601 Service Pack 1
.NET Framework: 4.0.30319.42000
Time: 2016-03-18 22:00:27
Mobiles: 3633
Items: 114927
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Server.Mobiles.OrcGeneral.OnDeath(Container c)
   at Server.Commands.Generic.KillCommand.Execute(CommandEventArgs e, Object obj)
   at Server.Commands.Generic.BaseCommandImplementor.RunCommand(Mobile from, Object obj, BaseCommand command, String[] args)
   at Server.Commands.Generic.SingleCommandImplementor.OnTarget(Mobile from, Object targeted, Object state)
   at Server.Mobile.SimpleStateTarget.OnTarget(Mobile from, Object targeted) in c:\Users\Immortel\Desktop\Life Binder 2\Server\Mobile.cs:line 2706
   at Server.Targeting.Target.Invoke(Mobile from, Object targeted) in c:\Users\Immortel\Desktop\Life Binder 2\Server\Targeting\Target.cs:line 269
   at Server.Network.PacketHandlers.TargetResponse(NetState state, PacketReader pvSrc) in c:\Users\Immortel\Desktop\Life Binder 2\Server\Network\PacketHandlers.cs:line 1323
   at Server.Network.MessagePump.HandleReceive(NetState ns) in c:\Users\Immortel\Desktop\Life Binder 2\Server\Network\MessagePump.cs:line 187
   at Server.Network.MessagePump.Slice() in c:\Users\Immortel\Desktop\Life Binder 2\Server\Network\MessagePump.cs:line 121
   at Server.Core.Main(String[] args) in c:\Users\Immortel\Desktop\Life Binder 2\Server\Main.cs:line 577

Clients:
- Count: 1
+ 127.0.0.1: (account = Master) (mobile = 0x360 'Life')
 
Try this:

Code:
        public override void OnDeath(Container c)
        {
            if (Utility.RandomDouble() < 0.15)
            {
                try
                {
                    if (Combatant != null)
                        c.DropItem(new SpikeHead(Combatant.Name));
                    else
                        Console.WriteLine("Tried to drop a SpikeHead, but Combatant was null!");
                }
                catch (Exception e) { Console.WriteLine(e.Message); }
            }
            if (Utility.RandomDouble() < 0.25)
                c.DropItem(new MaulOfOrigin());

            base.OnDeath(c);

        }
 

Active Shards

Donations

Total amount
$80.00
Goal
$1,000.00
Back