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!

Help with TeleportPets

zerodowned

Sorceror
I'm working on the vet reward, Crystal Portal.
Trying to script it so for each location I can just add StartTeleport and it will teleport the player's pets where the player is going.
It's compiling and teleporting the player without any problems but not the pet.



Code:
using System;
using Server;
using Server.Network;
using Server.Mobiles;
using Server.Spells;
 
namespace Server.Items
{
    public class CrystalPortal : Item
    {
   
        private Point3D m_PointDest;
        private Map m_MapDest;
 
        [CommandProperty( AccessLevel.GameMaster )]
        public Point3D PointDest
        {
            get { return m_PointDest; }
            set { m_PointDest = value; InvalidateProperties(); }
        }
 
        [CommandProperty( AccessLevel.GameMaster )]
        public Map MapDest
        {
            get { return m_MapDest; }
            set { m_MapDest = value; InvalidateProperties(); }
        }
   
   
   
        [Constructable]
        public CrystalPortal() : base()
        {
            ItemID= 18059;
            Name= "Crystal Portal";
           
           
        }
 
        public CrystalPortal( Serial serial ) : base( serial )
        {
           
        }
       
        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();
        }
 
       
       
        public virtual void StartTeleport( Mobile m )
        {
            Map map = m_MapDest;
 
            if ( map == null || map == Map.Internal )
                map = m.Map;
 
            Point3D p = m_PointDest;
 
            if ( p == Point3D.Zero )
                p = m.Location;
               
            Server.Mobiles.BaseCreature.TeleportPets( m, p, map );
        }   
       
        public override bool HandlesOnSpeech{ get{ return true; } }
 
///////  Begin Speech Entries  //////
 
        public override void OnSpeech( SpeechEventArgs e )
        {
            if (!e.Handled && e.Mobile.InRange(this.Location, 2))
                {
                    PlayerMobile pm = e.Mobile as PlayerMobile;
 
                    if (e.Speech.ToLower() == "Britain Mint")
                    {
                        e.Handled = true;
                        e.Mobile.MoveToWorld( new Point3D( 1434, 1699, 2 ), Map.Trammel );
                        StartTeleport( pm );
                    }
       
                }
        }
       
   
    }
}
 

milva

Sorceror
Try adding this m.MoveToWorld(p, map);
after Server.Mobiles.BaseCreature.TeleportPets(m, p, map);
Taken from the SHTeleporter
 

zerodowned

Sorceror
Thank you, I got that part working. Now to figure out how to make it recognize keywords with spaces.
There are not clilocs for the commands I need so I think I'll use the keywords found in Xanthos mercenary script. but even that doesn't seem to support spaces.
I guess there's no harm in making players type BritainMint instead of Britain Mint.

link to item i'm scripting for ref. http://www.uoguide.com/Crystal_Portal
 

Enroq

Sorceror
Code:
        public static void Initialize()
        {
            EventSink.Speech += new SpeechEventHandler(HookSpeech);
 
        }
 
        public static void HookSpeech(SpeechEventArgs e)
        {
            if (e.Speech.ToLower().IndexOf("i wish to form an alliance") >= 0)
            {
                AttemptInitialization(e);
            }
 
            if (e.Speech.ToLower().IndexOf("i wish to disband my alliance") >= 0)
            {
                CheckLeader(e);
            }
 
            if (e.Speech.ToLower().IndexOf("i wish to form a pact") >= 0)
            {
                AttemptPact(e);
            }
        }
 

zerodowned

Sorceror
Thank you Enroq. What script is that from? I'm running into some errors and always like a script to reference.
 

Enroq

Sorceror
Unfortunately that's from a project that has been paid for by a third party, and I can not release it. However, if you want to post the errors, I'm sure we can figure out whatever is going on.
 

zerodowned

Sorceror
oh, okay.

here's the error
Line 55: Keyword 'this' is not valid in a static property, static me
thod, or static field initializer
CS0103: Line 63: The name 'AttemptInitialization' does not exist in the curr
ent context


and here's the updated script
Code:
using System;
using Server;
using Server.Network;
using Server.Mobiles;
using Server.Spells;
 
namespace Server.Items
{
    public class CrystalPortal : Item
    {
 
        [Constructable]
        public CrystalPortal() : base()
        {
            ItemID= 18059;
            Name= "Crystal Portal";
        }
 
        public CrystalPortal( Serial serial ) : base( serial )
        {
           
        }
       
        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();
        }
 
    //public override bool HandlesOnSpeech{ get{ return true; } }
 
///////  Begin Speech Entries  //////
 
        public static void Initialize()
        {
            EventSink.Speech += new SpeechEventHandler(HookSpeech);
 
        }
 
