I have a script that lets players set up a custom biography of themselves and other players read it. I also have a robe that gives you a random name with the NameMod value. What I am trying to figure out is how do I check to see if a player has a NameMod? I have been searching RunUO and these forums and can't seem to find an example.

I tried
Code:
else if ( targeted is PlayerMobile && targeted.NameMod )
				{
					from.SendMessage("There's nothing special about it, it isn't worth looking at...");
				}

but got this error

Code:
Errors:
 + Custom/Commands/Look.cs:
    CS1061: Line 49: 'object' does not contain a definition for 'NameMod' and no
 extension method 'NameMod' accepting a first argument of type 'object' could be
 found (are you missing a using directive or an assembly reference?)
Scripts: One or more scripts failed to compile or no script files were found.
 - Press return to exit, or R to try again.

I'm prolly completely way off base. basically if a player has the robe on with the fake name I don't want players to see there true biography revealing who they are. So I am trying to do a NameMod check but don't know what value to check for?
 
You need to cast it right after checking if it inherits, ie:

1- check if target is playermobile.
2- if playermobile, create a local variable (or not) and convert the target to the playermobile.
3- use that converted to check what it has to offer.

Code:
else if ( targeted is PlayerMobile )
{
PlayerMobile pm = (PlayerMobile)targeted
if ( targeted.NameMod != null || targeted.NameMod.Trim().Length > 0 )
from.SendMessage("There's nothing special about it, it isn't worth looking at...");
}
 
