Author Topic: Getting encounter creatures  (Read 247 times)

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Getting encounter creatures
« on: May 19, 2011, 08:54:23 am »


               Is there an efficient method for getting the creatures created in an encounter without looping over every object in an area?

I would like a way for the encounter to spawn its creatures and then buff those creatures according to game difficulty and number of PCs in the area. But, the engineer in me doesn't like the idea of looping over every object returned by
GetFirstObjectInArea()
/
GetNextObjectInArea()
, especially since the game knows that an encounter was triggered and there is a test for whether a given object was part of an encounter (
GetIsEncounterCreature()
).

Ideally, a
GetFirstEncounterCreature()
&
GetNextEncounterCreature()
could take the encounter object as a parameter, perhaps as given by OBJECT_SELF or something in the OnEnter event handler.

Anyway, I don't know that anything that does what I am asking for exists, and I can do things in a big loop. But, there are areas with oodles of objects, so I though I'd check to avoid a monster loop if possible...
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Getting encounter creatures
« Reply #1 on: May 19, 2011, 12:01:29 pm »


               The only thing that comes to my mind is to handle it in the OnAreaEnter event.    Make a check to see if it is a new encounter creature.  Buff it on enter if it is,   Then set a local on it to mark it as an already buffed creature.  you would not wanting them to buff again just because they transistioned to a new area.
               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
Getting encounter creatures
« Reply #2 on: May 19, 2011, 02:21:42 pm »


               Or, if all creature share the same OnSpawn script, use the GetIsEncounterCreature() function in it to identify if the spawning creature is an encounter creature and then put (or hook to) your buffing code after that.
               
               

               
            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Getting encounter creatures
« Reply #3 on: May 19, 2011, 10:55:17 pm »


               Thayan, most of these encounters are spawning creatures with no OnSpawn script. OnSpawn is a good way to go generally, though I was hoping in this case avoid adding OnSpawns to all the encounter creatures and then to tailor the buffing to the encounter difficulty, as returned by
GetEncounterDifficulty()
.

Lightfoot8, setting a "buffed" local on each spawn was my plan to avoid rebuffs. By "OnAreaEnter event", do you mean use the area's
OnEnter
event or the
OnEnter
event for the encounter? I was assuming using the encounter's
OnEnter
event to trigger my script to find the encounter creatures, then buff and
SetLocalInt
them as buffed in case they're still around the next time an encounter is triggered.

But, I am still not clear how to avoid something like the following

void main()
    {
    object oPC = GetEnteringObject();
    int NumPCs = CountPCsInArea(oPC); // counts area faction members
    int GameDiff = GetGameDifficulty();
    // THIS cycles through every object in the area!
    object oCreature = GetFirstObjectInArea();
    while (GetIsObjectValid(oCreature))
        {
        if ( ( GetIsEncounterCreature(oCreature) ) && (GetLocalInt(oCreature,"encounter_buffed")==0) )
            {
            // buff appropriate for creature type, party size,
            // difficulty, etc., then set local
            BuffCreature(oCreature,NumPCs,GameDiff);
            }
        oCreature = GetNextObjectInArea();
        }
    }

I'm new to this, so I'm probably missing your suggestion, but I still see looping over every object in the area whenever an encounter is triggered.

[EDIT] Sorry for the sloppy post. I don't know how to do a decent code post on these boards.
               
               

               


                     Modifié par MrZork, 19 mai 2011 - 10:05 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Getting encounter creatures
« Reply #4 on: May 20, 2011, 12:17:24 am »


               I dont think anybody know how to make a good script post here. We just make due with what we have.

And no you did not miss it. The OnEnter for the encounter will only fire when something enters the trigger for the encounter. I do not even know if the creatures for the encounter are spawned when the event fires. So your loop my just come up with nothing new. So the OnAreaEnter event for the area is the script that I was suggesting to use. When the encounter creates the creature the areas on enter event will fire. At that point you do not need to search for the creature just check if it is an encounter creature then buff him. The only way the event would fire for the event again is if he left the area then returned, hence the need for the buffed int.

Of cource Thayan's soultion was probably better then mine. You would just need to modify the default onspawn script that is used for 90% of all creatures to check if it is an encounter creature. You could forget about the already buffed check, because the script only fires once when the creature is spawned.
               
               

               


                     Modifié par Lightfoot8, 19 mai 2011 - 11:18 .
                     
                  


            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Getting encounter creatures
« Reply #5 on: May 20, 2011, 01:47:48 am »


               <Headsmack> I'm such a bonehead. I'm so used to using area OnEnter events for setting things up when a PC enters an area that I forgot that it fires when a creature spawns, too. That is perfect and easy to use. Thanks for the help!