You need GetIsPC to check that the entering object is a PC.
GetLocalInt and SetLocalInt to read / write a local variable on the area which counts the number of players in it. As it stands, you will create a boss every time.
This should prevent multiple bosses from spawning (since only the first player entering will spawn the boss) and clean up the boss when no players are left in the area.
Your script will spawn the boss every time a player enters. Four players, four bosses. And, it assumes that the Entering Object is a PC.
object oPC = GetEnteringObject();
if( !GetIsPC(oPC) ) return;
int bSpawnBoss = TRUE; //assume we want to spawn the boss
//but we're going to scan all the objects in the area to see if the boss is already there.
object o = GetFirstObjectInArea(OBJECT_SELF);
while( GetIsObjectValid(o) )
{
//if we find the boss already present: we just quit the script
if( GetTag(o) == "Tag_of_Boss" ) return;
o = GetNextObjectInArea(OBJECT_SELF);
}
//Since we hvaen't quit by now, we must need to spawn... and don't forget
//to do an ApplyEffect function to show the VFX you want.
object oTarget = GetWaypointByTag("boss001waypoint");
object oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "boss001", GetLocation(oTarget));
ApplyEffectAtLocation(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_IMP_HARM), GetLocation(oTarget));
Here's something that I've been trying to figure out. My module is running on a linux server and I've set a few things up on my module's OnModuleLoad to randomize creatures in each area. For example: // area016
switch (Random(2))
{
// Goblins
case 0: oTarget = GetWaypointByTag("0161a"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0161b"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0161c"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0161d"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0163"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin3", GetLocation(oTarget)); break;
// Bugbears
case 1: oTarget = GetWaypointByTag("0161a"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0161b"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0161c"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0161d"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0163"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug3", GetLocation(oTarget)); break;
}
// area017
switch (Random(2))
{
// Goblins
case 0: oTarget = GetWaypointByTag("0171a"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0171b"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0171c"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0171d"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0172a"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin2", GetLocation(oTarget));
oTarget = GetWaypointByTag("0172b"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin2", GetLocation(oTarget)); break;
// Bugbears
case 1: oTarget = GetWaypointByTag("0171a"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0171b"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0171c"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0171d"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget));
oTarget = GetWaypointByTag("0172a"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug2", GetLocation(oTarget));
oTarget = GetWaypointByTag("0172b"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug2", GetLocation(oTarget)); break;
} This works great in single player. But for some reason when my module loads, area016 always has goblins and area017 always has bugbears! It doesn't matter how many times I reload my server, all my areas roll the same case as the very first time the server went online.
Is there an .ini file that was created the first time the server went online and it's using those cases each time I reload?
Unfortunately, I observed the same result you did -- works in single player but same result on the server. Guess the server uses a different random generator in some fashion, don't know offhand what's going on.
Comments
GetLocalInt and SetLocalInt to read / write a local variable on the area which counts the number of players in it. As it stands, you will create a boss every time.
Basically, you want the following code...
OnEnter:
if number of players in area == 1
spawn boss
OnExit:
if number of players in area == 0
delete boss
This should prevent multiple bosses from spawning (since only the first player entering will spawn the boss) and clean up the boss when no players are left in the area.
void main() { object oTarget; object oSpawn; object oPC = GetFirstPCInArea(); if (!GetIsPC(oPC)==1) return; oTarget = GetWaypointByTag("boss001waypoint"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "boss001", GetLocation(oTarget)); }
object oPC = GetEnteringObject(); if( !GetIsPC(oPC) ) return; int bSpawnBoss = TRUE; //assume we want to spawn the boss //but we're going to scan all the objects in the area to see if the boss is already there. object o = GetFirstObjectInArea(OBJECT_SELF); while( GetIsObjectValid(o) ) { //if we find the boss already present: we just quit the script if( GetTag(o) == "Tag_of_Boss" ) return; o = GetNextObjectInArea(OBJECT_SELF); } //Since we hvaen't quit by now, we must need to spawn... and don't forget //to do an ApplyEffect function to show the VFX you want. object oTarget = GetWaypointByTag("boss001waypoint"); object oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "boss001", GetLocation(oTarget)); ApplyEffectAtLocation(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_IMP_HARM), GetLocation(oTarget));
I hope this gets you closer. I haven't tested it.
For example:
// area016 switch (Random(2)) { // Goblins case 0: oTarget = GetWaypointByTag("0161a"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0161b"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0161c"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0161d"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0163"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin3", GetLocation(oTarget)); break; // Bugbears case 1: oTarget = GetWaypointByTag("0161a"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0161b"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0161c"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0161d"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0163"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug3", GetLocation(oTarget)); break; } // area017 switch (Random(2)) { // Goblins case 0: oTarget = GetWaypointByTag("0171a"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0171b"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0171c"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0171d"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0172a"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin2", GetLocation(oTarget)); oTarget = GetWaypointByTag("0172b"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "goblin2", GetLocation(oTarget)); break; // Bugbears case 1: oTarget = GetWaypointByTag("0171a"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0171b"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0171c"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0171d"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug1", GetLocation(oTarget)); oTarget = GetWaypointByTag("0172a"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug2", GetLocation(oTarget)); oTarget = GetWaypointByTag("0172b"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bug2", GetLocation(oTarget)); break; }
This works great in single player. But for some reason when my module loads, area016 always has goblins and area017 always has bugbears! It doesn't matter how many times I reload my server, all my areas roll the same case as the very first time the server went online.
Is there an .ini file that was created the first time the server went online and it's using those cases each time I reload?
// area016 string sCreature = ""; switch (Random(2)) { // Goblins case 0: sCreature = "goblin"; break; // Bugbears case 1: sCreature = "bug"; break; } CreateObject(OBJECT_TYPE_CREATURE, sCreature + "1", GetLocation(GetWaypointByTag("0161a"))); CreateObject(OBJECT_TYPE_CREATURE, sCreature + "1", GetLocation(GetWaypointByTag("0161b"))); CreateObject(OBJECT_TYPE_CREATURE, sCreature + "1", GetLocation(GetWaypointByTag("0161c"))); CreateObject(OBJECT_TYPE_CREATURE, sCreature + "1", GetLocation(GetWaypointByTag("0161d"))); CreateObject(OBJECT_TYPE_CREATURE, sCreature + "3", GetLocation(GetWaypointByTag("01613")));
Unfortunately, I observed the same result you did -- works in single player but same result on the server. Guess the server uses a different random generator in some fashion, don't know offhand what's going on.