Area Spawner:
Features:
- Spawns all types of objects
- Set time between spawns from 6 seconds to any number of hours
- Spawns in a rectangle of any size
- Holds up to 100 blueprints of objects
- Spawns infinite number of creatures
- Can set a range of objects per spawn
- Can set a total number of objects to spawn, then stop
- Any combination of conditions can be set (ex: Day, Night, Anything)
- Any combination of actions can be set for each object spawned (ex:
Follow, Attack)
- Can uncomment debug lines for help that tell you whats going on inside
the script
- Very easily edited script is very simple and longwinded for
readability
What can I do with these features:
- Spawn placables such as campfires at night that disapear when day
comes
- Spawn random loot over an area
- Spawn monsters around an npc or monster and tell them to follow
- Have an effect go off when each monster is spawned
Limitations, what can't I do:
- Spawn into an item (working on that)
- Spawn multiple types of objects with one script (need one for each
object type)
- Spawn time is rounded to the nearest number divisable by 6 ex: 6, 12,
18, 24
Directions (these can also be found at the end of the script below):
The script:
NWScript:
void SetPreferences()
{
SetLocalInt(OBJECT_SELF, "SpawnTime", 6);
SetLocalInt(OBJECT_SELF, "SpawnAreaHeight", 10);
SetLocalInt(OBJECT_SELF, "SpawnAreaWidth", 10);
SetLocalString(OBJECT_SELF, "FlagName", "TestSpawn");
SetLocalInt(OBJECT_SELF, "MaxNumObjects", 6);
SetLocalInt(OBJECT_SELF, "MinNumObjects", 5);
SetLocalInt(OBJECT_SELF, "MaxNumTotal", 10);
SetLocalInt(OBJECT_SELF, "ObjectType", OBJECT_TYPE_CREATURE);
SetLocalObject(OBJECT_SELF, "Target", OBJECT_SELF);
SetLocalInt(OBJECT_SELF, "NumberOfTemplates", 2);
SetLocalString(OBJECT_SELF, "Template1", "50_NW_DOG");
SetLocalString(OBJECT_SELF, "Template2", "50_NW_CHICKEN");
}
int SpawnConditions()
{
int iCondition;
iCondition = TRUE;
return iCondition;
}
void ObjectActions(object oSelectedObject)
{
}
void DestroyBadObjects(int iObjectType);
int CheckObject(object oSelectedObject);
int CheckTime();
int CheckTotalNumber();
int CountDeadObjects(int iObjectType);
int GetRandomMaxMinNumber();
int CreateObjects(int iObjectType, int iDeadObjects);
string GetTemplate();
location GetRandomLocation();
void main()
{
int iDeadObjects;
int iSpawnedObjects;
SetPreferences();
DestroyBadObjects(GetLocalInt(OBJECT_SELF, "ObjectType"));
if(CheckTime() == TRUE && SpawnConditions() == TRUE && CheckTotalNumber() == TRUE)
{
iDeadObjects = CountDeadObjects(GetLocalInt(OBJECT_SELF, "ObjectType"));
iSpawnedObjects = CreateObjects(GetLocalInt(OBJECT_SELF, "ObjectType"), iDeadObjects);
}
SetLocalInt(OBJECT_SELF, "TotalSpawnedObjects", (iSpawnedObjects+GetLocalInt(OBJECT_SELF, "TotalSpawnedObjects")));
}
void DestroyBadObjects(int iObjectType)
{
int iObjectCount;
string sSpawnFlag;
object oSelectedObject;
oSelectedObject = GetNearestObject(iObjectType, OBJECT_SELF, iObjectCount);
while(GetIsObjectValid(oSelectedObject))
{
if(GetIsDead(oSelectedObject) == FALSE)
{
if(CheckObject(oSelectedObject) == TRUE && SpawnConditions() == FALSE)
DestroyObject(oSelectedObject);
}
iObjectCount++;
oSelectedObject = GetNearestObject(iObjectType, OBJECT_SELF, iObjectCount);
}
}
int CheckObject(object oSelectedObject)
{
int iMatchesConditions;
iMatchesConditions = FALSE;
if(GetLocalString(oSelectedObject, "SpawnFlag") == GetLocalString(OBJECT_SELF, "FlagName"))
iMatchesConditions = TRUE;
return iMatchesConditions;
}
int CheckTotalNumber()
{
int iUnderTotal;
iUnderTotal = TRUE;
if(GetLocalInt(OBJECT_SELF, "MaxNumTotal") == -1)
return iUnderTotal;
else if(GetLocalInt(OBJECT_SELF, "TotalSpawnedObjects") != 0)
{
if(GetLocalInt(OBJECT_SELF, "MaxNumTotal") <= GetLocalInt(OBJECT_SELF, "TotalSpawnedObjects"))
iUnderTotal = FALSE;
}
else
SetLocalInt(OBJECT_SELF, "TotalSpawnedObjects", 1);
return iUnderTotal;
}
int CheckTime()
{
int iTime;
int iSpawnTime;
int iSpawnNow;
iSpawnNow = FALSE;
if(GetLocalInt(OBJECT_SELF, "Time") != 0)
{
iSpawnTime = GetLocalInt(OBJECT_SELF, "SpawnTime");
iTime = GetLocalInt(OBJECT_SELF, "Time");
if(iTime >= iSpawnTime)
{
SetLocalInt(OBJECT_SELF, "Time", 6);
iSpawnNow = TRUE;
}
else
SetLocalInt(OBJECT_SELF, "Time", iTime+6);
}
else
{
SetLocalInt(OBJECT_SELF, "Time", 6);
iSpawnNow = TRUE;
}
return iSpawnNow;
}
int CountDeadObjects(int iObjectType)
{
int iLivingObjects;
int iDeadObjects;
int iObjectCount;
string sSpawnFlag;
object oSelectedObject;
iLivingObjects = 0;
iObjectCount = 1;
oSelectedObject = GetNearestObject(iObjectType, OBJECT_SELF, iObjectCount);
while(GetIsObjectValid(oSelectedObject))
{
if(GetIsDead(oSelectedObject) == FALSE)
{
if(CheckObject(oSelectedObject) == TRUE)
iLivingObjects++;
}
iObjectCount++;
oSelectedObject = GetNearestObject(iObjectType, OBJECT_SELF, iObjectCount);
}
iDeadObjects = GetLocalInt(OBJECT_SELF, "MinNumObjects") - iLivingObjects;
if(iDeadObjects < 0)
iDeadObjects = 0;
if(iDeadObjects > 0)
iDeadObjects = iDeadObjects + GetRandomMaxMinNumber();
return iDeadObjects;
}
int GetRandomMaxMinNumber()
{
int iRandom;
int iMaxMinDifference;
iMaxMinDifference = GetLocalInt(OBJECT_SELF, "MaxNumObjects") - GetLocalInt(OBJECT_SELF, "MinNumObjects");
iRandom = Random(iMaxMinDifference+1);
return iRandom;
}
int CreateObjects(int iObjectType, int iDeadObjects)
{
int iCounter;
string sSelectedTemplate;
object oSelectedObject;
for(iCounter = 1; iCounter <= iDeadObjects; iCounter++)
{
sSelectedTemplate = GetTemplate();
sSelectedTemplate = GetSubString(sSelectedTemplate, 3, GetStringLength(sSelectedTemplate)-1);
oSelectedObject = CreateObject(iObjectType, sSelectedTemplate, GetRandomLocation(), TRUE);
SetLocalString(oSelectedObject, "SpawnFlag", GetLocalString(OBJECT_SELF, "FlagName"));
ObjectActions(oSelectedObject);
}
return iCounter-1;
}
string GetTemplate()
{
int iCounter;
int iRandom;
int iProbability;
int iLow;
int iHigh;
iLow = 1;
iRandom = Random(99)+1;
for(iCounter = 1; iCounter <= GetLocalInt(OBJECT_SELF, "NumberOfTemplates"); iCounter++)
{
iProbability = StringToInt(GetSubString(GetLocalString(OBJECT_SELF, "Template"+IntToString(iCounter)), 0, 2));
iHigh = iHigh+iProbability;
if(iRandom >= iLow && iRandom <= iHigh)
return GetLocalString(OBJECT_SELF, "Template"+IntToString(iCounter));
iLow = iHigh+1;
}
return "Error";
}
location GetRandomLocation()
{
float fRandomOrientation;
float fRandomVectorX;
float fRandomVectorY;
vector vRandom;
location lSpawnLocation;
fRandomOrientation = IntToFloat(Random(360) - 180);
fRandomVectorX = IntToFloat(Random(GetLocalInt(OBJECT_SELF, "SpawnAreaWidth")*2)-GetLocalInt(OBJECT_SELF, "SpawnAreaWidth"));
fRandomVectorY = IntToFloat(Random(GetLocalInt(OBJECT_SELF, "SpawnAreaHeight")*2)-GetLocalInt(OBJECT_SELF, "SpawnAreaHeight"));
vRandom = Vector(fRandomVectorX, fRandomVectorY, 0.0) + GetPositionFromLocation(GetLocation(GetLocalObject(OBJECT_SELF, "Target")));
lSpawnLocation = Location(GetArea(OBJECT_SELF), vRandom, fRandomOrientation);
return lSpawnLocation;
}
_________________
-Enthas
|