Hello everyone,
I started to learn NWNscript a few weeks ago, and doing simply things at the moment. Right now im creating a script that does spawn some winter placeables arround some waypoints arround the module in winter months ( 11, 12, and 1), when spring comes they are removed. It is executed in each area.
The problem I have is that even without giving it a loop to create many, they do spawn arround 1-6 placeables, overstacking the place. I want to decide how many they spawn. I though about a while or for loop, but having this issue no matter what I write, it always spawns 1-6 placeables >.<
This is the code I have got so far. As far as I know, this should spawn 1 placeable in each waypoint in the module with that tag.
//This is a random placeable spawn for iceblocks in winter. sObject is the tag of the placeable
void Randomspawn(object oArea,string sOject)
{
object oFirst = GetFirstObjectInArea(oArea);
while(GetIsObjectValid(oFirst) )
{
// All area objects are checked to detect the waypoing by tag
if(GetTag(oFirst) == "NO_IS_SPAWN01")
{
//Random location from that waypointin that area
location lLocation = GetRandomLocation(oArea,oFirst,IntToFloat(d4()));
//Create the placeable in tha tlocation
object oDog = CreateObject(OBJECT_TYPE_PLACEABLE,sOject,lLocation,TRUE);
}
//Go for the next object in the area to check if there are more waypoints.
oFirst= GetNextObjectInArea(oArea);
}
DelayCommand(120.0,Randomspawn(oArea,sOject));
}
//This deletes the above placeables each cycle.
void Despawnrandom(object oArea,string sOject)
{
object oFirst = GetFirstObjectInArea(oArea);
while(GetIsObjectValid(oFirst))
{
if(GetTag(oFirst) == sOject)
{
SetPlotFlag(oFirst,FALSE);
DestroyObject(oFirst,0.1);
}
oFirst= GetNextObjectInArea(oArea);
}
DelayCommand(120.0,Despawnrandom(oArea,sOject));
}
The functions are called on the onloadmodule script, so the cycle begins every 2 minuts./ hour ingame.
object oArea =GetFirstArea();
while(GetIsObjectValid(oArea))
{
Despawnrandom(oArea,"x3_plc_flame001");
DelayCommand(0.5,Randomspawn(oArea,"x3_plc_flame001"));
oArea = GetNextArea();
}
It detects all waypoints in each area correctly, but the number of spawns isnt correct. If im not mistaken this code should place only 1.
Anoyne sees anything wrong?
Thanks!