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!

[1.0 & 2.0 RC1] NPC Control command

Quick_silver

Sorceror
[1.0 & 2.0 RC1] NPC Control command

I have a new release of the Control command fpr the 2.0 RC1.
I hade made some Bugfixes but not realy tested it on the 2.0 Server. So i will be happy for any bug report ;)

Current version: 2.0.1

Changes:
2.0.1:
- Skills will be saved correct
2.0.0:
- Compatible with RunUO 2.0 RC1
1.0.1:
- Added "private static object Construct(...)" to "class ControlCommand"
- Following command arguments added: NoStats, NoSkills, NoItems

.Control -> Target mobile
To takeover the Mobile and get a "Control Item" into your Backpack.
Doubleclick, drop or delete the item to get back your own body.

At .control you get all items from the mobile. Only newbed and blessed items never move.
Also items from PlayerVendors never move.

Most of the comments and standart messegaes are in german. English messages are commented in the sourcecode, only replace them if needed.

Here is the Link to the RunUO 1.0 version of this Script:
http://www.runuo.com/forums/custom-script-release-archive/68186-control-control-npcs.html
 

Attachments

  • Control.cs
    18.7 KB · Views: 268

Liacs

Sorceror
Neat script. Little bug though: if you change into the NPC all skills he doesn't have are set to 0 and when you change back you don't get the old skill values back for those! Just for the ones where the NPC has values...

Thanks anyways for the idea. I am going to use it!

Lia
 

qwerty84

Sorceror
Code:
Server Crash Report
===================
RunUO Version 2.0, Build 2710.12842
Operating System: Microsoft Windows NT 5.1.2600 Service Pack 2
.NET Framework: 2.0.50727.832
Time: 30/07/2007 15.20.20
Mobiles: 2961
Items: 103479
Exception:
System.NullReferenceException: Riferimento a un oggetto non impostato su un'istanza di oggetto.
   in Server.Items.Glasses.CanEquip(Mobile m) in c:\Documents and Settings\Maderick\Desktop\RunUO\Scripts\Mondain's Legacy\Items\Armor\Glasses.cs:riga 37
   in Server.Mobile.EquipItem(Item item)
   in Server.Commands.ControlCommand.MoveEquip(Mobile from, Mobile to, Boolean fromBackpack) in c:\Documents and Settings\Maderick\Desktop\RunUO\Scripts\Custom\Control.cs:riga 372
   in Server.Commands.ControlCommand.StartControl(Mobile from, Mobile target, Boolean stats, Boolean skills, Boolean items) in c:\Documents and Settings\Maderick\Desktop\RunUO\Scripts\Custom\Control.cs:riga 219
   in Server.Commands.ControlCommand.DoControl(Mobile from, Object targeted, Boolean stats, Boolean skills, Boolean items) in c:\Documents and Settings\Maderick\Desktop\RunUO\Scripts\Custom\Control.cs:riga 190
   in Server.Commands.ControlCommand.InternalTarget.OnTarget(Mobile from, Object targeted) in c:\Documents and Settings\Maderick\Desktop\RunUO\Scripts\Custom\Control.cs:riga 130
   in Server.Targeting.Target.Invoke(Mobile from, Object targeted)
   in Server.Network.PacketHandlers.TargetResponse(NetState state, PacketReader pvSrc)
   in Server.Network.MessagePump.HandleReceive(NetState ns)
   in Server.Network.MessagePump.Slice()
   in Server.Core.Main(String[] args)
Clients:
- Count: 1
+ XXX.XXX.X.XXX: (account = XXXXXX) (mobile = 0x1 'Arthur')

:)
 

Quick_silver

Sorceror
Some more infos would be nice ;) For example what items did you wear while using the command? Custom items? Than the code of the item would be helpfull.

Edit: I found the Script glasses.cs in the ML package. I will test it an try to fix the bug.
An try {} catch() {} maybe be a good workaround untill I found a better way ;)
 

Mideon

Page
Man I've had so many problems finding a decent possess script. I'm definantly going to check this out tonight! I'll try to make some suggestions if I think of them, thanks for this submission, I totally musta missed it when it was posted.
 

Quick_silver

