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!

[RunUO 2.0 RC1] Government (Player City) System 2.0

iamjedi

Wanderer
Government (Player City) System 2.0

Player Government System 2.0!!! (v. 2.0.6b)

Hey folks, first of all this script package was originally wirtten by -RoninGT- for RunUO 1.0. I have taken his package and modified some parts, remove/fixed bugs, added more content, and buffed it up for RunUO 2.0. All of the code found here is either original RunUO scripting, original FS Gavernment System 1.0 by RoninGT, or by yours truly. However, this is now for you. So all support will be found by you, or one of the authors.

In all honesty, this is my first script release, so I'm sure I will forget a lot, edit this post 1 trillion times, and post 65 more releases and fixes, but this is where you start. As far as I can tell, it runs smooth as a whistle. HELP ME FIND BUGS!! :)

Changelog:

Updated July 16, 2006: (v2.0.6b)
*Fixed fresh install bug

Updated July 15, 2006: (v2.0.6)
*Fixed CheckifHouseinCity() bug
*Fixed more out of place tiles
*Implimented the IsGMCity variable *CityManagementStone.DoUpdate()* - see feature notes
*details

Updated July 13, 2006: (v2.0.5)
*City name is now changeable. Also, the regions thereof are fully dynamic. The code will automatically generate a fun name on city placement, which again, is changeable from the stone. (Thanks Avelyn :) )
*Fixed a bug causing overlapable cities (city bounds check not functioning properly)
*Fixed a possible crash involving a null exception in the city stones
*Applies several missing core file mods (Thanks Hanse :) )
*Fixed several small bugs/errors/typos
*Note: These changes encompass many files, including very small fixes in some. It is suggested that you perform a full re-install of the system

Updated July 11, 2006:
*(2.0.4)Fixed redeeding issue after server reset. *citydeed.cs
*(2.0.3)Updated region loading @ server load. (prev. versions did not assign the region to the appropriate city stone) **AccountPrompt.cs for quick install
*(2.0.2)Fixed serialization bug in PlayerMobile.cs..... AGAIN!!
*(2.0.1)Updated Rectangle2D to 3D error..


Basic feature overview:
(aside from 1.0 features) ** to view version 1.0 by Ronin, click here. His page contains useful information on the core of the system
  • More structures such as blacksmiths added
  • City civic structures spawn NPC's and guildmasters for added town functionality
  • City Parks and Gardens spawn abmient creatures/npc's for cozy town effect
  • City Guards working properly
  • GM Cities - Rank 6, rank 3 city bounds, 500 lockdowns (every update, customizable)
  • Several structure placement bugs addressed
  • Overall stability addressed
  • Written for RunUO 2.0 RC1
  • PLAYER MUST IMMEDIATELY enter city name, and it can not change.
  • Region updates will take affect upon next server restart (due to 2.0 region system changes)
  • Many more that I cen't remember right now because it's late

Installation
  • Extract the 'new' folder somwhere to your custom script location
  • Place all the other files in the directory into your edited folder, EXCEPT FOR PLAYERMOBILE.CS
  • note: be sure to backup and remove your original scripts of these.
  • Follow the next steps for editing your playermobile file.

I suggest self-editing the PlayerMobile.cs file using my instructions, because it is often the most modded file in your scripts. (However, if you have an unedited PlayerMobile, it is MUCH easier to just replace it) To finish the installation, open your PlayerMobile.cs file and locate:

