Action delay, range checks and LOS checks on items.

Discussion in 'RunUO Development' started by JackJack, Nov 2, 2014.

  1. JackJack

    JackJack New Member

    Joined:
    Nov 2, 2014
    Messages:
    1
    Likes Received:
    0
    A big thing that confused me in RunUO was when I went to add in an action delay to items

    Using items through walls is obviously not a good thing to have on any server, and personally I find action delay to be very important. There are many things by default that simply don't function very well without an action delay. Telamon gives a good example here.

    I had been manually adding in action delays/range checks/LOS checks to items as I went because I didn't realise it was possible from a root level - OnDoubleClick is generally overridden. However there are certain things that do happen before OnDoubleClick even gets called. Let's take a look at them.

    Item.cs - CheckItemUse gets called, followed by OnItemUse. If these return false, OnDoubleClick is never called.

    Mobile.cs - Again, CheckItemUse. This gets called when the item.cs CheckItemUse finds the item is on the player. By default, it always just returns true.

    Changes you will need to make:

    Item.cs
    Code:
    public virtual void OnItemUse( Mobile from, Item item )
    {
        from.NextActionTime = Core.TickCount + Mobile.ActionDelay;
        /// rest of OnItemUse code here
    }
    Item.cs
    Code:
            public virtual bool CheckItemUse( Mobile from, Item item )
            {
                if ( m_Parent is Item )
                    return ((Item)m_Parent).CheckItemUse( from, item );
                else if ( m_Parent is Mobile )
                    return ((Mobile)m_Parent).CheckItemUse( from, item );
                else
                {      // first, check we are close enough and can see the item
                    if ( from.InRange( this.GetWorldLocation(), 2 ) && from.InLOS( this ) && from.CanSee( this ) )
                    {      // check the action timer has expired
                        if ( Core.TickCount - from.NextActionTime >= 0 )
                        {
                            return true;
                        }
                        else
                        {
                            from.SendActionMessage();
                            return false;   
                        }
                    }
                    else
                    {
                        from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1019045 ); // I can't reach that.
                        return false;
                    }
                }
            }
    The other thing we need to do, is create a check for when the item is on the Mobile. This includes whether it is equipped and inside the player's backpack.

    Mobile.cs
    Clear the return true statement already existing in CheckItemUse and replace it with the following:
    Code:
                if ( Core.TickCount - from.NextActionTime >= 0 )
                {
                    from.NextActionTime = Core.TickCount + Mobile.ActionDelay;
                    return true;
                }
                else
                {
                    from.SendActionMessage();
                    return false;
                }
    
    Finally, in Mobile.cs, you can control what the action delay is by changing

    Code:
    private static int m_ActionDelay = (number);
    To what you want the action delay to be. I use 1000 on my server, which is 1 second - an OSI accurate number. You can use whatever you want.

    Particular things do not use these functions, such as snooping. Snooping is not a regular "OnDoubleClick" function, so you have to add it in manually if you want it. Hope this helps someone who wanted a global action delay on items like I did. It would be worthwhile doing a search to check that action delays are not applied anywhere else in your scripts, or they will clash and make the particular item unusable due to the clashing of NextActionTime checks. A search for "NextActionTime" should reveal this.

Share This Page