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!

Trying to hide FameTitle with an item.

Packer898

Knight
Trying to hide FameTitle with an item.

This should be simple but for the life of me I cant make it work. I am simply trying to hide the FameTitles when this item is equipped. I thought I could do this with from.ShowFameTitle = false; but that just gives me an error below.
Code:
 5) Property or indexer 'Server.Mobile.ShowFameTitle' cannot be assigned to -- i
t is read only

Now I have tried everything I can think of. I have case mobile to PlayerMobile and tried that. Any suggestions for the way to do this. I know there has to be a way...

Heres the script in case you need to see it.
Code:
///************************************************///*********************///
/// Script:	Halloween Mask                         ///      ,dP""dMb,      ///
/// Version: 1.0                                   ///     d"   dMP"Tb     ///
/// Designed by: Packer898                         ///    (M    YMbodM)    ///
/// For use with: RunUO 1.0.0                      ///    `M, o  )MMMP     ///
/// Please do NOT remove this header.              ///      "b,,aMMP"      ///
///************************************************************************///
/// Intallation: Place into your Custom directory and restart the server.  ///
///************************************************************************///
using System;
using Server.Mobiles;

namespace Server.Items
{
	public class HalloweenMask : HornedTribalMask
	{
		
		[Constructable]
		public HalloweenMask() : base( 0x1549)
		{
			Hue = 1358;
			Name = "Trick or Treat";
			LootType = LootType.Blessed;
			Weight = 1.0;
		}
		
		public HalloweenMask( Serial serial ) : base( serial )
		{
		}
		
		public override bool OnEquip( Mobile from )
		{
			if ( from.Mounted == true )
			{
				from.SendLocalizedMessage( 1042561 );
			}
			if ( from.BodyValue == 0x190 )
			{
				from.SendMessage("Trick! You are now a ghoul!");
				from.NameMod = "a ghoul";
				from.BodyMod = 153;
				from.HueMod = 0x0;
				from.DisplayGuildTitle = false;
				from.Criminal = false;
				from.PlaySound( 1343 );
				new MaskTimer(from).Start();
			}
			if ( from.BodyValue == 0x191 )
			{
				from.SendMessage("Trick! You are now a ghoul!");
				from.NameMod = "a ghoul";
				from.BodyMod = 153;
				from.HueMod = 0x0;
				from.DisplayGuildTitle = false;
				from.Criminal = false;
				from.PlaySound( 1340 );
				new MaskTimer(from).Start();
			}
			if (from is PlayerMobile)
			{
				PlayerMobile pm = (PlayerMobile)from;
				
				pm.ShowFameTitle = false;
			}
			
			return base.OnEquip(from);
		}
		
		public override void OnRemoved( object parent )
		{
			if(parent is Mobile)
			{
				Mobile from = (Mobile)parent;
				
				if ( from.BodyMod == 153 )
				{
					from.SendMessage("Treat - Happy Halloween 2005");
					from.NameMod = null;
					from.BodyMod = 0x0;
					from.HueMod = -1;
					from.PlaySound( 527 );
				}
				if(from.Kills >= 5)
				{
					from.Criminal = true;
				}
				if(from.GuildTitle != null )
				{
					from.DisplayGuildTitle = true;
				}
			}
		}
		
		private class MaskTimer : Timer
		{
			private Mobile m_Mobile;
			
			public MaskTimer( Mobile m ) : base( TimeSpan.FromSeconds( 10.0 ) )
			{
				m_Mobile = m;
			}
			
			protected override void OnTick()
			{
				m_Mobile.SendMessage("Treat - Happy Halloween 2005");
				m_Mobile.NameMod = null;
				m_Mobile.BodyMod = 0x0;
				m_Mobile.HueMod = -1;
				m_Mobile.PlaySound( 527 );
				
				if(m_Mobile.Kills >= 5)
				{
					m_Mobile.Criminal = true;
				}
				if(m_Mobile.GuildTitle != null )
				{
					m_Mobile.DisplayGuildTitle = true;
				}
			}
		}
		
		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			
			writer.Write( (int) 0 ); // version
		}
		
		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			
			int version = reader.ReadInt();
		}
	}
}
 

milt

Knight
I think you will have to do it another way. In Mobile.cs, this is what it says:
Code:
public virtual bool ShowFameTitle{ get{ return true; } }

Notice how there is no set accessor.
 

Kamron

Knight
To elaborate on arul, you could do something similar to

public override bool ShowFameTitle{ get{ return !(FindItemOnLayer( Layer.Helm ) is HalloweenMask); } }
 

Packer898

Knight
XxSP1DERxX said:
To elaborate on arul, you could do something similar to

public override bool ShowFameTitle{ get{ return !(FindItemOnLayer( Layer.Helm ) is HalloweenMask); } }

Kool Thanks. How would I write this If I wanted to be able to override this property and not specifiy an item in playermobile and just be able to add it in each item I want to do this with? That possible? I have a couple different items I would love to be able to do this with.
 

Kamron

Knight
You would create an interface... like

INoFameTitle

then you would make all of the items have that interface, and change the property to

public override bool ShowFameTitle{ get{ return !(FindItemOnLayer( Layer.Helm ) is INoFameTitle); } }
 

arul

