Full Version : Race Change
xmlspawner >>Scripting Support >>Race Change


<< Prev | Next >>

Haazen- 07-15-2006
I do understand most script I look at. But I must admit that I am lost when it comes to Packets and bit map. I got the script for race change command before 2.0 was released. We have had elfs for many months. I converted the racechange command into aan item to give out in a quest. I have try to adjust this script to fit 2.0 but as I said, it evades me. I feel this will be a very useful script for many people is it can be fixed to work. Any help would be great. Here is the sript:
CODE
using System;
using Server.Items;
using Server.Network;

namespace Server.Items
{
public class RaceChangeCrystal : Item
{
 [Constructable]
 public RaceChangeCrystal() : base( 0x240 )
 {
  base.Weight = 1.0;
  base.Hue = 1076;
  base.Name = "magical race change crystal";
 }

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

 public override void OnDoubleClick( Mobile from )
 {
  if ( !IsChildOf( from.Backpack ) )
  {

   from.SendLocalizedMessage( 1042001 );// That must be in your pack for you to use it.
  }
  else
  {
   Mobile m = from;

   byte gender = Convert.ToByte(m.Female);
   byte race   = (byte)(m.Race == Race.Elf ? 1 : 2);

   if (m != null && m.Alive)
   {
    m.Send(new ChangeRace(gender, race));
    this.Delete();
   }
  }
 }
}

public sealed class ChangeRace : Packet
{

 public ChangeRace(byte gender, byte race)
  : base(0xBF)
 {
  EnsureCapacity(7);

  m_Stream.Write( (short) 0x2A     );
  m_Stream.Write( (byte)  gender   );
  m_Stream.Write( (byte)  race     );
 }
 public static void Initialize()
        {

  PacketHandlers.RegisterExtended(0x2A, true, new OnPacketReceive(Change));
 }

 private static void Change(NetState state, PacketReader pvSrc)
 {
  short bodyHue  = pvSrc.ReadInt16();
  short hairId   = pvSrc.ReadInt16();
  short hairHue  = pvSrc.ReadInt16();
  short beardId  = pvSrc.ReadInt16();
  short beardHue = pvSrc.ReadInt16();

  if ((bodyHue | hairId | hairHue | beardId | beardHue) == 0) return;

  Mobile sender    = state.Mobile;

  byte senderFlags = (byte)(Convert.ToByte(sender.Female) | (Convert.ToByte(sender.Race == Race.Elf ? 1 : 2) << 1));

 // Item currentHair    = sender.FindItemOnLayer(Layer.Hair);
 // Item currentBeard   = sender.FindItemOnLayer(Layer.FacialHair);

 // if ( currentBeard != null ) currentBeard.Delete();
 // if ( currentHair  != null ) currentHair.Delete();

  switch (senderFlags)
  {
   case 0:  // human male -> elf male
   {
    sender.Body = 0x25D;
    sender.Hue  = bodyHue;

  //  sender.AddItem( Hair.CreateByID( hairId, hairHue ) );
    sender.Race = Race.Elf;
    sender.Title = "the Elf";
    break;
   }
   case 1:  // human female -> elf female
   {
    sender.Body = 0x25E;
    sender.Hue  = bodyHue;

  //  sender.AddItem( Hair.CreateByID( hairId, hairHue ) );
    sender.Race = Race.Elf;
    sender.Title = "the Elf";
    break;
   }
   case 2:  // elf male -> human male
   {
    sender.Body = 0x190;
    sender.Hue  = bodyHue;

  //  sender.AddItem( Hair.CreateByID( hairId, hairHue ) );
  //  sender.AddItem( Beard.CreateByID( beardId, beardHue ) );
    sender.Race = Race.Human;
    sender.Title = "";
    break;
   }
   case 3:  // elf female -> human female
   {
    sender.Body = 0x191;
    sender.Hue  = bodyHue;
   // sender.AddItem( Hair.CreateByID( hairId, hairHue ) );
    sender.Race = Race.Human;
    sender.Title = "";
    break;
   }
  }
 }
}
}


Presently what works is, the proper gump comes up for all 4 types of players. Human Female get gumps for Elf Female and so on.
Elfs get changed to human. BodyValue and Race get set correctly. Humans remain the same. No change at all. As far as hair and beard, I plan to figure out that issues after I get the race to change.

Like I said, Packets and Bitwise functions evade me. Any help please?

ArteGordon- 07-16-2006
try changing this

CODE

byte senderFlags = (byte)(Convert.ToByte(sender.Female) | (Convert.ToByte(sender.Race == Race.Elf ? 1 : 2) << 1));


to this

CODE

byte senderFlags = (byte)(Convert.ToByte(sender.Female) | (Convert.ToByte(sender.Race == Race.Elf ? 1 : 0) << 1));

Haazen- 07-16-2006
Thx This worked and I got the hair and beard working also. I have but one thing let on this script and that is to delete the crystal within the class RaceChange rather than class RaceChangeCrystal. I will figure this out then post this script for others to use. Thanks again. These are my last 2 issues before going active with 2.0. All other custom scripts have been fixed for 2.0