Im going to make an unique item (there will be only one in whole server)

How can i make a gump show the name of the player carrying that unique item?

Ive been checking lots of scripts and cant find an example

Not sure if im explaining myself well :D
Thanks
 
Something like this, in your Gump body:

Code:
UniqueItem found = null;

foreach (Item i in World.Items.Values)
{
    if (i is UniqueItem) found = i as UniqueItem;
}

if (found != null)
{
    Mobile m = found.RootParent;
    if (m != null)
    {
        AddLabel(20,20,m.Name);
    }
  else AddLabel(20,20,"Nobody is carrying the item.");
}
 
Not 100% positive on the Label format, it might require a Hue. I forget. This was done off the cuff. Also, not sure of the RootParent call.
 
Hehe no problem. im getting errors thought:


CS0266: Line 92: Cannot implicitly convert type 'object' to 'Server.Mobile'.
An explicit conversion exists (are you missing a cast?)
CS1501: Line 95: No overload for method 'AddLabel' takes '3' arguments
CS1501: Line 97: No overload for method 'AddLabel' takes '3' arguments
CS0103: Line 104: The name 'sender' does not exist in the current context

this is the messy script:



Code:
using System;
using Server;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
using Server.Network;
using Server.Targeting;
using Server.Prompts;

using System.Collections;
using System.Collections.Generic;


namespace Server.Items
{

    public class Probandogump : Item
    {

        [Constructable]
        public Probandogump() : this( null )
        {
        }
       
        [Constructable]
        public Probandogump( string name ) : base( 0x2258 )
        {
            Name = "Deed check key test";
            Hue = 1153;
            Movable = false;
            LootType = LootType.Blessed;
        }
       
            public override void OnSingleClick( Mobile from )
{
    //PrivateOverheadMessage( MessageType.Label, 25, true, "[Epico]", from.NetState );
    PrivateOverheadMessage( MessageType.Label, 2548, true, "[Checks for a key]", from.NetState );
    base.OnSingleClick( from );
}
       
        public Probandogump( Serial serial ) : base( serial )
        {
        }
       

       
       

       
        public override void OnDoubleClick( Mobile from )
        {           

        from.SendGump( new testkeygump( from, this ) );
           
            }
       
        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
            writer.Write( (int) 0 );
        }
       
        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
        }
    }

   
   
        public class testkeygump : Gump
        {
    private Mobile m_Mobile;
        private Item m_Deed;
       
         public testkeygump (Mobile from, Item deed ) : base( 30, 20 )
        {
            m_Mobile = from;
            m_Deed = deed;
                       
           
            Keyyew found = null;
foreach (Item i in World.Items.Values)
{
    if (i is Keyyew) found = i as Keyyew;
}
if (found != null)
{
    Mobile m = found.RootParent;
    if (m != null)
    {
        AddLabel(20,20,m.Name);
    }
  else AddLabel(20,20,"Nobody is carrying the item.");
}
           
        }
       
        public override void OnResponse( NetState state, RelayInfo info )
        {
        Mobile from = sender.Mobile;

            switch ( info.ButtonID )
            {
                case 1:
                {
                    break;
                }
            }
          }
        }
}
 
CS0266: Line 92: Cannot implicitly convert type 'object' to 'Server.Mobile'.
An explicit conversion exists (are you missing a cast?)

Instead of " Mobile m = found.RootParent;" ...it should read:

Code:
Mobile m = null;
if (found.RootParent is Mobile)
{
    m = found.RootParent as Mobile;
}

CS1501: Line 95: No overload for method 'AddLabel' takes '3' arguments
CS1501: Line 97: No overload for method 'AddLabel' takes '3' arguments

Like I said, probably needs a Hue variable after the X, Y coordinates.

eg:

Code:
AddLabel(20, 20, 0x480, "This is my label"); // AddLabel(X, Y, Hue, Text);

CS0103: Line 104: The name 'sender' does not exist in the current context

Change it to read state.Mobile instead of sender.Mobile.
 
THANKS

It works now! Time to build the gump.
the only issue is that i got mobs that carry that unique item, and their name shows up in the gump, i would like to show only the names if the mobile is a Playermobile and not a mob
 
Maybe this part:

Code:
    if (m != null)
    {
        AddLabel(20,20,m.Name);
    }

Change to:

Code:
    if (m != null && m is PlayerMobile)
    {
        AddLabel(20,20,m.Name);
    }
 
Hm, right now it is crashing whenever i doubleclick

crash log:

Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Server.Items.testkeygump..ctor(Mobile from, Item deed)
at Server.Items.Probandogump.OnDoubleClick(Mobile from)
at Server.Mobile.Use(Item item)
at Server.Engines.XmlSpawner2.XmlAttach.UseReq(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)



Code:
using System;
using Server;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
using Server.Network;
using Server.Targeting;
using Server.Prompts;

using System.Collections;
using System.Collections.Generic;


namespace Server.Items
{

    public class Probandogump : Item
    {

        [Constructable]
        public Probandogump() : this( null )
        {
        }
      
        [Constructable]
        public Probandogump( string name ) : base( 0x2258 )
        {
            Name = "Deed check key test";
            Hue = 1153;
            Movable = false;
            LootType = LootType.Blessed;
        }
      
            public override void OnSingleClick( Mobile from )
{
    //PrivateOverheadMessage( MessageType.Label, 25, true, "[Epico]", from.NetState );
    PrivateOverheadMessage( MessageType.Label, 2548, true, "[Checks for a key]", from.NetState );
    base.OnSingleClick( from );
}
      