Code:
public class PlayerMobile : Mobile, IHonorTarget
	{
		private class CountAndTimeStamp
		{
			private int m_Count;
			private DateTime m_Stamp;

			public CountAndTimeStamp()
			{
			}

			public DateTime TimeStamp { get{ return m_Stamp; } }
			public int Count 
			{ 
				get { return m_Count; } 
				set	{ m_Count = value; m_Stamp = DateTime.Now; } 
			}
		}

		private DesignContext m_DesignContext;

		private NpcGuild m_NpcGuild;
		private DateTime m_NpcGuildJoinTime;
		private TimeSpan m_NpcGuildGameTime;
		private PlayerFlag m_Flags;
		private int m_StepsTaken;
		private int m_Profession;

and place the following immediately after...

Code:
// Start FSGov Edits

		private CityManagementStone m_City;
		private string m_CityTitle;
		private bool m_ShowCityTitle;
		private bool m_OwesBackTaxes;
		private int m_BackTaxesAmount;

		[CommandProperty( AccessLevel.GameMaster )]
		public CityManagementStone City
		{
			get{ return m_City; }
			set{ m_City = value; InvalidateProperties(); }
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public string CityTitle
		{
			get{ return m_CityTitle; }
			set{ m_CityTitle = value; InvalidateProperties(); }
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public bool ShowCityTitle
		{
			get{ return m_ShowCityTitle; }
			set{ m_ShowCityTitle = value; InvalidateProperties(); }
		}

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

		[CommandProperty( AccessLevel.GameMaster )]
		public int BackTaxesAmount
		{
			get{ return m_BackTaxesAmount; }
			set{ m_BackTaxesAmount = value; }
		}

		//End FSGov Edits

Then scroll WAY down until you find this code...

Code:
public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();

			switch ( version )
			{

And this is where it may be more tricky... add this:

Code:
//// Governments System edits!!!/////
                    case 26: /////////////this should be 1 higher than the next ## in the list
                    {
                        m_City = (CityManagementStone)reader.ReadItem();
                        m_CityTitle = reader.ReadString();
                        m_ShowCityTitle = reader.ReadBool();
                        m_OwesBackTaxes = reader.ReadBool();
                        m_BackTaxesAmount = reader.ReadInt();
                        goto case 25; /////////// same as next ##
                    }
//////end edits

Notice the comments on the numbering. my previous ## was 25, hence my coding.
One more part, the serializer: find this:

Code:
base.Serialize( writer );
			
            writer.Write((int)25);

And then add this: (make sure this ## matches your deserializer!!!)

Code:
///////////////////Government Edits//////////////////////
            writer.Write((int)26); // version MUST MATCH YOUR DESERIALIZER
            writer.Write(m_City);

            writer.Write(m_CityTitle);

            writer.Write(m_ShowCityTitle);

            writer.Write(m_OwesBackTaxes);

            writer.Write(m_BackTaxesAmount);
            ////////////////////////end////////////////////////

note: with this update, I have included my PlayerMobile.cs file, in the case that you don't have other edits there and this hands-on edit is over your head.

And that should do it. If you have any issues, please let me know. If you have any Ideas, please make them happen. Thanks, and have fun.
 

Attachments

  • Government 2.0.6b.zip
    311.4 KB · Views: 395
I did have 1 error:

RunUO - [www.runuo.com] Version 2.0, Build 2357.32527
Core: Running on .NET Framework Version 2.0.50727
Core: Optimizing for 2 processors
Scripts: Compiling C# scripts...failed (1 errors)
+ Customs/Government 2.0/PlayerGovernmentSystem.cs:
CS0184: Line 197: The given expression is never of the provided ('Server.Reg
ions.GuardedRegion') type
CS0184: Line 197: The given expression is never of the provided ('Server.Reg
ions.PlayerCityRegion') type
CS0162: Line 198: Unreachable code detected
Errors:
+ Customs/Government 2.0/Regions/PlayerCityRegion.cs:
CS1502: Line 157: The best overloaded method match for 'Server.Regions.Guard
edRegion.GuardedRegion(string, Server.Map, int, params Server.Rectangle3D[])' ha
s some invalid arguments
CS1503: Line 157: Argument '4': cannot convert from 'Server.Rectangle2D' to
'Server.Rectangle3D[]'
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.
 

iamjedi

Wanderer
Oo that's right... I found that in the default GuardedRegion code. There was no method with Rectange2D, only 3D... so I added one. Updating.... done. And greetings from the Treasure Coast!!

note: if by some chance your GuardedRegion is edited... juast add this code near a similar method..
Code:
public GuardedRegion(string name, Map map, int priority, params Rectangle2D[] area) : base(name, map, priority, area)
        {
            m_GuardType = DefaultGuardType;
        }
 

iamjedi

Wanderer
Oh, either one should work. I would just redownload and only add teh GuardedRegion.cs file. (remembering to backup and remove the old version) That is, unless you have already edited your GuardedRegion.cs file that is. Good luck. Go find some bugs!!! :)
 

RoninGT

Sorceror
bravo! Good work. I had a copy i was working on but it got put back due to other projects. Nice work.

Ronin
 

iamjedi

Wanderer
Found a bug myself... forgot to add PlayerMobile serialize/deserialize of city variables!!!! Told you it was late. :) Updating now... DONE! Enjoy!
 

iamjedi

Wanderer
Fixed another one in 2.0.3 ----- Upon server restart, the city regions were not linked to their city. (the stone) This error was in the loading, the AccountPrompt.cs file.
 

iamjedi

Wanderer
Yay!! Fixed the redeeding issue... system appears 100% by all my tests (though I know it's not). v2.0.4 current....

*replace CityDeed.cs for quick install if you have 2.0.3
 

zetamine

Sorceror
awesome

i'm at work right now so i won't get a chance to test it out til after 5 EST, but looks great. I used to run a fairly large pvp server and this might be the thing to get me back into RunUO. Thanks for your contribution, iamjedi, and thanks to RoninGT for starting this script.
 

iamjedi

Wanderer
thanks

Be sure to let me know how it goes. I don't have an active server currently, so it makes it more difficult to properly test it. I know it's always been one of my favorite systems, so I'm excited to iron it out.
 

iamjedi

Wanderer
next...

Note: since no errors have immediately popped up, I've address a couple of small "issues" and am waiting to release another patch until theres a bit more content. However, one small bug that I have worked around (inspiring a new feature idea) causes a server crash when the new mayor double clicks the city management stone WITHOUT having named the city yet. An easy fix, the name simply needed to be checked in the OnDoubleClick() method, but here's what I have in currently, which I find fun..

Code:
if (this.CityName == null)
            {
                // If this is first use and the city has not been named, a name must be ASSIGNED! (avoiding server crash)
                string[] prefixes = { "Mount ", "Port ", "Lake ", "", "", "", "", "", "", "", "", "", "", "" };
                string[] suffixes = { "ville", "shire", "ston", "sburg", "haven", " Meadow", " Hills", "brook", "urbia", " Valley", "" };
                Random i = new Random();

                this.CityName = prefixes[(int)i.Next(14)] + from.Name + suffixes[(int)i.Next(11)];

                from.SendMessage(34, "Your city's name has been automatically set to {0}.", this.CityName);
               
                //done
            }

Basically, when double-clicked, if the city stone has no name, it creates a name by combining random prefixes and suffixes to the players name. :D My favorite I got in testing so far is "Port Adminurbia". (btw, there is more to the fix then this, you must address the region initializtion differently than in the 2.0.4, but the next patch will be posted soon)

Any thoughts before I post?
 

Avelyn

Sorceror
iamjedi said:
Note: since no errors have immediately popped up, I've address a couple of small "issues" and am waiting to release another patch until theres a bit more content. However, one small bug that I have worked around (inspiring a new feature idea) causes a server crash when the new mayor double clicks the city management stone WITHOUT having named the city yet. An easy fix, the name simply needed to be checked in the OnDoubleClick() method, but here's what I have in currently, which I find fun..

Code:
if (this.CityName == null)
            {
                // If this is first use and the city has not been named, a name must be ASSIGNED! (avoiding server crash)
                string[] prefixes = { "Mount ", "Port ", "Lake ", "", "", "", "", "", "", "", "", "", "", "" };
                string[] suffixes = { "ville", "shire", "ston", "sburg", "haven", " Meadow", " Hills", "brook", "urbia", " Valley", "" };
                Random i = new Random();

                this.CityName = prefixes[(int)i.Next(14)] + from.Name + suffixes[(int)i.Next(11)];

                from.SendMessage(34, "Your city's name has been automatically set to {0}.", this.CityName);
               
                //done
            }

Basically, when double-clicked, if the city stone has no name, it creates a name by combining random prefixes and suffixes to the players name. :D My favorite I got in testing so far is "Port Adminurbia". (btw, there is more to the fix then this, you must address the region initializtion differently than in the 2.0.4, but the next patch will be posted soon)

Any thoughts before I post?


i think if you dont give them the option of renaming it even if they screw up and not put a name it they will not be happy. Seems like there will be a few versions of this system out.. should be kind of neat.
 

iamjedi

Wanderer
I'm planning on changing the Non-renamability in my next patching of it, because the reason I originally removed it was because of difficulties with the 2.0 region system. However, I have found a simple workaround, but it is not implimented publicly yet. Although, when I change that, I will want to disable the immediate naming of the cities, and have it generate one of these instead. They would then after be able to change the name from the stone.

The only issue with this is the same as the city bounds issue. You CAN NOT change the regions while the server is running. Information therein is READ-ONLY. Therefore, the data is currently changed in the stone. Every time the server loads, it locates every management stone in the world and "creates the city" based on the data within. So the same will go for city name. For now, I think those are the only 2 pertinent city properties pertaining to the regions, and therefore, the only stats that require a server restart to update. (I prefer auto-restart)
 

iamjedi

Wanderer
Hey, thanks! Will do!

Actually, I know first off making the name/area changeable can be as simple as a core edit of the region.cs file, and adding a set{} property, instead of just get{}. But I don't want to modify my core per say. Hopefully he has a different method.
 

Avelyn

Sorceror
iamjedi said:
I'm planning on changing the Non-renamability in my next patching of it, because the reason I originally removed it was because of difficulties with the 2.0 region system. However, I have found a simple workaround, but it is not implimented publicly yet. Although, when I change that, I will want to disable the immediate naming of the cities, and have it generate one of these instead. They would then after be able to change the name from the stone.

The only issue with this is the same as the city bounds issue. You CAN NOT change the regions while the server is running. Information therein is READ-ONLY. Therefore, the data is currently changed in the stone. Every time the server loads, it locates every management stone in the world and "creates the city" based on the data within. So the same will go for city name. For now, I think those are the only 2 pertinent city properties pertaining to the regions, and therefore, the only stats that require a server restart to update. (I prefer auto-restart)


That is incorrect. You can certainly do the same thing you do at server load actual time in a script. You can rewrite that UpdateRegion method you commented out to do it. All you need to do is calculate the new area, Unregister the region and then register it with the new area calcuations. I have it running on my version of this system flawlessly for weeks. Completely dynamic. Also, you do not have to have the city name have anythign to do with the region name. Write a method to randomly pick region names. Then you can leave the old code in to allow them to do whatever they want with the city name.
 
Top