Last edited:
I never would have thought of targeted.NameMod.Trim().Length thank you! Based off your example I tried constructing this. (I couldn't just add your code without complications from other checks.)

Code:
protected override void OnTarget( Mobile from, object targeted ) 
		{ 
			if ( from is PlayerMobile && targeted is PlayerMobile ) 
			{ 
				PlayerMobile pm = (PlayerMobile)targeted;
				if(from.Equals(targeted))
				{
					((Mobile)targeted).DisplayPaperdollTo( from );
					from.Send( new DisplayProfile( !from.ProfileLocked, from, "Description of " + from.RawName, from.Profile, "Use the space above to describe your character.") );
				}
				else if ( targeted.NameMod != null || targeted.NameMod.Trim().Length > 0 )
				{
					from.SendMessage("There's nothing special about it, it isn't worth looking at...");
				}
				else
				{
					((Mobile)targeted).SendMessage("You notice that {0} is looking at you.", from.Name );
					((Mobile)targeted).DisplayPaperdollTo( from );
					from.CloseGump( typeof( lookGump ) );
					from.SendGump(new lookGump( from, (Mobile)targeted ));
				}
			}
	 		else
				from.SendMessage("There's nothing special about it, it isn't worth looking at...");
		}

but get this error.

Code:
Errors:
 + Custom/Commands/Look.cs:
    CS1061: Line 50: 'object' does not contain a definition for 'NameMod' and no
 extension method 'NameMod' accepting a first argument of type 'object' could be
 found (are you missing a using directive or an assembly reference?)
    CS1061: Line 50: 'object' does not contain a definition for 'NameMod' and no
 extension method 'NameMod' accepting a first argument of type 'object' could be
 found (are you missing a using directive or an assembly reference?)
Scripts: One or more scripts failed to compile or no script files were found.
 - Press return to exit, or R to try again.

Here is the entire script. (should have posted it to begin with, I'm sorry.)

Code:
//   ___|========================|___
//   \  |  Written by Felladrin  |  /	This script was released on RunUO Forums under the GPL licensing terms.
//    > |      February 2010     | < 
//   /__|========================|__\	Current version: 1.0 (February 6, 2010)

using System;
using Server;
using Server.Mobiles;
using Server.Targeting;
using Server.Gumps;
using Server.Network;

namespace Server.Commands
{ 
	public class lookCommand
	{ 
		public static void Initialize() 
		{ 
			CommandSystem.Register( "Look", AccessLevel.Player, new CommandEventHandler( look_OnCommand ) );
		}

		[Usage( "Look" )]
		[Description( "Used to look at someone who is near you or to change your's character description." )]
		public static void look_OnCommand( CommandEventArgs e )
		{ 
			if ( e.Mobile is PlayerMobile ) 
			{				
				e.Mobile.SendMessage( "Who would you like to look at?" );
				e.Mobile.Target = new lookTarget();
			}
		}
	}

	public class lookTarget : Target
	{ 
		public lookTarget() : base( -1, false, TargetFlags.None )
		{
		}

		protected override void OnTarget( Mobile from, object targeted ) 
		{ 
			if ( from is PlayerMobile && targeted is PlayerMobile ) 
			{ 
				PlayerMobile pm = (PlayerMobile)targeted;
				if(from.Equals(targeted))
				{
					((Mobile)targeted).DisplayPaperdollTo( from );
					from.Send( new DisplayProfile( !from.ProfileLocked, from, "Description of " + from.RawName, from.Profile, "Use the space above to describe your character.") );
				}
				else if ( targeted.NameMod != null || targeted.NameMod.Trim().Length > 0 )
				{
					from.SendMessage("There's nothing special about it, it isn't worth looking at...");
				}
				else
				{
					((Mobile)targeted).SendMessage("You notice that {0} is looking at you.", from.Name );
					((Mobile)targeted).DisplayPaperdollTo( from );
					from.CloseGump( typeof( lookGump ) );
					from.SendGump(new lookGump( from, (Mobile)targeted ));
				}
			}
	 		else
				from.SendMessage("There's nothing special about it, it isn't worth looking at...");
		} 
	}

	public class lookGump : Gump
	{
		private const int Width = 300;
		private const int Height = 200;

		public lookGump( Mobile m, Mobile target ) : base( 100, 100 )
		{
			AddPage( 0 );

			AddBackground( 0, 0, Width, Height, 0xDAC );

			AddPage( 1 );

			AddHtml( 0, 10, Width, 25, "<CENTER>" + "Observing " + target.Name, false, false );
			AddHtml( 20, 30, Width-40, Height-50, target.Profile, true, true );
		}
	}
}
 
You are making the same mistake you made in your first post. You need to explicitly cast targeted to the type you are expecting which is mobile or playermobile.
 
  • Like
Reactions: ExX
I am sorry I fail at this. I'm not sure what you mean. I am still defining
  1. if ( from is PlayerMobile && targeted is PlayerMobile )
    {
    PlayerMobile pm = (PlayerMobile)targeted;
I just put it at the top of the if statement in the override. I did it just like he suggested but I had to re-arrange it cause of how large the checks is getting.
Hmmm I'll try playing with it a bit more.
 
Ahh I see the problem.

Po0ka gave you the right steps in fixing the error but never applied the last step to the code he gave you.

Since playermobile is casted on target you need to apply your conditionals to pm rather than targeted.

Change

Code:
 ( targeted.NameMod != null || targeted.NameMod.Trim().Length > 0 )

to

Code:
( pm.NameMod != null || pm.NameMod.Trim().Length > 0 )
 
That fixed the issue! Thanks a lot. I was actually going to ask why he wanted me to define pm and not use it. Sometimes I refrain from asking questions cause I am so new and still learning that I don't want to sound too dumb. lol

As the risk of it... So I can better learn. I wonder why targeted didn't work? If the targeted is the playermobile it seems redundant to convert it to pm?
 
Ask whatever questions you wish! It is how you learn.

At compile time there is no way to know what type targeted is going to be because it has not been assigned yet, it is blank for all intents and purposes. NameMod is an attribute of mobile and playermobile and not targeted at compile so when you have targeted.NameMod == xxx the compiler is not going to know what to do since NameMod does not exist within targeted until you actually target something in game. Because of this you need to cast the type you are expecting upon targeted, this will tell the compiler that when it comes time that this attribute will exist in the type even though it does not at compile time. I hope this clears it up for you.
 
Ah duh. Makes complete sense. Sometimes I forget that this language doesn't read code on the fly in order and it's all pre-read at compile. Have to keep reminding myself of that. Thank you very much for the explanation.
 
Mind popped up when dmurphy said:
NameMod is an attribute of mobile and playermobile
This made me think casting as a PlayerMobile would be too much, casting to Mobile would be enough in this case, as both Mobile and PlayerMobile use NameMod.

Conclusion: (Mobile)targeted instead of (PlayerMobile)targeted.
 
Back