Piotr

Member
Hi,
I got this nice script shared by someone some time ago, with DH having 2 modes: detecting and revealing. I mostly got it to work after a slight modification, but the problem is that there is no delay for using both commands, so players are now able to gain very quickly.
Can someone help me setting a delay of 6 seconds between using those commands, so it's impossible to spam them?


Here's the script:

Code:
using System;
using Server.Multis;
using System.Collections;
using Server.Mobiles;
using System.Collections.Generic;
using Server.Commands;


namespace Server.SkillHandlers
{
    public class CustomDetectHidden
    {

        public static void Initialize()
        {
            CommandSystem.Register("detect", AccessLevel.Player, new CommandEventHandler(Detection));
            CommandSystem.Register("reveal", AccessLevel.Player, new CommandEventHandler(Revealing));
        }

        [Usage("Detect")]
        [Description("Allows you to detect hidden creatures near you. Does not require line of sight.")]
        private static void Detection(CommandEventArgs e)
        {
            int range = 22;
            Mobile src = e.Mobile;
            double srcSkill = src.Skills[SkillName.DetectHidden].Value;
            bool detectedanyone = false;

            if (!src.CheckSkill(SkillName.DetectHidden, 0.0, 100.0))
                range = 0;

            if (range > 0)
            {
                ArrayList inRangeArray = new ArrayList();

                foreach (Mobile trg in src.GetMobilesInRange(range))
                {
                    if (trg is PlayerMobile)
                    {
                        PlayerMobile test = trg as PlayerMobile;

                        if (trg.Hidden && src != trg)
                        {
                            double ss = srcSkill + Utility.Random(21) - 10;
                            double ts = trg.Skills[SkillName.Hiding].Value + Utility.Random(21) - 10;
                            if ((src.AccessLevel >= trg.AccessLevel) && (ss >= ts))
                            {
                                detectedanyone = true;
                                Detecting(src, trg);
                                inRangeArray.Add(trg);
                            }
                        }
                    }
                }

                if (detectedanyone)
                    src.SendMessage("You detect someone nearby!");
                else
                    src.SendMessage("You didn't detect anyone nearby.");

                InternalTimer pause = new InternalTimer(src, inRangeArray);
                pause.Start();

            }
        }



        private static void Detecting(Mobile from, Mobile targ)
        {

            PlayerMobile pm = (PlayerMobile)targ;

            List<Mobile> list = pm.VisibilityList;

            list.Add(from);

            if (Utility.InUpdateRange(from, targ))
            {
                if (from.CanSee(targ))
                {
                    from.Send(new Network.MobileIncoming(from, targ));
                    //from.SendMessage("You have detected " + targ.Name);
                }
            }
        }

        [Usage("Reveal")]
        [Description("Reveals creatures that are hidden near you. Requires line of sight.")]
        private static void Revealing(CommandEventArgs e)
        {
            PlayerMobile m_From = e.Mobile as PlayerMobile;

            m_From.RevealingAction();

            Rev(e.Mobile, e.Mobile);
        }

        private static void Rev(Mobile src, object targ)
        {
            bool foundAnyone = false;

            Point3D p;
            p = ((Mobile)targ).Location;

            double srcSkill = src.Skills[SkillName.DetectHidden].Value;
            int range = (int)(srcSkill / 10.0);

            if (!src.CheckSkill(SkillName.DetectHidden, 0.0, 100.0))
                range /= 2;

            BaseHouse house = BaseHouse.FindHouseAt(p, src.Map, 16);

            bool inHouse = (house != null && house.IsFriend(src));

            if (inHouse)
                range = 22;

            if (range > 0)
            {
                foreach (Mobile trg in src.GetMobilesInRange(range))
                {
                    if (trg.Hidden && src != trg)
                    {
                        double ss = srcSkill + Utility.Random(21) - 10;
                        double ts = trg.Skills[SkillName.Hiding].Value + Utility.Random(21) - 10;

                        if ((src.AccessLevel >= trg.AccessLevel) && ((ss >= ts) || (inHouse && house.IsInside(trg))) && (src.InLOS(trg)))
                        {
                            trg.RevealingAction();
                            trg.SendLocalizedMessage(500814); // You have been revealed!
                            foundAnyone = true;
                        }
                    }
                }
            }

            if (!foundAnyone)
            {
                src.SendLocalizedMessage(500817); // You can see nothing hidden there.
            }
            else
                src.SendMessage("You find someone in the shadows!");
        }


        private class InternalTimer : Timer
        {
            private Mobile m_From;
            private ArrayList m_InRange;

            public InternalTimer(Mobile from, ArrayList inRange2) : base(TimeSpan.FromSeconds(10.0))
            {
                m_From = from;
                m_InRange = inRange2;
            }

            protected override void OnTick()
            {
                foreach (Mobile target in m_InRange)
                {
                    Mobile TargetMobile = target;
                    PlayerMobile TargetPlayerMobile = target as PlayerMobile;

                    TargetPlayerMobile.VisibilityList.Remove(m_From);

                    if (TargetMobile.Hidden && m_From != TargetPlayerMobile)
                    {
                        if (!m_From.CanSee(TargetPlayerMobile) && Utility.InUpdateRange(m_From, TargetMobile))
                            m_From.Send(TargetPlayerMobile.RemovePacket);
                    }
                }
                m_InRange.Clear();
            }
        }

    }
}
 
Last edited:
Nobody can give me a hand here?
I'm stuck here and really need a solution. If you could at least point me in some direction, because I don't know how to apply a delay between using both commands.
 
You could add something like
Code:
src.NextSkillTime = Core.TickCount + (int)TimeSpan.FromSeconds(10).TotalMilliseconds
 
Last edited:
Doesn't work either, here's what I get:

upload_2019-1-6_16-7-42.png

I've triend multiple different ways but still can't get it done.
Could you take a closer look into this and maybe send me the solution if you figure it out?
That would be of great help... Basically I want both commands to act like the skill was used, with a 6 second delay for any other skill usage.
 
My bad

src.NextSkillTime = Core.TickCount+ (int)TimeSpan.FromSeconds(10).TotalMilliseconds
 
Thanks a lot, that's a bit of progress!
Now using the commands prevents me from using another skill for 10 secs, but I can still spam the [reveal and [detect commands every second. We'd need the delay between using those commands as well. Would you know how to do it?

https://i.imgur.com/UmfGCOf.png
 
Sure add something like this too
Code:
if (Core.TickCount - src.NextSkillTime < 0)
{
    src.SendSkillMessage();
    return;
}
 
Nope, I take that back.
It works just fine! :D I'd just put it in the wrong line before.

@PyrO, thank you a lot. You're a life saver!
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back