Sorceror
Packer898 said:
Kool Thanks. How would I write this If I wanted to be able to override this property and not specifiy an item in playermobile and just be able to add it in each item I want to do this with? That possible? I have a couple different items I would love to be able to do this with.
You'll need to add a new flag to PlayerFlags
Code:
    [Flags]
    public enum PlayerFlag // First 16 bits are reserved for default-distro use, start custom flags at 0x00010000
    {
        None = 0x00000000,
        Glassblowing = 0x00000001,
        Masonry = 0x00000002,
        SandMining = 0x00000004,
        StoneMining = 0x00000008,
        ToggleMiningStone = 0x00000010,
        KarmaLocked = 0x00000020,
        AutoRenewInsurance = 0x00000040,
        UseOwnFilter = 0x00000080,
        PublicMyRunUO = 0x00000100,
        PagingSquelched = 0x00000200,
        Young = 0x00000400,
[COLOR="Red"][B]        ShowFame = 0x00010000[/B][/COLOR]
    }
And then you can override the property this way
Code:
        public overrider bool ShowFameTitle
        {
            get
            {
                return GetFlag( PlayerFlag.ShowFame );
            }
            set
            {
                SetFlag( PlayerFlag.ShowFame, value );
            }
        }
 

Packer898

Knight
arul said:
You'll need to add a new flag to PlayerFlags
Code:
    [Flags]
    public enum PlayerFlag // First 16 bits are reserved for default-distro use, start custom flags at 0x00010000
    {
        None = 0x00000000,
        Glassblowing = 0x00000001,
        Masonry = 0x00000002,
        SandMining = 0x00000004,
        StoneMining = 0x00000008,
        ToggleMiningStone = 0x00000010,
        KarmaLocked = 0x00000020,
        AutoRenewInsurance = 0x00000040,
        UseOwnFilter = 0x00000080,
        PublicMyRunUO = 0x00000100,
        PagingSquelched = 0x00000200,
        Young = 0x00000400,
[COLOR="Red"][B]        ShowFame = 0x00010000[/B][/COLOR]
    }
And then you can override the property this way
Code:
        public overrider bool ShowFameTitle
        {
            get
            {
                return GetFlag( PlayerFlag.ShowFame );
            }
            set
            {
                SetFlag( PlayerFlag.ShowFame, value );
            }
        }

Tell me that I cannot override this because it has no set accessor.
 

arul

Sorceror
Well my bad ;)
So we need to make a slave setter
Code:
        public overrider bool ShowFameTitle
        {
            get
            {
                return GetFlag( PlayerFlag.ShowFame );
            }
        }
        public bool SetShowFameTitle
        {
               set
               {
                   SetFlag( PlayerFlag.ShowFame, value );
               }
         }
 

arul

Sorceror
Yes, since initially there is no such flag, the value of that flag is false at default, thus I suggest negate the bool expressions.
 

arul

Sorceror
Code:
        public overrider bool ShowFameTitle
        {
            get
            {
                !return GetFlag( PlayerFlag.ShowFame );
            }
        }
        public bool SetShowFameTitle
        {
               set
               {
                   SetFlag( PlayerFlag.ShowFame, !value );
               }
         }
negation = switches true x false in fact.
 

Kamron

Knight
arul said:
Well my bad ;)
So we need to make a slave setter
Code:
        public [COLOR=RED]overrider[/COLOR] bool ShowFameTitle
        {
            get
            {
                return GetFlag( PlayerFlag.ShowFame );
            }
        }
        public bool SetShowFameTitle
        {
               set
               {
                   SetFlag( PlayerFlag.ShowFame, value );
               }
         }

You don't need a slave setter as long as you casted to a PlayerMobile before you tried to set it.
Also you spelled override wrong arul ;)

And as a note, I suggest certain ways because other ways are a pain in the ass...
 

arul

Sorceror
XxSP1DERxX said:
You don't need a slave setter as long as you casted to a PlayerMobile before you tried to set it.
Mobile.ShowFameTitle doesn't have overridable set accessor, thus we need the slave setter...
 

Khaz

Knight
And Sp1der's previous suggestion (using an interface) is a really great way to do this, and it'll teach you a good deal more than flagging the PlayerMobile.
 

Packer898

Knight
Error:
Code:
 - Error: Scripts\Custom\Modified\Mobiles\PlayerMobile.cs: CS1525: (line 71, col
umn 18) Invalid expression term 'return'
 - Error: Scripts\Custom\Modified\Mobiles\PlayerMobile.cs: CS1002: (line 71, col
umn 25) ; expected

Playermobiles.cs: 71 is in red
Code:
		public override bool ShowFameTitle
        {
            get
            {
               [COLOR="Red"] !return GetFlag( PlayerFlag.ShowFame );[/COLOR]
            }
        }
        public bool SetShowFameTitle
        {
               set
               {
                   SetFlag( PlayerFlag.ShowFame, !value );
               }
         }
 

arul

Sorceror
Khaz said:
And Sp1der's previous suggestion (using an interface) is a really great way to do this, and it'll teach you a good deal more than flagging the PlayerMobile.
Obviously its a good and working way, but I'm intent to the code reusuability rather...
 

arul

Sorceror
Packer898 said:
Error:
Code:
 - Error: Scripts\Custom\Modified\Mobiles\PlayerMobile.cs: CS1525: (line 71, col
umn 18) Invalid expression term 'return'
 - Error: Scripts\Custom\Modified\Mobiles\PlayerMobile.cs: CS1002: (line 71, col
umn 25) ; expected

Playermobiles.cs: 71 is in red
Code:
		public override bool ShowFameTitle
        {
            get
            {
               [COLOR="Red"] !return GetFlag( PlayerFlag.ShowFame );[/COLOR]
            }
        }
        public bool SetShowFameTitle
        {
               set
               {
                   SetFlag( PlayerFlag.ShowFame, !value );
               }
         }
Well, I need really sleep ;)
Code:
public override bool ShowFameTitle
        {
            get
            {
                return !GetFlag( PlayerFlag.ShowFame );
            }
        }
 
Top