RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

How To ... create race(Tutorial)

Pheyte

Wanderer
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]
 

sTo0z

Wanderer
This post is so depressing...

I'm a computer scientist in college and I can't follow this completely...

Damn I suck. :\
 
A

Al_hurtcha

Guest
Its ok :p

Your not alone, i haven't been able to take the fifteen or so hours of reading required to get to know the basics of C#. I have zero interest in knowing how to do anything else in C#... ever... in my life... until I die... And there is no clear document that tells you what does what in the RunUO scripts.

So I just breeze past the info like whats posted above, because to me its all a bunch of hooey.

have fun :)
 

Pheyte

Wanderer
Could you PM me what you don't understand ? i'll edit after to write more clearly the explanation.

There's a point to know too: you can not develop for runuo if you don't understand c#
thats's why there's a post about c# learning links ;)
 

David

Moderate
In my best Gomer Pyle impersonation; Thank you Thank you Thank you. I have had my epiphany and have written my first three successful and actually useful scripts tonight! I wish everyone tried to comment their code; I found exactly what I was missing. (Well ok, two of them were bastardized versions of your scripts, but at this point I’m good with it.)


:D Thanks again,
David
 

Phantom

Knight
Al_hurtcha said:
Its ok :p

Your not alone, i haven't been able to take the fifteen or so hours of reading required to get to know the basics of C#. I have zero interest in knowing how to do anything else in C#... ever... in my life... until I die... And there is no clear document that tells you what does what in the RunUO scripts.

So I just breeze past the info like whats posted above, because to me its all a bunch of hooey.

have fun :)

If you don't know the basics, no amount of "guide" on just RunUO scripts will make sense. You almost have to know a basic understaned how it works. then you have the knowlege to look at a script and understand why it works. Maybe now how really but why, is all you need to make custom anything.
 

Gustavo

Wanderer
Thanks Pheyte :)

I have a question..
If i want to make a stone with a gump for them to choose the race the first time they log in, how would i say this:

[code:1]switch ( race )
{
case 0:
{
if (e.PgRace == RaceType.None)
{
if (e.PgRace == RaceType.Elf)
{
from.SendMessage("You are already an Elf.")
}
else
{
e.PgRace = RaceType.Elf // Would this be alrite?? I mean would this stay on the next time they login?
}
else
{
from.SendMessage("You already have a race.")
}
break;
}
}
[/code:1]

thanks in advance,
Gustavo
 

Pheyte

Wanderer
happy that it's usefull :D


It depends Gustavo, what is "e" for you ? if it's a MyMobile class it's ok, else you have to make it a MyMobile class
 
L

Lost User

Guest
Just a note "Using Server.Scripts;" should be "using Server.Scripts;"

Dont want any complaints about things not working =P

With that said... this is a great script. I can see that it is going to get put to good use!

Pheyte... when I have finished making all the races I want, and tweaking the scripts to make the races do things, would you mind if I add all the scripts to a zip file for everyone just to "Plug & Play" ??

All credit will go to you without saying *smiles*

- Dark Konoko
 

Pheyte

Wanderer
Thanks for the "error" ;)

Well i haven't got any objection to do that, it's going to be good if it's usefull.

the code is to be re-use after all ;)

If you have question or want help my icq is ... somewhere on the post lol
 

thema

Wanderer
Are they supposed to vanish over time?

I've compiled the scripts succesfully and made 13 gates for 13 races. Only by the time i've placed the last one the fist one has vanished.

Is this normal?
Can I stop it from happenening?
What am I doing wrong?

I'm using Beta 14 with a UORiced T2A

Thema



______________


Member of the society for the preservation of signature Virii.

Hi! I'm a signature virus. Copy me into your signature to help me spread.
Hi, Im a signature virus removal tool. Copy me into your signature to help fight the signature virus
Hi! I'm a signature virus. Copy me into your signature to help me spread.
Hi! I'm a signature virus. Copy me into your signature to help me spread.


OMG We've been infiltrated
 

krrios

Administrator
You'll probably want to make the gates unmovable, or override Decays:

[code:1]Movable = false;[/code:1]

[code:1]public override bool Decays{ get{ return false; } }[/code:1]
 

thema

Wanderer
Hmmm...

It seems to have worked

Thanks.

Here's a small mod I made to the gates so that they only work once, and are non-decaying at build time.

[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 )
{
if ( someperso.PgRace == RaceType.None )
{
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");
}
else someperso.SendMessage("Be satisfied with your race!");
}
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]

_Thema_
 

thema

Wanderer
Hehe No worries.

I hope you don't mind me messing, but I've been told I have to learn this. and yours is the first script I could almost understand.

Anyway. I married the racegate to a teleporter and they had a baby....

Can anyone tell me how I can inherit a teleporter class? It would have been better methinks then writing this lot out.

[code:1]
using System;
using Server;
using Server.Items;

