Not quite sure I fully understand how to use it properly. I’ve got a custom function that is supposed to spawn Random(3) dire rats, but it seems to always only spawn 2. What gives?
Shadoooow has explained the Random-function perfectly, but I’m puzzled, that you expect that this would spawn multiple copies of a NPC.
Multispawn will spawn just one creature. There is another CreateObject in main(), so the whole scripting would always spawn two rats.
Try the following:
// Epic "rats in the basement" spawner
void main()
{
object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;
// Maybe add a "do once" here??
string sCreature = "ratdire002";
location lLoc = GetLocation(GetWaypointByTag("RAT_LOC1"));
object oSpawn;
int i, n = d4();
for (i=1; i<=n; i++)
{
oSpawn = CreateObject(OBJECT_TYPE_CREATURE, sCreature, lLoc);
DelayCommand(0.2, AssignCommand(oSpawn, ActionAttack(oPC)));
// with rats, ActionAttack should be enough, save the rats have a feat to go berserk.
}
}
Yeah, I think i might misunderstand how to use SetSpawnInCondition() as well. I thought that stated to spawn Randon (3) rats, not a copy of the PC. What the hell am I doing? Did I mention I’m not a coder…?
I suppose I simply could have painted an encounter of rats down and let the game handle it, but I wanted to challenge myself by attempting to create a custom function. Epic fail!!!
You’d need to use a loop in order to spawn multiple creatures since the function only creates a single creature at a time. Only stackable items can have multiples created at a time.
There is an alternative but it requires putting some extra coding into the OnSpawn event for the creature, and that gets even more complicated.