Discussion in   Coding Corner   started     10 years ago   July 13, 2013, 12:36:15 AM   by   Kyn

Lets make a weapon! (C#)

Kyn
Offline
336 Posts
Topic :   Lets make a weapon! (C#)
10 years ago  July 13, 2013, 12:36:15 AM


Hey guys. I realize that my first tutorial may have been starting off a little bit advanced for some of you beginners. So for the next item I will try and include as much information in regards to syntax and differen't item properties.


We will be making a Katana, promptly titled "Kyns Katana"


As with everything we will start with our "using directives" as seen below. Please note this is a weapon so we will be using "Server.Items;" and "Server.Targeting;" as well as "System;" and "Server.Network;"


Code: [Select]
using System;
using Server.Network;
using Server.Items;
using Server.Targeting;


Next we will create our item Namespace, public class for the item and give it a base reference "KynsKatana : Katana" - Don't forget your opening brackets!


Code: [Select]
using System;
using Server.Network;
using Server.Items;
using Server.Targeting;


namespace Server.Items
{
   public class KynsKatana : Katana
  {


Next I will add in my public item overrides for various properties that I'd like to have on my sword. For the purpose of this tutorial I have included multiple overrides.


Code: [Select]
using System;
using Server.Network;
using Server.Items;
using Server.Targeting;


namespace Server.Items
{
   public class KynsKatana : Katana
  {
      public override int ArtifactRarity{ get{ return 125; } }


      public override int OldMinDamage{ get{ return 16; } }
      public override int AosMinDamage{ get{ return 16; } }
      public override int OldMaxDamage{ get{ return 19; } }
      public override int AosMaxDamage{ get{ return 19; } }


      public override int InitMinHits{ get{ return 120; } }
      public override int InitMaxHits{ get{ return 120; } }




As you can see, our public overrides are now added. Each one has a specific purpose. InitMinHits and InitMaxHits dictate the durability of the items. So as you can see our item (when brand new) will have 120/120 durability as dictated by the "public override int InitMinHits" and "public override int InitMaxHits" We also have an override for the items damage which will be 16-19. Please note that overrides for damage are only need if you want the damage/durability to be different from the base item we used as a reference earlier in "Public class KynsKatana : Katana" (which was the Katana)


Next we will be creating the item itself, assigning it the [Constructable] tag and various other properties.


Code: [Select]
using System;
using Server.Network;
using Server.Items;
using Server.Targeting;


namespace Server.Items
{
   public class KynsKatana : Katana
  {
      public override int ArtifactRarity{ get{ return 125; } }


      public override int OldMinDamage{ get{ return 16; } }
      public override int AosMinDamage{ get{ return 16; } }
      public override int OldMaxDamage{ get{ return 19; } }
      public override int AosMaxDamage{ get{ return 19; } }


      public override int InitMinHits{ get{ return 120; } }
      public override int InitMaxHits{ get{ return 120; } }


      [Constructable]
      public KynsKatana()
      {
          Weight = 3;
          Name = "Kyns Katana";
          Hue = 1150;


we have now assigned the item a name, a weight (in stones) and a hue color. "Weight = 3;" "Name ="Kyns Katana";" and "Hue = 1150;"


Next we will be adding various weapon attributes, for the purposes of the tutorial I have added a ton of attributes so that you can see how they function. There is no real order they need to be in pending that your syntax when adding them is correct. I like to keep my weapon attributes and my generic attributes seperated. - Again don't forget your closing bracket!


Code: [Select]
using System;
using Server.Network;
using Server.Items;
using Server.Targeting;


namespace Server.Items
{
   public class KynsKatana : Katana
  {
      public override int ArtifactRarity{ get{ return 125; } }


      public override int OldMinDamage{ get{ return 16; } }
      public override int AosMinDamage{ get{ return 16; } }
      public override int OldMaxDamage{ get{ return 19; } }
      public override int AosMaxDamage{ get{ return 19; } }


      public override int InitMinHits{ get{ return 120; } }
      public override int InitMaxHits{ get{ return 120; } }


      [Constructable]
      public KynsKatana()
      {
          Weight = 3;
          Name = "Kyns Katana";
          Hue = 1150;
      WeaponAttributes.ResistColdBonus = 5;
      WeaponAttributes.ResistEnergyBonus = 5;
      WeaponAttributes.ResistPhysicalBonus = 5;
      WeaponAttributes.ResistPoisonBonus = 5;
      WeaponAttributes.ResistFireBonus = 5;
      WeaponAttributes.SelfRepair = 5;
      WeaponAttributes.UseBestSkill = 1;
      Attributes.BonusStr = 5;
      Attributes.BonusDex = 5;
      Attributes.BonusInt = 5;
      Attributes.EnhancePotions = 5;
      Attributes.LowerManaCost = 5;
      Attributes.LowerRegCost = 5;
      Attributes.Luck = 5;
      Attributes.NightSight = 1;
      Attributes.RegenHits = 5;
      Attributes.RegenMana = 5;
      Attributes.RegenStam = ;
      Attributes.SpellChanneling = 1;
      Attributes.SpellDamage = 5;
      Attributes.WeaponSpeed = 20;
      }



All of the differen't bonuses and attributes can be modifed by simply changing the number. For the purposes of this tutorial they are all 5. However it is easy to change the amount to whatever you'd like. Be advised that some attributes are simply "on" or "off" attributes, one example being spell channeling. Its value is either 1 (for yes) or 0 (for no)

Now lets serialize our item and give it a try!


Code: [Select]
using System;
using Server.Network;
using Server.Items;
using Server.Targeting;


namespace Server.Items
{
   public class KynsKatana : Katana
  {
      public override int ArtifactRarity{ get{ return 125; } }


      public override int OldMinDamage{ get{ return 16; } }
      public override int AosMinDamage{ get{ return 16; } }
      public override int OldMaxDamage{ get{ return 19; } }
      public override int AosMaxDamage{ get{ return 19; } }


      public override int InitMinHits{ get{ return 120; } }
      public override int InitMaxHits{ get{ return 120; } }


      [Constructable]
      public KynsKatana()
      {
          Weight = 3;
          Name = "Kyns Katana";
          Hue = 1150;
      WeaponAttributes.ResistColdBonus = 5;
      WeaponAttributes.ResistEnergyBonus = 5;
      WeaponAttributes.ResistPhysicalBonus = 5;
      WeaponAttributes.ResistPoisonBonus = 5;
      WeaponAttributes.ResistFireBonus = 5;
      WeaponAttributes.SelfRepair = 5;
      WeaponAttributes.UseBestSkill = 1;
      Attributes.BonusStr = 5;
      Attributes.BonusDex = 5;
      Attributes.BonusInt = 5;
      Attributes.EnhancePotions = 5;
      Attributes.LowerManaCost = 5;
      Attributes.LowerRegCost = 5;
      Attributes.Luck = 5;
      Attributes.NightSight = 1;
      Attributes.RegenHits = 5;
      Attributes.RegenMana = 5;
      Attributes.RegenStam = ;
      Attributes.SpellChanneling = 1;
      Attributes.SpellDamage = 5;
      Attributes.WeaponSpeed = 20;
      }


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


      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();
      }
   }
}


There you have it, our very own Katana with a ridiclous amount of attributes. I hope this help shed a little light on the basic scripting process behind creating an item. Thanks for reading :)

KhaoticFuture
Offline
2 Posts
#1 Re :   Lets make a weapon! (C#)
10 years ago  July 13, 2013, 12:46:15 AM

<3 love the scripting tutorials Kyn, its really neat for those of us that know some C# but are not familiar with the RunUO stuff.

pibb100k
Offline
49 Posts
#2 Re :   Lets make a weapon! (C#)
10 years ago  July 13, 2013, 10:47:47 AM

Yeh, i know HTML and Java.... Lol, Kyn sell that katana at the next auction

Loki
Offline
7 Posts
#3 Re :   Lets make a weapon! (C#)
10 years ago  July 13, 2013, 01:11:56 PM

Liking these Kyn you should keep posting tutorials