Skip to content

Could Use Help

2»

Comments

  • ProlericProleric Member Posts: 1,316
    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.
  • BalkothBalkoth Member Posts: 161
    The while loop isn't doing you any good.

    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.
  • IronActualIronActual Member Posts: 24
    Would this be correct?
    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)); }
  • TerrorbleTerrorble Member Posts: 179
    edited April 2018
    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));

    I hope this gets you closer. I haven't tested it.
  • ProlericProleric Member Posts: 1,316
    edited April 2018
    You need two checks - do nothing if the entering creature is not a PC, and do nothing unless they are the first in.
    void main()
    {
        object oArea = OBJECT_SELF;
        object oTarget;
        object oSpawn;
        int nPCcount = GetLocalInt(oArea, "PCcount"); 
        object oPC = GetEnteringObject();;
    
        if (!GetIsPC(oPC)) return;
    
       ++nPCcount;
    
       SetLocalInt(oArea, "PCcount", nPCcount);
    
       if (nPCcount > 1) return;
    
        oTarget = GetWaypointByTag("boss001waypoint");
        oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "boss001", GetLocation(oTarget));
    }
    This is a bit scrappy as I'm writing this on a tablet, but you get the general idea. The OnExit script is the reverse.
  • IronActualIronActual Member Posts: 24
    Thanks, I love this community! Looking into both those suggestions.
  • IronActualIronActual Member Posts: 24
    edited April 2018
    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?
  • TerrorbleTerrorble Member Posts: 179
    edited April 2018
    *edit* nvm, I said something you clearly understood. I'm not sure.
  • BalkothBalkoth Member Posts: 161


    // 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; }

    I updated the code to the following (to be cleaner and easier to maintain).

    // 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.
Sign In or Register to comment.