        public Probandogump( Serial serial ) : base( serial )
        {
        }
      

      
      

      
        public override void OnDoubleClick( Mobile from )
        {          

        from.SendGump( new testkeygump( from, this ) );
          
            }
      
        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
            writer.Write( (int) 0 );
        }
      
        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
        }
    }

  
  
        public class testkeygump : Gump
        {
    private Mobile m_Mobile;
        private Item m_Deed;
      
         public testkeygump (Mobile from, Item deed ) : base( 30, 20 )
        {
            m_Mobile = from;
            m_Deed = deed;
                      
          
            Keyyew found = null;
foreach (Item i in World.Items.Values)
{
    if (i is Keyyew) found = i as Keyyew;
}
if (found != null)
{
    Mobile m = null;
  
if (found.RootParent is Mobile && m is PlayerMobile)
{

    m = found.RootParent as Mobile;
}
              this.Closable=true;
            this.Disposable=true;
            this.Dragable=true;
            this.Resizable=false;

            AddPage(0);
            AddBackground(7, 6, 584, 476, 9200);
            AddHtml( 419, 54, 168, 129, @"Player carrying the item:", (bool)true, (bool)true);
            AddImage(0, 3, 5500);
            AddImage(40, 39, 5528);
            AddButton(355, 430, 2450, 2451, 0, GumpButtonType.Reply, 0);
            AddImage(80, 85, 22200);
            AddLabel(445, 111, 1156, m.Name);
    }
  else
        AddLabel(124, 435, 1152, @"Nobody is carrying the item.");
}
          
      
      
        public override void OnResponse( NetState state, RelayInfo info )
        {
        Mobile from = state.Mobile;

            switch ( info.ButtonID )
            {
                case 1:
                {
                    break;
                }
            }
          }
        }
}

I think the problem is here:


Code:
if (found != null)
{
    Mobile m = null;
  
if (found.RootParent is Mobile && m is PlayerMobile)
{
    m = found.RootParent as Mobile;
}
 
I took the liberty of cleaning it up.

Code:
using System;
using Server;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
using Server.Network;
using Server.Targeting;
using Server.Prompts;
using System.Collections;
using System.Collections.Generic;

namespace Server.Items
{
    public class Probandogump : Item
    {
        [Constructable]
        public Probandogump() : this( null )
        {
        }

        [Constructable]
        public Probandogump( string name ) : base( 0x2258 )
        {
            Name = "Deed check key test";
            Hue = 1153;
            Movable = false;
            LootType = LootType.Blessed;
        }

        public override void OnSingleClick( Mobile from )
        {
            //PrivateOverheadMessage( MessageType.Label, 25, true, "[Epico]", from.NetState );
            PrivateOverheadMessage( MessageType.Label, 2548, true, "[Checks for a key]", from.NetState );
            base.OnSingleClick( from );
        }

        public Probandogump( Serial serial ) : base( serial )
        {
        }

        public override void OnDoubleClick( Mobile from )
        {
            from.SendGump( new testkeygump( from, this ) );
        }

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
            writer.Write( (int) 0 );
        }

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

    public class testkeygump : Gump
    {
        private Mobile m_Mobile;
        private Item m_Deed;

        public testkeygump (Mobile from, Item deed ) : base( 30, 20 )
        {
            m_Mobile = from;
            m_Deed = deed;

            this.Closable=true;
            this.Disposable=true;
            this.Dragable=true;
            this.Resizable=false;

            AddPage(0);
            AddBackground(7, 6, 584, 476, 9200);
            AddHtml( 419, 54, 168, 129, @"Player carrying the item:", (bool)true, (bool)true);
            AddImage(0, 3, 5500);
            AddImage(40, 39, 5528);
            AddButton(355, 430, 2450, 2451, 0, GumpButtonType.Reply, 0);
            AddImage(80, 85, 22200);

            Keyyew found = null;
            foreach (Item i in World.Items.Values)
            {
                if (i is Keyyew) found = i as Keyyew;
            }
           
            if (found != null)
            {
                Mobile m = null;

                if (found.RootParent is Mobile)
                {
                    m = found.RootParent as Mobile;
                }
                if (m != null && m is PlayerMobile)
                {
                    AddLabel(445, 111, 1156, m.Name);
                }
                else
                {
                    AddLabel(124, 435, 1152, @"Nobody is carrying the item.");
                }
            }
        }



        public override void OnResponse( NetState state, RelayInfo info )
        {
            Mobile from = state.Mobile;

            switch ( info.ButtonID )
            {
                case 1:
                {
                    break;
                }
            }
        }
    }
}
 

Attachments

  • Probandogump.cs
    2.5 KB · Views: 2
Thanks!!!!!!!

For some reason the gump is not showing the player carrying the item. Im trying to move the label to the front with Gumpstudio but no sucess :D

gump.png
 
Last edited:
Gump Studio relies on layers. The game's gump system doesn't need them. If something is added after something else, it will be "on top" so as long as the code is lower (which it is) you can be sure it will NOT be hiding behind something.
 
It works now, i removed the white background with that scrollbar ( i dont know hows called) and the name shows up, yay!


Thanks for the help and support Lokai :)
 
Last edited:
------------------edit -------------------------------------------


I dont know why it doesnt works sometimes,

the gump doesnt show the player carrying the item, (i have it in my backpack) but it says ''nobody is carrying the item''.

I give the item to the player, then i click the board i made and the gump says it says ''nobody is carrying the item'', sometimes it does show the playername, then if i click after few minutes, it says ''nobody is carrying the item''. again :(

if i do [props to the item and the RootParentEntity shows the Playermobile name correctly

But the gump still doesnt shows it. (sometimes it does show the player carrying the time for a while, then after few mins it stops working and doesnt show it anymore until i carry a new item)

The item cant be on the ground, its going to be always on first level of players backpack, seems like the rootparent is not reaching the player carrying the item or something like that.

Does anyone knows why this happens?

any idea @Lokai ?

Thanks
 
Last edited:
Back