Lightfoot,
I am still having problems. The script is:
#include "nw_i0_generic"
//object heartbeat
void main()
{
object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR,
PLAYER_CHAR_IS_PC/*, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION,
PERCEPTION_SEEN */); // I dont think Placeables have perception to see
//autoact is used to turn the autospawn function of the area on/off.
if (GetLocalInt(oPC, "autoact") != 1) return;
object oArea = GetArea(OBJECT_SELF);
location lTarget = GetLocation(OBJECT_SELF);
int iGoblinInArea = 0;
//iLimit is to set the limit to be spawned.
int iLimit = (GetLocalInt(oPC, "autoval")); // Edit to set the max number to spawn at at time.
string sMob = GetLocalString(oPC, "mnstrspwntyp");
object oCreature = GetFirstObjectInArea(oArea);
while (GetIsObjectValid(oCreature))
{
if (GetResRef(oCreature) == sMob && !GetIsDead(oCreature))
iGoblinInArea=iGoblinInArea +1 ;
oCreature = GetNextObjectInArea(oArea);
}
while (iGoblinInArea < iLimit )
{
object oSpawn = CreateObject(OBJECT_TYPE_CREATURE, sMob, lTarget);
SetIsTemporaryEnemy(oPC, oSpawn);
AssignCommand(oSpawn, DetermineCombatRound(oPC));
iGoblinInArea= iGoblinInArea +1;
}
}
That script spawns on each HB the number picked by the PC, not up to a maximum total.
If the PC picks 3, it spawns 3 each HB, if they pick 1, it spawns 1 each HB.
I am trying to step through this to figure out what the problem is, not seeing it though.
edit-To try testing this I made this change to the first loop:
while (GetIsObjectValid(oCreature))
{
if (GetResRef(oCreature) == sMob && !GetIsDead(oCreature))
iGoblinInArea=iGoblinInArea +1 ;
SendMessageToPC(oPC, "Went through first loop");
oCreature = GetNextObjectInArea(oArea);
}
Just to see how many times it goes through the loop.
With the PC selecting 1, it spawns 1 mob each HB but if I counted right, it goes
through the loop 13 times. This 13 is the number if objects in the area plus whatever
creatures had spawned at that time(which I think was 3).
I tried the same thing with the second loop. And if the PC wants just 1, it only goes through once,
like expected. So basically just need to figure out how to set a maximum number in the area to stop
spawning until at least one is killed.
Modifié par datamaster, 05 mai 2011 - 10:14 .