How To ... create race(Tutorial)
Create Race, Function and Gate for them
* If someone know other thing about it to improve code or noticed some errors PM me i will add on the text.
* If other peaople have some tutorial to post here too (i hope numbers will do it) so devs can post-it if they want
Quasi simple, follow the example
MyOwnMobile.cs
[code:1]using System;
using Server;
using Server.Items;
using System.Collections;
using Server.Mobiles;
using Server.Network;
namespace Server.Scripts
{
public enum RaceType
{
None, Human, Elf //contain all race you want
}
public class MyMobile : Mobile
{
private RaceType race; //Create a private RaceType variable it will countain the race of you're character
public MyMobile()
{
PgRace = RaceType.None; //don't forget to init the private variable
}
public MyMobile( Serial serial ) : base( serial )
{
}
[CommandProperty( AccessLevel.GameMaster )]
public RaceType PgRace
{
get {return race;}
set {race = value;}
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
writer.Write((int) race ); // don't forget to save you're characters race
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch ( version )
{
case 0:
{
race = (RaceType)reader.ReadInt(); //neither to load it
break;
}
}
}
}
}[/code:1]
now new character have to be of these new class.
For this open CharacterCreation.cs file, go to line 200, and replace return [code:1]a = new Mobile(); [/code:1]
by
[code:1]a = new MyMobile (); [/code:1]
and add this line in the top of the file
[code:1]using Server.Scripts;[/code:1]
then for give the race some specific function (optional)
CharacterFunction.cs
[code:1]using System;
using Server;
using Server.Network;
namespace Server.Scripts
{
public class RaceFunction
{
public static void Initialize()
{
Server.Commands.Register( "MyCommand", AccessLevel.Player, new CommandEventHandler( MyCommand_OnCommand ) ); //register the function and is access
}
private static void MyCommand_OnCommand( CommandEventArgs e )
{
Mobile somemobile = e.Mobile;
MyMobile from = somemobile as MyMobile; //put somebile in from and it take's MyMobile class form
if ( from != null )
{
if (from.PgRace == RaceType.Human) //check you're character race
{
//Put you're action code here
}else{
from.SendMessage("You can not use it."
}
}
}
}
}[/code:1]
to create a gate race to make him become of a certain race (here it's an Elf)
i make it derived from Item but you can make it derived from another thing (like a BaseRaceGate or else)
ElfGate.cs
[code:1]namespace Server.Scripts
{
public class ElfGate : Item
{
[Constructable]
public ElfGate() : base(0x0F6D)
{
Name = "An Elf Gate";
this.Movable = false;
}
public ElfGate( Serial serial ) : base( serial )
{
}
public override bool OnMoveOver(Mobile from)
{
Mobile somemobile = from;
MyMobile someperso = somemobile as MyMobile;
if ( someperso != null )
{
someperso.InitStats(50, 120, 90); //set the charater's stats
someperso.PgRace = RaceType.Elf; //give him the race of the gate
someperso.SendMessage("You are now an elf"
}
return true;
}
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();
}
}
}[/code:1]
Create Race, Function and Gate for them
* If someone know other thing about it to improve code or noticed some errors PM me i will add on the text.
* If other peaople have some tutorial to post here too (i hope numbers will do it) so devs can post-it if they want
Quasi simple, follow the example
MyOwnMobile.cs
[code:1]using System;
using Server;
using Server.Items;
using System.Collections;
using Server.Mobiles;
using Server.Network;
namespace Server.Scripts
{
public enum RaceType
{
None, Human, Elf //contain all race you want
}
public class MyMobile : Mobile
{
private RaceType race; //Create a private RaceType variable it will countain the race of you're character
public MyMobile()
{
PgRace = RaceType.None; //don't forget to init the private variable
}
public MyMobile( Serial serial ) : base( serial )
{
}
[CommandProperty( AccessLevel.GameMaster )]
public RaceType PgRace
{
get {return race;}
set {race = value;}
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
writer.Write((int) race ); // don't forget to save you're characters race
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch ( version )
{
case 0:
{
race = (RaceType)reader.ReadInt(); //neither to load it
break;
}
}
}
}
}[/code:1]
now new character have to be of these new class.
For this open CharacterCreation.cs file, go to line 200, and replace return [code:1]a = new Mobile(); [/code:1]
by
[code:1]a = new MyMobile (); [/code:1]
and add this line in the top of the file
[code:1]using Server.Scripts;[/code:1]
then for give the race some specific function (optional)
CharacterFunction.cs
[code:1]using System;
using Server;
using Server.Network;
namespace Server.Scripts
{
public class RaceFunction
{
public static void Initialize()
{
Server.Commands.Register( "MyCommand", AccessLevel.Player, new CommandEventHandler( MyCommand_OnCommand ) ); //register the function and is access
}
private static void MyCommand_OnCommand( CommandEventArgs e )
{
Mobile somemobile = e.Mobile;
MyMobile from = somemobile as MyMobile; //put somebile in from and it take's MyMobile class form
if ( from != null )
{
if (from.PgRace == RaceType.Human) //check you're character race
{
//Put you're action code here
}else{
from.SendMessage("You can not use it."
}
}
}
}
}[/code:1]
to create a gate race to make him become of a certain race (here it's an Elf)
i make it derived from Item but you can make it derived from another thing (like a BaseRaceGate or else)
ElfGate.cs
[code:1]namespace Server.Scripts
{
public class ElfGate : Item
{
[Constructable]
public ElfGate() : base(0x0F6D)
{
Name = "An Elf Gate";
this.Movable = false;
}
public ElfGate( Serial serial ) : base( serial )
{
}
public override bool OnMoveOver(Mobile from)
{
Mobile somemobile = from;
MyMobile someperso = somemobile as MyMobile;
if ( someperso != null )
{
someperso.InitStats(50, 120, 90); //set the charater's stats
someperso.PgRace = RaceType.Elf; //give him the race of the gate
someperso.SendMessage("You are now an elf"
}
return true;
}
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();
}
}
}[/code:1]