Full Version : Individual Type Amounts vs MaxCount
xmlspawner >>XMLSpawner - Discussion >>Individual Type Amounts vs MaxCount


<< Prev | Next >>

roadmaster- 10-02-2006
Ok, what i have done is written a script that will allow me to convert PremiumSpawners into XmlSpawners either by Targeting a specific spawner or by converting every PremiumSpawner in World.Items.Values.

my script works in general but ive noticed a small difference in how the PremiumSpawner and the XmlSpawner handle the individual typenames added to the spawner in regards to the Counts.

re...

PremiumSpawner's if you create a spawner with 3 typenames and you set each value to say 3, so a total of nine. then if you hit respawn several times it will respawn with different amounts each time (randomly) [assuming that the total amount to make has been set to 9]

bird 3
cat 3
dog 3

then after a respawn it randomly would change to like so:

bird 0
cat 5
dog 4

then again

bird 1
cat 3
dog 6

with XmlSpawner's if i do the same thing it always give the same amount the script originally set it to. the only way ive been able to change it is by manually decreasing the max value at the bottom of the spawner.

i first set them to:

bird 3 3
cat 3 3
dog 3 3

this gives a total max count

spawner 9 9

now if i reduce the spawner max value of 9 to 5 so that it looks like this:

bird 3 3
cat 3 3
dog 3 3

spawner 9 5

then respawn i get:

bird 2 3
cat 3 3
dog 0 3

spawner 5 5

then respawn again:

bird 2 3
cat 0 3
dog 3 3

spawner 5 5

so at this point the count is changing while the Max is staying the same

basically what im wanting to do is to set the Total Max amount for the spawner to produce, and have it spawn randomly between the entries, which works fine if by manually manipulating them like i did above, the problem comes in when i convert them by the script it automatically assigns a value of 1 to each typename's count and Max then it assigns the Total amount to the spawner Max value so it would look like this

bird 1 1
cat 1 1
dog 1 1

spawner 3 9

now if i respawn that it just keeps doing the same

bird 1 1
cat 1 1
dog 1 1

spawner 3 9

so after all of this my question is how can i set it in my script so that the XmlSpawner will set the Max value of the individual typename's to a predetermined value as passed in from the script, then i would need to do the same with the first count of the individual entry?

Is this possible the way the current version of XmlSpawner is set up?

would it help if i posted my script for you to look at?

was it alright for me to post this here or should i have gone to the RunUo forums script support?

I figured you would probably be the one to answer me if i had so thought id just cut out the middle man so to speak. smile.gif


roadmaster

ArteGordon- 10-02-2006
QUOTE

PremiumSpawner's if you create a spawner with 3 typenames and you set each value to say 3, so a total of nine. then if you hit respawn several times it will respawn with different amounts each time (randomly) [assuming that the total amount to make has been set to 9]

bird 3
cat 3
dog 3

then after a respawn it randomly would change to like so:

bird 0
cat 5
dog 4

then again

bird 1
cat 3
dog 6


If you wanted an xmlspawner to behave in that way, what you would do would be to assign each individual entry a maxcount that was the same as the spawner maxcount.

bird 9
cat 9
dog 9

spawner maxcount=9

roadmaster- 10-08-2006
QUOTE

If you wanted an xmlspawner to behave in that way, what you would do would be to assign each individual entry a maxcount that was the same as the spawner maxcount.


Hi Arty, Ive been looking through this for a couple days now, is there an easy way to do this that im just not seeing?

I didnt see any property that jumped out at me that i thought might do that. I originally was going with the following code:

CODE

XmlSpawner xml = new XmlSpawner();

for (int g = 0; g < creatureNames.Count; g++)
{
   string name = (String)creatureNames[g];
   XmlSpawner sp = xml;
   sp.AddSpawn = name;
   sp.MaxCount = npcMaxCount;
   xml = sp;
}

xml.Team = team;
if (xml.MaxCount < npcMaxCount)
   xml.MaxCount = npcMaxCount;
