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!

Name system

Mr_clavet

Wanderer
Name system

Hey guys,
I'm trying to do a system that changes the names of the mobiles that the player sees. But i don't want the names of the mobile to change in fact, i just want to change the vision of the player, so that the player sees Jesus when the real name is Bob.
So if you dont know someone's name, it would be written: anonymous, or something like that. And after if you present yourself to this person, you tapp a command wich adds this player to your liste of contacts... And after that, you see his real name, not "anonymous".
i've looked the hallucination system, wich changes the color of all objects in a range of 50. But only the player hallucinating can see them. Is it possible to do that, but just to change the name of players around?
 

Fenn

Wanderer
I think you need to get down into the packet level in the server. I would think it would be a similar kind of intervention of data sent to a client, like when a mobile is hidden. Staff can see hidden things, and you can see yourself, but others can't.

I could be wrong, but that's my guess off the top of my head.
 

Mr_clavet

Wanderer
Yeah i know i could work with the client itself, but it'ld be pretty tough..
Although, maybe there's another way to do it. Like in the Hallucination script, it can change some items hue whitout changing it for real.
Dont know if we can do something with that...
 

Mideon

Page
Fenn is correct, you just have to modify the packet handlers. It's been a while since I've messed with them...but this will likely require a core mod and you'll have to play around with which packets have to be altered...for names there may be a few of them.

But it's certainly possible
 

Mr_clavet

Wanderer
Is there a tutorial somewhere showing how to play with these packets handlers? :D
I dont wanna mess everything...
ps. thanks for helping :)
 

Mideon

Page
Sorry finally had a bit more time to actually look at the code....

All the code you want is in the RunUO Source.

Now...bear in mind I'm working with an old 1.0 version here....but most of this will apply likely directly to what you want.

An example is...

Code:
// unsure of proper format, client crashes
	public sealed class MobileName : Packet
	{
		public MobileName( Mobile m ) : base( 0x98 )
		{
			string name = m.Name;

			if ( name == null ) name = "";

			this.EnsureCapacity( 37 );

			m_Stream.Write( (int) m.Serial );
			m_Stream.WriteAsciiFixed( name, 30 );
		}
	}

This is from the Core>>Netowork>>Packets.cs

There are many that pass mobile names though...so you may have to deal with all of them. Such as MobileIncoming, Even trade windows......

Basically you'll need to mod the packets to deal with who is "looking" at the mobile. This wil lbe the difficult part.

So in the above example you'd likely want to pass in a Mobile beholder parameter as well...and then check if beholder knows m....if so then make the name appear as normal, if not then obscure the name.
 

Mideon

Page
No you just have to alter the code in the core. You aren't really completely changing the packets, just altering what info they pass.

So if you didn't know the mobs name...instead of writing mobvar.Name to the packet stream, youd write "anonymous" etc
 

Gargouille

Sorceror
Hi,