namespace Server.Scripts
{
public class DarkElfGate : Item
{
private bool m_Active, m_Creatures;
private Point3D m_PointDest;
private Map m_MapDest;

[CommandProperty( AccessLevel.GameMaster )]
public bool Active
{
get { return m_Active; }
set { m_Active = value; }
}

[CommandProperty( AccessLevel.GameMaster )]
public Point3D PointDest
{
get { return m_PointDest; }
set { m_PointDest = value; }
}

[CommandProperty( AccessLevel.GameMaster )]
public Map MapDest
{
get { return m_MapDest; }
set { m_MapDest = value; }
}

[CommandProperty( AccessLevel.GameMaster )]
public bool Creatures
{
get { return m_Creatures; }
set { m_Creatures = value; }
}

[Constructable]
public DarkElfGate() : this( new Point3D( 0, 0, 0 ), null, false )
{
}

[Constructable]
public DarkElfGate( Point3D pointDest, Map mapDest ) : this( pointDest, mapDest, false )
{
}

[Constructable]
public DarkElfGate( Point3D pointDest, Map mapDest, bool creatures ) : base( 0x0F6D)
{
Visible = true;
Movable = false;
Hue = 0x048e; // This picks funky colors for the gate. you might prefer to comment this out.
Light = LightType.Circle300;
Name = "DarkElfGate";

m_Active = true;
m_PointDest = new Point3D( 1100, 1280, 5 ); // CHANGE THIS!!!!!!!!!!
m_MapDest = mapDest;
m_Creatures = creatures;
}

public override void OnSingleClick( Mobile from )
{
LabelTo( from, "Dark Elf Gate" ); // DarkElfGate

if ( m_Active )
{
if ( m_MapDest != null && m_PointDest != Point3D.Zero )
LabelTo( from, "{0} [{1}]", m_PointDest, m_MapDest );
else if ( m_MapDest != null )
LabelTo( from, "[{0}]", m_MapDest );
else if ( m_PointDest != Point3D.Zero )
LabelTo( from, m_PointDest.ToString() );
}
else
{
LabelTo( from, "(inactive)" );
}
}

public override bool OnMoveOver( Mobile m )
{
Mobile somemobile = m;

MyMobile someperso = somemobile as MyMobile;

if ( someperso != null )
{
if ( someperso.PgRace == RaceType.None )
{
someperso.Hue = 0x037a; // Comment out this line if you don't want new skin color.

// This next bit changes the stats according to race, and Character choice.
switch ( someperso.Str )
{
case 95:
{
someperso.InitStats(75, 115, 40); //set the Fighter's stats
break;
}
case 85:
{
someperso.InitStats(65, 40, 95); //set the Mage's stats
break;
}
case 60:
{
someperso.InitStats(40, 40, 40); //set the Blacksmith's stats
break;
}
}
someperso.PgRace = RaceType.DarkElf; //give him the race of the gate
someperso.SendMessage("You are now a Dark Elf!");
}
else someperso.SendMessage("Be satisfied with your race!");
}

if ( m_Active )
{
if ( !m_Creatures && !m.Player )
return true;

Map map = m_MapDest;

if ( map == null )
map = m.Map;

Point3D p = m_PointDest;

if ( p == Point3D.Zero )
p = m.Location;

Server.Mobiles.BaseCreature.TeleportPets( m, p, map );

if ( m_MapDest != null )
m.Map = m_MapDest;

if ( m_PointDest != Point3D.Zero )
m.Location = m_PointDest;

return false;
}

return true;
}

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

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

writer.Write( (int) 1 ); // version

writer.Write( m_Creatures );

writer.Write( m_Active );
writer.Write( m_PointDest );
writer.Write( m_MapDest );
}

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

int version = reader.ReadInt();

switch ( version )
{
case 1:
{
m_Creatures = reader.ReadBool();

goto case 0;
}
case 0:
{
m_Active = reader.ReadBool();
m_PointDest = reader.ReadPoint3D();
m_MapDest = reader.ReadMap();

break;
}
}
}
}
}
[/code:1]

I made a place they couldn't escape from then when they pick a race they can go to the point you preset.

Watch the co-ords I left in they may not work with your map.

I fixed the bug, and now it also changes the skin color so you can make grey Dark Elves, and Green orcs etc.

A thought I had was to preset the gates so the characters could teleport to a start location special to each race.


Thema
 

thema

Wanderer
Okay here's a little bug.

It's only a minor thing, but some of you might want to correct it.

One of my players asked a simple question that I should have thought of before :)
How do we tell our race?

Well here's how!
Just add this to MyMobile.cs around line 34

[code:1]
public override void OnSingleClick( Mobile from )
{
from.LocalOverheadMessage( MessageType.Regular, 0, false, String.Format( "{0} : {1}", Name, PgRace ) );
}

[/code:1]


Now a single click will get the player's Name and raceType.

