Go Back   RunUO - Ultima Online Emulation > RunUO > RunUO Post Archive

RunUO Post Archive The Archvie

Reply
 
Thread Tools Display Modes
Old 09-20-2003, 10:07 PM   #1 (permalink)
Forum Expert
 
Join Date: Sep 2002
Posts: 1,267
Send a message via ICQ to Spooky
Default Region Initialization 101

To initialize a region it must be included in a script file for this purpose, you may have noticed that RunUO comes with towns and dungeons already done for you.

If you want to add a town or dungeon you could just add its entry into these already existing files, However this means you need to edit these scripts everytime you update it is far better to put them in there own file to minimise the amount of editing default scripts for an update. (this goes for other script types as well).

First part of this script is the using directives that appear in all c#
[code:1]using System;
using System.Collections;
using Server;
using Server.Mobiles;
using Server.Spells;[/code:1]I am not going to cover the using section of the scripts here if you do not understand this bit there are plenty of C# help sites that explain it.

Next comes the namespace statement for the purpose of regions it will always be[code:1]namespace Server.Regions[/code:1]
Then we move into the nitty gritty section of region initialization, first and foremost comes the class declaration and inheritance statements, you can name the class whatever you like as long as it is unique, although a good rule of thumb is to name it so it is representative of what it is IE dont name it cat if it is a dog. For my example here im calling it example[code:1]public class Example[/code:1]Of course this line of code is incomplete because it isnt a region to make it a region we need it to inherit from one of the region classes, luckily there is only two you need to be concerned about[list]
GuardedRegion
Region[/list:u]
In this case we will make a town that needs guards so we want it to be a guarded region making our class declaration line[code:1]public class Example : GuardedRegion[/code:1]The next section of code is mandatory and wont change no matter what type of region you are making[code:1]public static new void Initialize()[/code:1]within this section of code is where we tell RunUO to use the region we created in regions.xml.
For each custom guarded region you want to add you need either of the following lines of code for guards enabled[code:1]Region.AddRegion( new Example( "Example" ) );[/code:1]for guards disabled[code:1]Region.AddRegion( new GuardedRegion.Disable( new Example( "Example" ) ) );[/code:1]
*Note: the above lines of code assume the region was named Example in the regions.xml file.

Next comes the default constructor for our class in this basic level tutorial we will only do a default constructor and wont go into a detailed explanation of constructors. Because this will be a guarded region we need to include the guard type in the constructor by default there is only two types[list]
WarriorGuard
ArcherGuard[/list:u] For this example we will use WarriorGuards.
[code:1]public Example( string name ) : this( name, typeof( WarriorGuard ) )[/code:1]

And that is all we need to have a complete custom guarded region of course there is a lot more you can do with region a hell of a lot more actually but ill leave that for another higher level disscussion on regions here is the completed example[code:1]using System;
using System.Collections;
using Server;
using Server.Mobiles;
using Server.Spells;

namespace Server.Regions
{
public class Example : GuardedRegion
{
public static new void Initialize()
{
Region.AddRegion( new Example( "Example" ) );
}

public Example( string name ) : this( name, typeof( WarriorGuard ) )
{
}
}
}[/code:1]
Spooky is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5