::Multiple Creature Spawn::
This script spawns multiple creature (of one type), with special effects, in
an area radius.
This script is written as a function so it can be used very easily througout
your modules.
To implement it create a new script, let's call it cr_spawn. Remove all the
code in this script and replace it with the following
NWScript:
void CreateMultipleCreatures(int iNumberOfCreatures, int sSphereSize, string sTemplate, object oSpawnObject, int iEffect, int bInstantAttack = FALSE, int bOnceOnly = TRUE)
{
if((bOnceOnly == TRUE && (GetLocalInt(oSpawnObject, "SPAWN_ONCE") != 1)) || (bOnceOnly == FALSE))
{
location oMyLocation = GetLocation(oSpawnObject);
vector oMyVector = GetPosition(oSpawnObject);
int iCount = 0;
while(iCount < iNumberOfCreatures)
{
vector oNewVector = oMyVector;
int xOffSet = Random(sSphereSize);
int yOffSet = Random(sSphereSize);
if(Random(2) == 1)
{
xOffSet = xOffSet * -1;
}
if(Random(2) == 1)
{
yOffSet = yOffSet * -1;
}
oNewVector.x = oNewVector.x + xOffSet;
oNewVector.y = oNewVector.y + yOffSet;
location oNewLocation = Location(GetAreaFromLocation(oMyLocation), oNewVector, 0.0);
object oMonster = CreateObject(OBJECT_TYPE_CREATURE, sTemplate, oNewLocation, FALSE);
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(iEffect), oNewLocation, 0.5);
if(bInstantAttack == TRUE)
{
object oAttack = GetLastOpenedBy();
AssignCommand(oMonster, ActionAttack(oAttack));
}
iCount = iCount + 1;
}
SetLocalInt(oSpawnObject, "SPAWN_ONCE", 1);
}
}
OK, now save that script.
Here's a breakdown of the parameters:
iNumberOfCreatures := the number of creatures to spawn
sSphereSize := the radius of the sphere into which the creatures will spawn.
For example, if you make this 5 all creatures will appear within 5 meters of
the object. If it's 20 all creatures will appear within 5 meters of the
object.
sTemplate := the creature template. this is the same as the default creature
tag or the Blueprint ResRef
oSpawnObject := the object you want the creatures to spawn around. If it's
the object that's being opened you can just use OBJECT_SELF
iEffect := the effect constant for the effect you want to use when the
creature is created
bInstantAttack := FALSE by default, if this is set to true, it'll make the
creatures attack the user immediatly. If it's FALSE they will attack the
first enemy they percieve
bOnceOnly := default is TRUE. If set to TRUE, creature will only be spawned
from the object once. IF false, they'll be spawned every time the script is
triggered by the same object.
Now, lets say you have a chest, and you want some creatures to spawn when a
PC opens it.
Place the following in the OnOpen event:
NWScript: #include "cr_spawn"
void main()
{
CreateMultipleCreatures(3, 10, "NW_GOBLINA", OBJECT_SELF, VFX_FNF_SUMMON_UNDEAD, FALSE, FALSE);
}
When a PC opens the chest 3 goblins will spawn, in random locations within
10 meters of the chest. When they spawn the Summon Undead effect will
appplied to where they spawn. They will attack the nerest enemy they see and
the next time the chest is opened, this whole process will be repeated.
Play around with it.
|