Full Version : Commands
xmlspawner >>Scripting Support >>Commands


<< Prev | Next >>

Odee- 08-07-2006
Hey there

Im thinking about making a command that picks up projectiles that have been fired and are laying on ground.

Is there a tutorial on making commands or anything? Or could somone explaing?

Any help would be greatly appreciated. Thanks smile.gif

-- Odee --

ArteGordon- 08-07-2006
here is a basic command framework that you can start with

CODE

using System;
using System.Text;
using Server;
using Server.Items;
using Server.Network;
using System.Collections;
using System.Reflection;
using Server.Targeting;
using Server.Mobiles;
using Server.Multis;
using Server.Engines.XmlSpawner2;
using Server.Gumps;
using Server.Engines.Help;
using Server.Commands;
using Server.Commands.Generic;
using Server.Accounting;


namespace Server.Scripts.Commands
{
   public class GenericCommand
   {

       public static void Initialize()
       {
           CommandSystem.Register("g", AccessLevel.GameMaster, new CommandEventHandler(GenericCommand_OnCommand));
       }

       public class GenericTarget : Target
       {

           public GenericTarget()
               : base(30, true, TargetFlags.None)
           {
               CheckLOS = false;
           }
           protected override void OnTarget(Mobile from, object targeted)
           {
               if (from == null || targeted == null) return;

               if (targeted is Mobile)
               {
                   Mobile m = (Mobile)targeted;

                   // put your code for targeting a mobile here

               }
               else
                   if (targeted is Item)
                   {
                       Item i = (Item)targeted;

                       // put your code for targeting an item here
                   }
           }
       }

       [Usage("g")]
       public static void GenericCommand_OnCommand(CommandEventArgs e)
       {
           if (e == null || e.Mobile == null) return;

           Mobile from = e.Mobile;

           // if you want to use targeting then uncomment this line
           //from.Target = new GenericTarget();

           // if you just want to do something when the command is executed, then add your code here

       }
   }
}


Odee- 08-08-2006
CODE
using System;
using System.Text;
using Server;
using Server.Items;
using Server.Network;
using System.Collections;
using System.Reflection;
using Server.Targeting;
using Server.Mobiles;
using Server.Multis;
using Server.Engines.XmlSpawner2;
using Server.Gumps;
using Server.Engines.Help;
using Server.Commands;
using Server.Commands.Generic;
using Server.Accounting;


This is a guess but out of all of these I would want to use?...:

CODE

using Server;
using System;
using Items;
using Collections;
using Server.Commands;


Could you explain to me what all of the tags mean? And If anything that I listed above is wrong please correct me? I really wanna learn about commands happy.gif I will also have a look at the [sort command.

Thanks smile.gif


happy.gif

ArteGordon- 08-08-2006
those are just namespaces where the compiler will look for methods that you refer to.
By adding the line

using Server;

You can refer to methods like

Utility.Random

instead of the fully qualified name of

Server.Utility.Random

There is no real harm in having those using statements there. It just gives you a more general template for making commands that might refer to things that are defined in those namespaces.

You can always remove what you dont think you will need.

Odee- 08-10-2006
Ahh okay.

Somone commented on my idea to look at hordeminion.cs . Would this help a bit?

Thanks for the feedback dude smile.gif