(I don't think you can work with the MobileName packet, as it does not have the Mobile "from" for argument... Someone is aking for your name... but who ? )

Here's a suggest for you, it's a work I done long time ago...


First, in Mobile.cs, add this :
Code:
public virtual string GetNameUseBy(Mobile from)
{
	return Name;
}

Then, in PlayerMobile, override it as you need to change the name...

And now, you got t o use that method GetNameUseBy wherether Name is asked... And it's asked very often :rolleyes:

Such as in Packets, in the MobileStatus packet :
Code:
public sealed class MobileStatus : Packet
{
	public MobileStatus( Mobile beholder, Mobile beheld ) : base( 0x11 )
	{
		//string name = beheld.Name;
		string name=beheld.GetNameUseBy(beholder);
		if ( name == null ) name = "";

And, with a little working-bidouille for the Paperdollrequest :
Code:
public override void DisplayPaperdollTo( Mobile to )
{
         string oldname=Name;
         Name=GetNameUseBy(to);
         EventSink.InvokePaperdollRequest( new PaperdollRequestEventArgs( to, this ) );
         Name=oldname;
 }

But still name requests everywhere, House signs, secure trade, etc, etc ...



Now some code for a kind of system you want :
Code:
private Dictionary<int,string>KnewName=new Dictionary<int,string>();
				
		private void LaunchGumpName()
		{
			from.SendGump(new RenameGump(this));
		}
		
		public void NewName(string entry,Mobile mob)
		{
			if(KnewName.ContainsKey(mob.Serial.Value))KnewName[mob.Serial.Value]=entry;//ici
			else KnewName.Add(mob.Serial.Value,entry);//ou là, on crée le nom
			SendPropertiesTo(mob);
		}
		
		public override void SendPropertiesTo( Mobile from )
		{
			ObjectPropertyList list=new ObjectPropertyList(this);
			list.Add(from==this?Name:GetNameUseBy(from));
			from.Send( list );
		}
		
		public string GetNameUseBy(Mobile from)
		{
			if(KnewName.ContainsKey(from.Serial.Value))return KnewName[from.Serial.Value];
			
			return DefaultName(from);
		}	
		
		private string DefaultName(Mobile from)
		{
			if(from.Female)return "une femme";  // et ici rajouter en fonction des races, si besoin
			else return "un homme";
		}
		
		public override void OnAosSingleClick( Mobile from )
		{
			ObjectPropertyList opl = new ObjectPropertyList(this);
			opl.Add(GetNameUseBy(from));
			
			if ( opl.Header > 0 )
			{
				int hue=11;
				from.Send( new MessageLocalized( this.Serial, Body, MessageType.Label, hue, 3, opl.Header, Name, opl.HeaderArgs ) );
			}
		}
						
		public override void OnSingleClick( Mobile from )
		{
			
		}
		
		public override void DisplayPaperdollTo( Mobile to )
		{
			string oldname=Name;
			Name=GetNameUseBy(to);
			EventSink.InvokePaperdollRequest( new PaperdollRequestEventArgs( to, this ) );
			Name=oldname;
		}

An ugly gump to do it working :
Code:
using System;
using Server;
using Server.Gumps;
using Server.Network;
using Server.Mobiles;

namespace Server.Gumps
{
	public class RenameGump : Gump
	{
		public RenameGump(PlayerMobile m)
			: base( 0, 0 )
		{
			this.Closable=true;
			this.Disposable=true;
			this.Dragable=true;
			this.Resizable=false;
			this.AddPage(0);
			this.AddBackground(0, 0, 454, 182, 9200);
			this.AddLabel(98, 14, 0, @"Entrez le nom de ce personnage :");
			this.AddTextEntry(89, 60, 200, 20, 0, 0,"");
			AddButton( 345, 217, 0xF2, 0xF1, 0, GumpButtonType.Reply, 0 );
			to=m;
		}
		
		public PlayerMobile to;
		
		public override void OnResponse( NetState sender, RelayInfo info )
		{
			Mobile from=(Mobile)sender.Mobile;
			
			switch( info.ButtonID )
			{
				case 0:
				{
					TextRelay entry = info.GetTextEntry( 0 );
					string entrytext = (entry == null) ? "" : entry.Text;
					to.NewName(entrytext,from);
					from.SendMessage(entrytext);
					from.CloseGump(typeof(RenameGump));
					break;
				}
				from.SendGump(new RenameGump((PlayerMobile)from));
			}
		}
	}
}

A MenuEntry to launch the gump :
Code:
public override void GetContextMenuEntries( Mobile m_from, List<ContextMenuEntry> list )
		{
			base.GetContextMenuEntries( m_from, list );
                       
			if(m_from!=this)
			{
				list.Add( new CallbackEntry(6161, new ContextCallback(LaunchGumpName)));
			}
		}

And the Serialization/Deserialization fo rthe Dictionary :
Code:
writer.Write((int)KnewName.Count);
foreach(KeyValuePair<int,string>kvp in KnewName)
{
	writer.Write((int)kvp.Key);
	writer.Write((string)kvp.Value);
}

Code:
int count=reader.ReadInt();
for(int i=0;i<count;i++)
{
	KnewName[reader.ReadInt()]=reader.ReadString();
}
 

Mr_clavet

Wanderer
Well thank you!
If I use the system (the one with the ugly gump), do i still have to alter the packets?
Other question: the Dictionary,with wich namespace should I work? (Sry i'm so noob)
--> As for the MenuEntry...
 

Gargouille

Sorceror
The Dictionary and the menu take place in PlayerMobile, and Dictionary serialization too of course.

It just save for each player the names he gave to the others.

But you need to recompile a core with edited packet...

And replace Name by GetNameUseBy everywhere Name is used "in public place"...
 
Top