Full Version : Call XmlLoad (and other XMLSpawner commands)
xmlspawner >>Scripting Support >>Call XmlLoad (and other XMLSpawner commands)
<< Prev | Next >>
oak- 01-19-2006
How could I call XmlLoad from a script... I've been playing around a bit with constructions like Server.Commands.XmlLoad or Server.Engines.XmlSpawner2.XmlLoad but can't seem to accomplish it.
ArteGordon- 01-19-2006
XmlSpawner.XmlLoadFromFile(string filename, string SpawnerPrefix, bool loadnew, out int processedmaps, out int processedspawners)
should do it. There are a number of different overloads of that available as well.
oak- 01-19-2006
hmm, ok. That should load a saved xmlspawner definition, yes? What do processedmaps and processedspawners do? I went through xmlspawner2.cs and it seems they usually are set to 0.
I'm trying to see if I can just load a saved spawner xml def file such as the jeweler2.xml or one I save in-game thru xmlfind, via a script.
ArteGordon- 01-19-2006
you dont need to worry about those. They just return some status information about the number of spawners loaded from the file.
You would call it like this
int processedspawners;
int processedmaps;
string filename = "jeweler.xml";
XmlSpawner.XmlLoadFromFile(filename, null, false, out processedmaps, out processedspawners)
oak- 01-20-2006
Ahhh, I had loadnew as true...that may have prevented it from working. I'll try it when I get home tonight. Thank you!
ArteGordon- 01-20-2006
another thing to remember is that those methods wont automatically look for files in the default folders like Spawns. If you want it to do that, then first make a call to the LocateFile method, and use the result of that as your filename
string filename = XmlSpawner.LocateFile("jeweler.xml");
XmlSpawner.XmlLoadFromFile( filename, null, false, out processedmaps, out processedspawners);
that will search for the file in the default locations and return the full path to it, and then you can pass that to the load file method.
Setting the loadnew to true or false just determines whether it should replace any existing spawners that were previously loaded via that file, or whether it should create new ones and leave the old ones there. Set it to false to replace them, set it to true to add them.
oak- 01-20-2006
Aha! I imagine it was that the script couldn't find the filename...very good point. I hadn't thought of that. My code was probably fine except for the fact it couldn't locate the file...hmm, mebbe I have a copy of runuo here somewhere on my work computer...I wanna check this out. loadtrue would need to be true in my case...since I am attempting to create an xmlspawner
ArteGordon- 01-20-2006
yeah, that would be my guess too.
oak- 01-20-2006
hmmm, must be something more to do.
I had to make the spawner prefix equal something since a null value crashed the server on line 5235 in xmlspawner2.cs....
xmlspawner.locatefile appears to work fine...I write out the value of filename to the console and it shows it as "Spawner/jeweler2.cs" ... but the actual spawner never appears. It works fine with [xmload jeweler2.xml
code:

CODE
public override void OnSpeech( SpeechEventArgs e ) { if ( !e.Handled ) { e.Handled = true;
Mobile from = e.Mobile;
int[] keywords = e.Keywords;
if ( e.Speech.ToLower().Equals("loadit"))
{
int processedmaps = 0;
int processedspawners = 0;
string filename = XmlSpawner.LocateFile("jeweler2.xml");
Console.WriteLine ("filename is: " + filename);
XmlSpawner.XmlLoadFromFile( filename, "qu", true, out processedmaps, out processedspawners);
SayTo(from,"Alrighty, there you go!");
}
else
{
SayTo(e.Mobile,"Umm, didja forget? Say 'loadit'.");
}
}
else
{
base.OnSpeech( e );
}
}

ArteGordon- 01-20-2006
ah ok. Yeah, make the spawner prefix just an empty string "" or even better string.Empty instead of a null string. That way it will load all of the spawners that are defined in the file.
If you give it a value like "qu", then it will only load the spawners with names that begin with "qu", and since you dont have any, you dont load any.
oak- 01-20-2006
Aha! That makes sense and certainly does the job...worked like a charm. Thank you so much.
ArteGordon- 01-20-2006
just note that because you are calling it with the loadnew flag set to true
XmlSpawner.XmlLoadFromFile( filename, "qu", true, out processedmaps, out processedspawners);
everytime you call this you will add a new spawner instead of just replacing an existing one (or adding one if none already exist).
You could also use one of the overloads that lets you load the spawner in at a specific location (like where the person issuing the command is at the moment) instead of the default location defined in the file by passing it a value of true for the loadrelative flag, and then giving it a coordinate and a map location.
public static void XmlLoadFromFile(string filename, string SpawnerPrefix, Mobile from, Point3D fromloc, Map frommap, bool loadrelative, int maxrange, bool loadnew, out int processedmaps, out int processedspawners)