For the heck of it, my rabbit-spawning script (called from area-on-enter script):
[nwscript]
// spawn_sc_rabbits
// Name_Date
int iResupplyClock() {
int iLastHour = GetLocalInt(OBJECT_SELF, "iRabbitLastHour");
int iThisHour = GetTimeHour();
int iSupplyClock = iThisHour - iLastHour;
// if (iSupplyClock < 0) {iSupplyClock = iSupplyClock + 24;}
int iLastDay = GetLocalInt(OBJECT_SELF, "iRabbitLastDay");
int iThisDay = GetCalendarDay();
if (iLastDay != iThisDay) {
iSupplyClock = iSupplyClock + 24;
}
SetLocalInt(OBJECT_SELF, "iRabbitLastHour", iThisHour);
SetLocalInt(OBJECT_SELF, "iRabbitLastDay", iThisDay);
return iSupplyClock;
}
object oSpawnRabbit(int iSpawnNum) {
object oWP = GetObjectByTag("SPAWN_SCRabbit" + IntToString(iSpawnNum));
location lLoc = GetLocation(oWP);
object oRabbit = CreateObject(OBJECT_TYPE_CREATURE, "myrabbit", lLoc, FALSE, "SCRabbit" + IntToString(iSpawnNum));
return oRabbit;
}
int iCheckSpawnRabbit(int iSpawnNum) {
object oRabbit = GetObjectByTag("SCRabbit" + IntToString(iSpawnNum));
if (GetIsObjectValid(oRabbit) && !GetIsDead(oRabbit)) {
ForceRest(oRabbit);
return 1;
}
else {
oSpawnRabbit(iSpawnNum);
return -2;
}
}
void main()
{
object oPC = GetFirstPC();
//Do Plot restrictions
int iMaxRabbits = 9;//Constant
int iSupply = iResupplyClock();
// SendMessageToPC(oPC, "Supply: " + IntToString(iSupply));
int iTer = 1;
while ((iTer <= iMaxRabbits) && (iSupply > 0)) {
// SendMessageToPC(oPC, "While Loop: " + IntToString(iTer) + "/" + IntToString(iSupply));
iSupply = iSupply + iCheckSpawnRabbit(iTer);
iTer = iTer + 1;
}
}
[/nwscript]
It just works to make the rabbit population doesn't get too big, and gradually repopulates after the PC kills a few.
Modifié par Lugaid of the Red Stripes, 26 décembre 2013 - 06:29 .