Full Version : Delay between Auto Macro Check.
xmlspawner >>Scripting Support >>Delay between Auto Macro Check.


<< Prev | Next >>

Galfaroth- 01-29-2006
Hi there I have a problem and I see community is much more friendly than on runuo.com. Here is part of my SkillCheck.cs It sends gump with macrocheck to player who train skills. How to make it send 2nd gump more than after one minute? E.G Player is tailoring. After random time MacroCheck(MC) apears(it is done). How to make another MC appear after one minute (+random) from last. In other words. How to make delay between gumps(My problem is that there can two MC appear in 6 secounds and players go to jail).

CODE

  NetState fromState = from.NetState;
  if ( from is PlayerMobile && AntiMacroCode && UseAntiMacro[skill.Info.SkillID] && fromState != null )
   {
      switch (Utility.Random( 50 ))
      {
      case 0:
      {
       JailSystem.macroTest( from, from ); //here gump appear
       break;
      }
      case 1:
      { break; }
     }
   }


ArteGordon- 01-29-2006
you will need to add a variable to your playermobile to keep track of the last time you sent a gump.
Then you can check that time before opening a new one.

Add this to your PlayerMobile class

CODE


 public DateTime LastMacroGump = DateTime.MinValue;


and then in your macro gump code, add this

QUOTE

  NetState fromState = from.NetState;
  if (from is PlayerMobile && AntiMacroCode && UseAntiMacro[skill.Info.SkillID] && fromState != null && DateTime.Now > ((PlayerMobile)from).LastMacroGump + TimeSpan.FromMinutes(1.0))
  {
    switch (Utility.Random(50))
    {
    case 0:
      {

      ((PlayerMobile)from).LastMacroGump = DateTime.Now;

      JailSystem.macroTest(from, from); //here gump appear
      break;
      }
    case 1:
      { break; }
    }
  }
  }

Galfaroth- 01-29-2006
Damn... Arte where did you learn this :]. You're my GoD. (btw. check topic about quests (i added two questions to my list). Thanks so lot!

Galfaroth- 01-31-2006
Now everytime player goes to jail (even macrocheck or me send him) crashes:
CODE
Exception:
System.ArgumentOutOfRangeException: minValue cannot be greater than maxValue.
Parameter name: minValue
  at System.Random.Next(Int32 minValue, Int32 maxValue)
  at Server.Scripts.Commands.JailSystem.lockupMobile(Mobile m, Boolean useFootWear) in c:\FTP\Server\Scripts\WOG\Komendy\Wiezienie\Jail.cs:line 1020
  at Server.Scripts.Commands.JailSystem.lockupMobile(Mobile m) in c:\FTP\Server\Scripts\WOG\Komendy\Wiezienie\Jail.cs:line 1007
  at Server.Scripts.Commands.JailSystem.newJailingFromGMandPlayer(Mobile from, Mobile m) in c:\FTP\Server\Scripts\WOG\Komendy\Wiezienie\Jail.cs:line 1550
  at Server.Scripts.Commands.JailTarget.OnTarget(Mobile from, Object targeted) in c:\FTP\Server\Scripts\WOG\Komendy\Wiezienie\Jail.cs:line 1668
  at Server.Targeting.Target.Invoke(Mobile from, Object targeted)
  at Server.Network.PacketHandlers.TargetResponse(NetState state, PacketReader pvSrc)
  at Server.Network.MessagePump.HandleReceive(NetState ns)
  at Server.Network.MessagePump.Slice()
  at Server.Core.Main(String[] args)

ArteGordon- 01-31-2006
in your Jail.cs code you are making an invalid call to the Random method at the line indicated

at System.Random.Next(Int32 minValue, Int32 maxValue)
at Server.Scripts.Commands.JailSystem.lockupMobile(Mobile m, Boolean useFootWear) in c:\FTP\Server\Scripts\WOG\Komendy\Wiezienie\Jail.cs:line 1020

Galfaroth- 01-31-2006
I don't know what is bad there(It's Cat's Jail scrypt). I restored Jail default Config and everything works.

ArteGordon- 01-31-2006
well, this line

CODE

  cell=(Point3D)cells[((new System.Random()).Next(0,cells.Count-1))];


will crash if cells.Count goes to zero. So this will happen any time you dont load in any cells.