Re-posting this here per request:
NWScript:
void SpawnCreatures(int Mode, string ResRef, string SpawnWP,int Count, int NumWP);
void main()
{
int PCLevels = 0;
int NumPCs = 0;
int CurrPCLvl = 0;
string sPCLevels;
string sNum;
object oPC = GetFirstPC();
while (oPC!=OBJECT_INVALID)
{
CurrPCLvl = GetLevelByPosition(1,oPC) + GetLevelByPosition(2,oPC) + GetLevelByPosition(3,oPC);
PCLevels += CurrPCLvl;
oPC=GetNextPC();
NumPCs++;
sPCLevels = IntToString(PCLevels);
sNum = IntToString(NumPCs);
}
string MonOne = "crhalf" ; float MLOne = 0.5;
string MonTwo = "crone" ; float MLTwo = 0.5;
string MonThree = "crtwo" ; float MLThree = 0.5;
string MonFour = "crfour" ; float MLFour = 0.5;
float Difficulty = 10.0;
int SOne;int STwo;int SThree;int SFour;
float TL = IntToFloat(PCLevels);
float Temp;
TL = TL * Difficulty;
if (MLFour <= (TL / 4.0))
{
Temp = (TL / 4.0) / MLFour;
SFour = FloatToInt(Temp);
TL = TL - (SFour * MLFour);
}
if (MLThree <= (TL / 3.0))
{
Temp = (TL / 3.0) / MLThree;
SThree = FloatToInt(Temp);
TL = TL - (SThree * MLThree);
}
if (MLTwo <= (TL / 2.0))
{
Temp = (TL / 2.0) / MLTwo;
STwo = FloatToInt(Temp);
TL = TL - (STwo * MLTwo);
}
Temp = TL / MLOne;
SOne = FloatToInt(Temp);
SpawnCreatures(0, MonOne, "SP_01", SOne, 4);
SpawnCreatures(1, MonTwo, "SP", STwo, 4);
SpawnCreatures(2, MonThree, "SP", SThree, 4);
SpawnCreatures(3, MonFour, "SP", SFour, 4);
}
void SpawnCreatures (int Mode, string ResRef, string SpawnWP, int Count, int NumWP)
{
if (Mode == 0)
{
int curCnt = 0;
object WP = GetWaypointByTag(SpawnWP);
location Loc = GetLocation(WP);
for (curCnt = 0; curCnt < Count; curCnt++)
{
CreateObject(OBJECT_TYPE_CREATURE, ResRef, Loc);
}
}
if (Mode == 1)
{
int Spread = 0;
int curCnt = 0;
string WPT;
object WP;
location Loc;
for (curCnt = 0; curCnt < Count; curCnt++)
{
Spread++;
if (Spread > NumWP)
{
Spread = 1;
}
WPT = SpawnWP + "_0" + (IntToString(Spread));
WP = GetWaypointByTag(WPT);
Loc = GetLocation(WP);
CreateObject(OBJECT_TYPE_CREATURE, ResRef, Loc);
}
}
if (Mode == 2)
{
int Spread;
int curCnt = 0;
string WPT;
object WP;
location Loc;
for (curCnt = 0; curCnt < Count; curCnt++)
{
Spread = (Random(NumWP) + 1);
WPT = SpawnWP + "_0" + (IntToString(Spread));
WP = GetWaypointByTag(WPT);
Loc = GetLocation(WP);
CreateObject(OBJECT_TYPE_CREATURE, ResRef, Loc);
}
}
if (Mode == 3)
{
int Spread = (Random(NumWP) + 1);
int curCnt = 0;
string WPT = SpawnWP + "_0" + (IntToString(Spread));
object WP = GetWaypointByTag(WPT);
location Loc = GetLocation(WP);
for (curCnt = 0; curCnt < Count; curCnt++)
{
CreateObject(OBJECT_TYPE_CREATURE, ResRef, Loc);
}
}
}
I tried to document it pretty well, but if anyone has any questions,
feel free to drop me a message.
What this script allows you to do, is set up a pool of up to four
monsters to draw from. You have to specify their CR or HD, whichever way
you want to go.
The script runs through and gets the party's level total, multiplies by
a difficulty variable, generates a group based on the result.
It tries to spread the HD evenly among the four monster types, ie: if it
needs to generate 16 HD worth of monsters, it will make four groups,
each with 4HD of monsters. Any remainder (say one of the groups above
was a 3HD monster) gets applied to the next lower group...
The creatures are then spawned. SpawnCreatures() can have four modes:
Mode 0 - Spawn all the creatures at a given waypoint
Mode 1 - Spawn the creatures and spread them out as evenly as possible
over up to 9 wayppoints, named XXX_01 through XXX_09.
Mode 2 - Similar to Mode 1, but spread the monsters at random
Mode 3 - Similar to Mode 0, but a range of WPs is given as in Mode 1 &
2, the whole group spawns at this waypoint.
Well, I enjoyed making this script, and it is just what I wanted for my
encounters to be. If you don't like it, change it to taste, it is pretty
well commented. Hope someone finds it useful.
_________________
Ranger Allan
-Lost? Of course I'm not lost! I'm just not sure where we are...
|