Actually, this method sux. If anyone can tell me how to add it to the player's PaperDoll I would be grateful.

Meanwhile I shall go and see if I can answer my own problem..


Thema
 

David

Moderate
Here is my Half-Elf race gate. You will notice I also have added an age to my mobile. The player chooses that with an 'age rune' when they start. The title is set with this line: from.Title = "an adult Half-Elf"; I was afraid that implementing fame and karma would mess that up, but it does not seem to have done so. However I have not extensively tested the titles yet. I am still lacking skin hue, I plan to add that one of these days.

When a player approaches, or if you single-click, or look at the paperdoll, you see the name age and race. I intend to not show trade or class or fame or karma as that is all information that should be learned through discussions between characters.

Feel free to hack away at this. :)

[code:1]
namespace Server.Misc.Custom
{
public class HalfElfGate : Item
{
private string thisMessage;
private Point3D newLocation;
private static int s = 0, d = 0, i = 0;

[Constructable]
public HalfElfGate() : base(0x0F6D)
{
Movable = false;
Light = LightType.Circle300;
Name = "A Half-Elf Race Gate";
}

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

public override bool OnMoveOver(Mobile from)
{
Mobile somemobile = from;
OwnMobile thisChar = somemobile as OwnMobile;

if ( thisChar != null )
{
thisChar.Race = RaceType.HalfElf; // give him the race of the gate
SetTitle(thisChar); // Set the Title and age modifiers
thisChar.InitStats(25 + s, 25 + d, 50 + i); // set the charater's stats
thisChar.MaxSTR = 90 + s/2;
thisChar.MaxINT = 95 + i/2;
thisChar.MaxDEX = 100 + d/2;

// Half-Elves choose their home city
// This is handled in a random fashion for now....
switch ( Utility.Random( 2 ) )
{
case 0:
thisChar.HomeCity = HomeCityType.Vesper;
newLocation = new Point3D( 2978, 879, 10 ); //Vesper, Vesper Youth Hostel
thisMessage = "you explore your Human heritage in Vesper";
break;
default: case 1:
thisChar.HomeCity = HomeCityType.Yew;
newLocation = new Point3D( 635, 859, 0 ); //Yew, Empath Abby
thisMessage = "you study your Elven heritage in Yew";
break;
}

// set the character's home point same as city
thisChar.HomePoint_x = newLocation.X;
thisChar.HomePoint_y = newLocation.Y;
thisChar.HomePoint_z = newLocation.Z;
thisChar.HomeMap = Map.Felucca;
from.Map = Map.Felucca;
from.Hidden = true;
from.Location = newLocation;
from.PlaySound( 0x1FE );
from.SendMessage("Welcome, Half-Elf");
from.SendMessage( thisMessage );
}
return false;
}

private static void SetTitle( OwnMobile from )
{
switch (from.Age)
{
case AgeType.unknown:
from.Title = "a Half-Elf";
s = 0;
i = 0;
d = 0;
break;
case AgeType.adult:
from.Title = "an adult Half-Elf";
s = 0;
i = 0;
d = 0;
break;
case AgeType.child:
from.Title = "a Half-Elf child";
s = 0;
i = -2;
d = 2;
break;
case AgeType.young:
from.Title = "a young Half-Elf";
s = 2;
i = -2;
d = 0;
break;
case AgeType.elder:
from.Title = "an elder Half-Elf";
s = 0;
i = 2;
d = -2;
break;
case AgeType.ancient:
from.Title = "an ancient Half-Elf";
switch ( Utility.Random( 10 ) )
{
case 0: //10% chance
s = -3;
i = 3;
d = 0;
break;
case 1: //10% chance
s = -1;
i = 1;
d = 0;
break;
default: //80% chance
s = -2;
i = 2;
d = 0;
break;
}
break;
}
}

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]

enjoy!
David
 

thema

Wanderer
Does it teleport?

I'm using the Title bits.
I have two questions.

1. Will the Title field be overwritten later by advancements in character status. IE: Promotion to Lord or something?


2. I notice that you used this bit in there:

[code:1]
newLocation = new Point3D( 2978, 879, 10 ); //Vesper, Vesper Youth Hostel
thisMessage = "you explore your Human heritage in Vesper";
break;
default: case 1:
thisChar.HomeCity = HomeCityType.Yew;
newLocation = new Point3D( 635, 859, 0 ); //Yew, Empath Abby
thisMessage = "you study your Elven heritage in Yew";
break;
[/code:1]

Does this make it a teleporter too?

Thema
 

David

Moderate
1. Not sure. That is what I was refering to when I said it was not throughly tested yet. There is a Titles.cs under Scripts\Misc, odds are you could just remove that file and not have to worry about it.

2. Yes. I created a place I call the "Hall of Races" in an unused bit of dungon. New characters start in that hall. The Race Gates are how they get from there into the world, and each race starts out in a different city.

3. I like your avatar ;)
 
Top