        public static void HookSpeech(SpeechEventArgs e)
        {   
           
       
            if (!e.Handled && e.Mobile.InRange(this.Location, 2))
                {
                    PlayerMobile pm = e.Mobile as PlayerMobile;
                   
                    //if (e.Speech.ToLower() == "unorus")
                    if (e.Speech.ToLower().IndexOf("Britain Mint") >= 0)
                    {
                        //e.Handled = true;
                        AttemptInitialization(e);
                   
                        Point3D loc = new Point3D( 1435, 1699, 2 );
                        Map map = Map.Trammel;
                       
                        BaseCreature.TeleportPets( e.Mobile, loc, map );
                        e.Mobile.MoveToWorld( loc, map );
                    }
       
                }
        }
       
   
    }
}
 

Enroq

Sorceror
You can not use 'this' inside static methods because they do not require the instantiation of an object. When a method is static that means one method exists for every object created by the class. When using 'this' you are referring to that object, before it is created.
 

zerodowned

Sorceror
changed static to virtual so it's object oriented, now getting this error

CS0103: Line 65: The name 'AttemptInitialization' does not exist in the current context



Code:
using System;
using Server;
using System.Text;
using Server.Commands;
using Server.Network;
using Server.Mobiles;
 
 
namespace Server.Items
{
    public class CrystalPortal : Item
    {
 
        [Constructable]
        public CrystalPortal() : base()
        {
            ItemID= 18059;
            Name= "Crystal Portal";
        }
 
        public CrystalPortal( Serial serial ) : base( serial )
        {
           
        }
       
        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();
        }
 
    //public override bool HandlesOnSpeech{ get{ return true; } }
 
///////  Begin Speech Entries  //////
 
        public virtual void Initialize()
        {
            EventSink.Speech += new SpeechEventHandler(HookSpeech);
 
        }
 
       
       
        public virtual void HookSpeech(SpeechEventArgs e)
        {   
           
       
            if (!e.Handled && e.Mobile.InRange(this.Location, 2))
            //if ( !e.Handled )
                {
                    PlayerMobile pm = e.Mobile as PlayerMobile;
                   
                    //if (e.Speech.ToLower() == "unorus")
                    if (e.Speech.ToLower().IndexOf("Britain Mint") >= 0)
                    {
                        //e.Handled = true;
                        AttemptInitialization(e);
                   
                        Point3D loc = new Point3D( 1435, 1699, 2 );
                        Map map = Map.Trammel;
                       
                        BaseCreature.TeleportPets( e.Mobile, loc, map );
                        e.Mobile.MoveToWorld( loc, map );
                    }
       
                }
        }
       
   
    }
}
 

zerodowned

Sorceror
doesn't seem like virtual would be correct, but since this is item based it needs to check how close the player is to the item.
 

zerodowned

Sorceror
figured out that the spoken part has to be all lower case letters. so "britain mint" instead of "Britain Mint".
but I'm still at a loss how to check distance from the item since I have to use a static modifier.

so any help with that would be appreciated.
 

daat99

Moderator
Staff member
Why are you trying to check it in your HookSpeach method?

What are you really trying to do?
 

zerodowned

Sorceror
i was only using HookSpeech because of Enroq's post. but going back to my original code and using all lower case it works now.
was trying to make it recognize upper and lower case letters. but i'm not a stickler for OSI accuracy. ref: http://www.uoguide.com/Crystal_Portal

and here's the original code cleaned up a bit with working speech

edit: cleaned up a little more
Code:
using System;
using Server;
using Server.Network;
using Server.Mobiles;


namespace Server.Items
{
    public class CrystalPortal : Item
    {

        [Constructable]
        public CrystalPortal() : base()
        {
            ItemID= 18059;
            Name= "Crystal Portal";
        }

        public CrystalPortal( Serial serial ) : base( serial )
        {
            
        }
        
        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();
        }

    public override bool HandlesOnSpeech{ get{ return true; } }

///////  Begin Speech Entries  //////

        public override void OnSpeech( SpeechEventArgs e )
        {
            if (!e.Handled && e.Mobile.InRange(e.Mobile.Location, 2))
                {
                
                    if (e.Speech.ToLower() == "britain mint")
                    {
                        Point3D loc = new Point3D( 1435, 1699, 2 );
                        Map map = Map.Trammel;
                        
                        BaseCreature.TeleportPets( e.Mobile, loc, map );
                        e.Mobile.MoveToWorld( loc, map );
                    }
                    
                }
        }
    }
}
 

daat99

Moderator
Staff member
You do realize that you are checking if the mobile is in range of itself, right? (this is why I deleted my earlier post but you were too fast to read it before I was able to)
 

daat99

Moderator
Staff member
You welcome :)
Considering you are no longer inside a "static" method than the keyword "this" has a meaning again Yay :)
 
Top