help with mob spawns

06/08/2010 01:16 macht102#1
i need help fixing this

Loaded 254 portals.
Loaded 1019 NPCs.
Loaded 40 Mobs.
Loaded 11147 items.
Loaded 172 Mob Spawns.
System.ArgumentOutOfRangeException: 'minValue' cannot be greater than maxValue.
Parameter name: minValue
at System.Random.Next(Int32 minValue, Int32 maxValue)
at COServer_Project.Mobs.SpawnAllMobs() in D:\CONQUER ONLINE SERVER STUFF\COServerProject\COServerProject1\COServerPro ject\Entities.cs:line 207
Loading Plus info done.

all i know is that with that error i cannot spawn more mobs

and on that line 207 it is

short spawn_x = (short)General.Rand.Next(Convert.ToInt16(ThisSpawn[3]), Convert.ToInt16(ThisSpawn[5]));



the whole section is

for (int n = 0; n < Convert.ToInt32(ThisSpawn[2]); n++)
{
uint UID = (uint)General.Rand.Next(400000, 500000);
short spawn_x = (short)General.Rand.Next(Convert.ToInt16(ThisSpawn[3]), Convert.ToInt16(ThisSpawn[5]));
short spawn_y = (short)General.Rand.Next(Convert.ToInt16(ThisSpawn[4]), Convert.ToInt16(ThisSpawn[6]));
while (AllMobs.Contains(UID))
{
UID = (uint)General.Rand.Next(400000, 500000);
}
SingleMob Mob = new SingleMob(spawn_x, spawn_y, Convert.ToInt16(ThisSpawn[7]), uint.Parse(ThisMob[3]), uint.Parse(ThisMob[3]), short.Parse(ThisMob[6]), short.Parse(ThisMob[7]), UID, ThisMob[2], int.Parse(ThisMob[1]), short.Parse(ThisMob[4]), (byte)General.Rand.Next(8), byte.Parse(ThisMob[5]));


AllMobs.Add(UID, Mob);

MobsSpawned++; ;
}


thats all the info i know about that the problem occurs at
06/08/2010 01:56 s.bat#2
Code:
for (int n = 0; n < Convert.ToInt32(ThisSpawn[2]); n++)
{
    uint UID = (uint)General.Rand.Next(400000, 500000);
    short xMin = Convert.ToInt16(ThisSpawn[3]);
    short xMax = Convert.ToInt16(ThisSpawn[5]);
    if (xMin > xMax)
    {
        short temp = xMin;
        xMin = xMax;
        xMax = temp;
    }
    short spawn_x = (short)General.Rand.Next(xMin, xMax);
    short yMin = Convert.ToInt16(ThisSpawn[4]);
    short yMax = Convert.ToInt16(ThisSpawn[6]);
    if (yMin > yMax)
    {
        short temp = yMin;
        yMin = yMax;
        yMax = temp;
    }
    short spawn_y = (short)General.Rand.Next(yMin, yMax);
    while (AllMobs.Contains(UID))
    {
        UID = (uint)General.Rand.Next(400000, 500000);
    }
    SingleMob Mob = new SingleMob(spawn_x, spawn_y, Convert.ToInt16(ThisSpawn[7]), uint.Parse(ThisMob[3]), uint.Parse(ThisMob[3]), short.Parse(ThisMob[6]), short.Parse(ThisMob[7]), UID, ThisMob[2], int.Parse(ThisMob[1]), short.Parse(ThisMob[4]), (byte)General.Rand.Next(8), byte.Parse(ThisMob[5]));
    AllMobs.Add(UID, Mob);
    MobsSpawned++; 
}
It's important to be able to read and understand the exceptions or errors that get thrown from methods. The issue in this case was that the contract for the System.Random.Next(Int32 minValue, Int32 maxValue) method is that the maxValue cannot be smaller than the minValue, and it was in your case. The code I've added checks to see if the minimum x range for the monster is not greater than the maximum x range, and the same for the y range, and if it is, then those ranges are switched. This should hopefully solve your problem. This was simple, and you should have be able to do it yourself. In the future, please take the time to make an attempt at fixing your problems, and if you're still having problems, show us what you've done to try and fix your issue, and we will help you from there. Don't expect someone to do the code for you every time.
06/10/2010 21:26 gerble93#3
The only problem he had is that one of his MinX was bigger than his MaxX point.. When he put in the mob spawn..
06/10/2010 21:59 s.bat#4
Quote:
Originally Posted by gerble93 View Post
The only problem he had is that one of his MinX was bigger than his MaxX point.. When he put in the mob spawn..
Yes, you've just reiterated what I've said with less detail. Instead of the OP searching through that list, the problem was solved using what they've provided. A rectangle is still a rectangle, even if its bounds are not ordered from least to greatest, therefore the fix was perfectly acceptable.