Sorceror
No, thats not possible. I never tought about it. Sounds like a nice idea, but I think it need much more modifications to the Player Mobile
 

Sergeant Bob

Sorceror
is the file corrupt or is there something wrong with me winace? its just a gobildygook file with no extention. i had this same problem with one other file on RUNUO.
:(
 

Siesna

Sorceror
Bump.

What they said. The zip file is corrupted for some reason. I'd really like to use this script, so if the author could fix the link, or if someone has a mirror, pretty pretty please upload it?

EDIT: Error message from WinRar: C:\Control_2_0_1.zip: The archive is either in unknown format or damaged
 

Siesna

Sorceror
Errr... Sorry for the double post, but my server crashes if I try to speak after possessing. The actual possession works fine, I can walk, too, but not speak.
Code:
Server Crash Report
===================

RunUO Version 2.0, Build 2959.20979
Operating System: Microsoft Windows NT 5.1.2600 Service Pack 3
.NET Framework: 2.0.50727.1433
Time: 9/15/2008 2:26:45 AM
Mobiles: 4403
Items: 125217
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Khazman.Logging.SpeechLogging.EventSink_Speech(SpeechEventArgs e)
   at Server.SpeechEventHandler.Invoke(SpeechEventArgs e)
   at Server.EventSink.InvokeSpeech(SpeechEventArgs e)
   at Server.Mobile.DoSpeech(String text, Int32[] keywords, MessageType type, Int32 hue)
   at Server.Mobiles.PlayerMobile.DoSpeech(String text, Int32[] keywords, MessageType type, Int32 hue)
   at Server.Network.PacketHandlers.UnicodeSpeech(NetState state, PacketReader pvSrc)
   at Server.Network.MessagePump.HandleReceive(NetState ns)
   at Server.Network.MessagePump.Slice()
   at Server.Core.Main(String[] args)
 

Quick_silver

Sorceror
Code:
Khazman.Logging.SpeechLogging.EventSink_Speech(SpeechEventArgs e)

Somewhere in the Khazman script the speech event has a null reference.
To help you, I need your Khazman.cs (or the *.cs with "class Khazman". I can't find it in the default scripts.
Or did the crash happens on all mobiles?

Edit:
Woops Khazman is a namespace, so I need you scripts in the namepsace Khazman.* to help you.
 

Siesna

Sorceror
Its the world speech logging script that's causing the problem. I tried removing it, and I can speak while controlled no problem.

A link to the script's thread: http://www.runuo.com/forums/custom-script-releases/78696-world-speech-logging-2-0-release.html

And the script itself:

Code:
using System;
using System.Diagnostics;
using System.IO;

using Server;
using Server.Accounting;
using Server.Commands;
using Server.Mobiles;
using Server.Network;

namespace Khazman.Logging {
	public class SpeechLogging {
		private const bool Enabled = true;
		private static bool ConsoleEnabled = true;

		private static StreamWriter writer;
		private static string LogPath = Path.Combine( "Logs\\Speech", String.Format( "{0}.log", DateTime.Now.ToLongDateString() ) );

		public static void Initialize() {
			if( Enabled ) {
				Console.Write( "SpeechLogging: Initializing..." );
				Stopwatch sw = new Stopwatch();
				sw.Start();

				EventSink.Speech += new SpeechEventHandler( EventSink_Speech );

				if( !Directory.Exists( "Logs" ) )
					Directory.CreateDirectory( "Logs" );

				string directory = "Logs\\Speech";

				if( !Directory.Exists( directory ) )
					Directory.CreateDirectory( directory );

				try {
					writer = new StreamWriter( LogPath, true );
					writer.AutoFlush = true;

					writer.WriteLine( "####################################" );
					writer.WriteLine( "Logging started on {0}", DateTime.Now );
					writer.WriteLine();

					writer.Close();

					Console.WriteLine( "done ({0:F2} seconds)", (sw.ElapsedMilliseconds / 1000) );
				}
				catch( Exception e ) {
					Console.WriteLine( "failed:\n{0}", e );
				}
				finally {
					sw.Stop();
				}

				CommandSystem.Register( "ConsoleListen", AccessLevel.Administrator, new CommandEventHandler( ConsoleListen_OnCommand ) );
			} else
				Console.WriteLine( "SpeechLogging: disabled." );
		}

		public static object Format( object o ) {
			if( o is Mobile ) {
				Mobile m = (Mobile)o;

				if( m.Account == null )
					return String.Format( "{0} (no account)", m );
				else
					return String.Format( "{0} ('{1}')", m, ((Account)m.Account).Username );
			} else if( o is Item ) {
				Item item = (Item)o;

				return String.Format( "0x{0:X} ({1})", item.Serial.Value, item.GetType().Name );
			}

			return o;
		}

		public static void WriteDroppedLog( Mobile from, string format, params object[] args ) {
			WriteDroppedLog( from, String.Format( format, args ) );
		}

		public static void WriteDroppedLog( Mobile from, string text ) {
			try {
				using( StreamWriter w = new StreamWriter( @"Logs\DroppedItems.log", true ) ) {
					w.WriteLine( "{0}: {1}: {2}", DateTime.Now, from.NetState, text );
					w.Close();
				}
			}
			catch { }
		}

		public static void WriteLine( Mobile from, string format, params object[] args ) {
			WriteLine( from, String.Format( format, args ) );
		}

		public static void WriteLine( Mobile from, string text ) {
			if( !Enabled )
				return;

			try {
				writer = new StreamWriter( LogPath, true );
				writer.AutoFlush = true;

				writer.WriteLine( "{0}: {1}: {2}", DateTime.Now, from.NetState, text );

				writer.Close();

				string path = Core.BaseDirectory;
				string name = (((Account)from.Account) == null ? from.RawName : ((Account)from.Account).Username);

				AppendPath( ref path, "Logs" );
				AppendPath( ref path, "Speech" );
				AppendPath( ref path, from.AccessLevel.ToString() );
				path = Path.Combine( path, String.Format( "{0}.log", name ) );

				using( StreamWriter sw = new StreamWriter( path, true ) ) {
					sw.WriteLine( "{0}: {1}: {2}", DateTime.Now, from.NetState, text );
					sw.Close();
				}
			}
			catch { }
		}

		private static char[] m_NotSafe = new char[] { '\\', '/', ':', '<', '>', '|', '{', '}' };

		public static void AppendPath( ref string path, string toAppend ) {
			path = Path.Combine( path, toAppend );

			if( !Directory.Exists( path ) )
				Directory.CreateDirectory( path );
		}

		public static string Safe( string ip ) {
			if( ip == null )
				return "null";

			ip = ip.Trim();

			if( ip.Length == 0 )
				return "empty";

			bool isSafe = true;

			for( int i = 0; isSafe && i < m_NotSafe.Length; ++i )
				isSafe = (ip.IndexOf( m_NotSafe[i] ) == -1);

			if( isSafe )
				return ip;

			System.Text.StringBuilder sb = new System.Text.StringBuilder( ip );

			for( int i = 0; i < m_NotSafe.Length; ++i )
				sb.Replace( m_NotSafe[i], '_' );

			return sb.ToString();
		}

		public static void EventSink_Speech( SpeechEventArgs e ) {
			WriteLine( e.Mobile, "{0}: {1}", Format( e.Mobile ), e.Speech );

			if( ConsoleEnabled )
				Console.WriteLine( e.Mobile.Name + String.Format( " ({0}): ", ((Account)e.Mobile.Account).Username ) + e.Speech );
		}

		[Usage( "ConsoleListen <true | false>" )]
		[Description( "Enables or disables outputting speech to the console." )]
		public static void ConsoleListen_OnCommand( CommandEventArgs e ) {
			if( e.Length == 1 ) {
				ConsoleEnabled = e.GetBoolean( 0 );
				e.Mobile.SendMessage( "Console speech output has been {0}.", ConsoleEnabled ? "enabled" : "disabled" );
				Console.WriteLine( "World listen has been {0}.", ConsoleEnabled ? "enabled" : "disabled" );
			} else {
				e.Mobile.SendMessage( "Format: ConsoleListen <true | false >" );
			}
		}
	}
}

Any help would be great. It's really necessary on my shard to have both these scripts. Although this might be something I need to go to the author of the world speech script instead of you, but if you see a way around this, please help. Thanks.
 
Top