Vorspire
Knight
[RUO 2.0+] Script Tracker
@"Script Package Tracker",
@"1.0.0.0",
@"GNU/GPL",
@"RunUO 2.0",
@"Vorspire",
@"Rhovanion-PK: CORE",
@"http://www.rpk-uo.com",
@"A simple way for any RunUO developer to quickly access methods designed to make handling your scripts a little easier.",
@"Provides ways to check if a certain class exists and keeps track of all Package Entries including some extended information and a simple UI for ease of access."
The Script Tracker was designed for developers and should be redistributed with any script that references this package, incase the end-user doesn't have it installed.
The above code outputs:
NOTE: CreateInstance also supports parameters (params object[] args) and will automatically match the parameters to the correct constructor for the object you are trying to create.
I hope anyone finds this useful, it could also be improved in many ways, I just don't have the time right now
Regards
@"Script Package Tracker",
@"1.0.0.0",
@"GNU/GPL",
@"RunUO 2.0",
@"Vorspire",
@"Rhovanion-PK: CORE",
@"http://www.rpk-uo.com",
@"A simple way for any RunUO developer to quickly access methods designed to make handling your scripts a little easier.",
@"Provides ways to check if a certain class exists and keeps track of all Package Entries including some extended information and a simple UI for ease of access."
The Script Tracker was designed for developers and should be redistributed with any script that references this package, incase the end-user doesn't have it installed.
Code:
using System;
using Server;
using Server.Misc;
using Server.Items;
namespace Server
{
public class ScriptTrackerUsage
{
//Using the static Initialize method.
public static void Initialize()
{
ScriptTracker.WriteLine("Script tracker Example output:");
//Type the name of any Class, even if it doesn't exist.
string className = "Longsword";
//Check to see if the class name exists
if (ScriptTracker.IsInstalled(className))
{
//Yes, it exists
ScriptTracker.WriteLine("THE {0} IS INSTALLED!", className);
//Let's get the Package Entry so we can manipulate it
PackageEntry entry = ScriptTracker.GetEntry(className);
//If the entry has constructors, (do not confuse with the Constructible Attribute)
if (entry.Constructible)
{
//Yes, we can construct the object
ScriptTracker.WriteLine("THE {0} IS CONSTRUCTIBLE!", className);
//Create an instance of the object.
//Be careful though, you can not declare or use the Class Name of the object you are searching for,
//because it may not be installed and *will* cause compilation errors.
//If you know that the Type you are searching for has an inherited parent,
//that is default in RunUO, for example; BaseWeapon, BaseArmor, BaseCreature, etc...
//you can still declare those Classes instead.
object instance = entry.CreateInstance();
//If the object couldn't be constructed...
if (instance == null)
{
ScriptTracker.WriteLine("THE {0} IS NULL!", instance.ToString());
}
//The object was successfully constructed
else
{
ScriptTracker.WriteLine("THE {0} IS NOT NULL!", instance.ToString());
}
//We don't need it anymore, or do we? - You decide...
if (instance is Item)
{
//But for now, this example is complete, so let's trash it!
((Item)instance).Delete();
}
}
//The class contains no constructors, (do not confuse with the Constructible Attribute)
else
{
ScriptTracker.WriteLine("THE {0} IS NOT CONSTRUCTIBLE!", className);
}
ScriptTracker.WriteLine("End Script tracker Example output.");
}
}
}
}
The above code outputs:
Code:
[Script Tracker] Script tracker Example output:
[Script Tracker] THE Longsword IS INSTALLED!
[Script Tracker] THE Longsword IS CONSTRUCTIBLE!
[Script Tracker] THE 0x40000002 "Longsword" IS NOT NULL!
[Script Tracker] End Script tracker Example output.
NOTE: CreateInstance also supports parameters (params object[] args) and will automatically match the parameters to the correct constructor for the object you are trying to create.
I hope anyone finds this useful, it could also be improved in many ways, I just don't have the time right now
Regards