if (xml.StackAmount < xml.MaxCount)
   xml.StackAmount = xml.MaxCount;
if (homerange > xml.HomeRange)
   xml.HomeRange = homerange;
if (spawnrange > xml.SpawnRange)
   xml.SpawnRange = spawnrange;

xml.MoveToWorld(loc, map);
if (xml.Parent == null)
xml.Respawn();


that code worked fine with the exception that, it leaves the individual max amounts to the default value of 1. When i couldnt find a property to assign, i changed how i was trying to do it and tried do it like so:

CODE

XmlSpawner.SpawnObject[] so = new XmlSpawner.SpawnObject[creatureNames.Count];

for (int i = 0; i < creatureNames.Count; i++)
{
   so[i] = new XmlSpawner.SpawnObject(creatureNames[i], npcMaxCount);
}

           
Guid SpawnId = Guid.NewGuid();
string spawnername = String.Format("Spawner{0}", DateTime.Now);
XmlSpawner.TODModeType defTODMode = XmlSpawner.TODModeType.Realtime;
int x = 0;
int y = 0;
int z = 0;

XmlSpawner spawner = new XmlSpawner(SpawnId, x, y, 0, 0, spawnername, npcMaxCount, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(0), -1, 0x1F4, 1, 0, homerange, false, so, TimeSpan.FromMinutes(0), TimeSpan.FromMinutes(0), TimeSpan.FromMinutes(0), TimeSpan.FromMinutes(0), null, null, null, null, null, null, null, null, null, 1, null, false, defTODMode, 1, false, -1, null, false, false, false, null, TimeSpan.FromHours(0), null, false, null);

spawner.Team = team;
if (spawner.MaxCount < npcMaxCount)
   spawner.MaxCount = npcMaxCount;
if (homerange > spawner.HomeRange)
   spawner.HomeRange = homerange;
if (spawnrange > spawner.SpawnRange)
   spawner.SpawnRange = spawnrange;

spawner.MoveToWorld(loc, map);
spawner.Respawn();


with this code i get the following error.

QUOTE

RunUO - [www.runuo.com] Version 2.0, Build 2357.32527
Core: Running on .NET Framework Version 2.0.50727
Scripts: Compiling C# scripts...failed (1 errors, 4 warnings)
Errors:
+ Custom/DeveloperScripts/PremiumSpawnerConverter.cs:
    CS1502: Line 168: The best overloaded method match for 'Server.Mobiles.XmlSpawner.SpawnObject.SpawnObject(string, int)' has some invalid arguments CS1503: Line 168: Argument '1': cannot convert from 'object' to 'string'


the error is refering to this line:

CODE

so[i] = new XmlSpawner.SpawnObject(creatureNames[i], npcMaxCount);


im trying to pass in the PremiumSpawners ArrayList of typenames which i believe is just a bunch of strings, to my ArrayList creatureNames, which works fine.

CODE

foreach (Item premiumSpawner in itemsToRemove)
{
   PremiumSpawner sp = (PremiumSpawner)premiumSpawner;
   CreateSpawner(from, sp.CreaturesName, sp.Location, sp.Map, sp.HomeRange, sp.SpawnRange, sp.Count, sp.Team);
   premiumSpawner.Delete();        
}


my problem now is im not sure how to convert this. Im sure its easy im just not seeing it.


roadmaster

roadmaster- 10-08-2006
Why is is 90% of the time after ive requested help with something i figure out what i was doing wrong? Jeez after all that work on the prevoius post.

this is what fixed it, changed this:

CODE

for (int i = 0; i < creatureNames.Count; i++)
{
  so[i] = new XmlSpawner.SpawnObject(creatureNames[i], npcMaxCount);
}


to this:

CODE

for (int i = 0; i < creatureNames.Count; i++)
{
   string name = (String)creatureNames[i];
   so[i] = new XmlSpawner.SpawnObject(name, npcMaxCount);
}



God i feel so stupid smile.gif


roadmaster