Author Topic: Check condition and fire encounter only if true - Is this possible?  (Read 426 times)

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0


               Howdy compan'eros - I give ye greet. I was wondering if somebody out there could help me with a little something. I want to make an encounter that only fires if the PC faction is hostile to the territory's faction. I'm guessing it would be an if/then in the encounter's OnEnter script. Thanks - George.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #1 on: June 01, 2013, 01:37:19 am »


               You're on the right track. Set the encounter to inactive and do something like this... (not to pick on dwarves '<img'>

<code>
void main() {
   object oPC = GetEnteringObject();
   if (GetRacialType(oPC) == RACIAL_TYPE_DWARF)
       SetEncounterActive(TRUE);
}
</code>

But the trickier bit will be checking the faction. You probably will want the script to get a member of the territory's faction (maybe one with a nice unique tag so it's easy) to do the hostility check. I don't believe you can get the faction of the encounter as such.

GetObjectByTag  and then GetIsEnemy would probably do it.
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #2 on: June 01, 2013, 02:27:21 am »


               Setting an encounter to inactive and having the OnEnter Event make it active will instead make it active for the next PC to enter the trigger, not the one that just did. You'll need to draw a trigger that is slightly large than the encounter and have it set the encounter active or even just use the OnEnter event for the area itself.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #3 on: June 01, 2013, 03:07:45 am »


               That's not true. I just made a test module with that exact on enter in it and the dwarf got creatures. I was curious about when the encounter fired versus when the on enter happened so I checked before I posted it.
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #4 on: June 01, 2013, 01:05:06 pm »


               From the NWN Lexicon:

RemarksFrom Victor Morales:

I have tried the SetEncounterActive function to spawn creatures at different times of the day. For example, I only wanted the undead in a cemetery to spawn if it was nighttime.

If the encounter active flag is set to FALSE to begin with (in the encounter GUI window when the encounter is created) then the SetEncounterActive function will spawn them properly the first time. It seems that the creatures are set to spawn before the OnEnter event is checked for validity. In addition, once the active flag is set it won't revert until the next time the encounter is triggered.

So I would have undead that would spawn at night properly, but once they spawned - if the time changed to day they would spawn at least one more time during daylight hours. Then the trigger would work properly again.

I tried to make it reset the active flag to active OnEnter, then the creatures would spawn, and to reset it to inactive OnExit. However, that didn't work either and the behavior stayed the same.

You can draw a trigger around the encounter and call this function from OnEnter of that trigger instead as a workaround.


So it may work properly (or appear to), but will likely glitch for second and successive PCs entering it.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #5 on: June 01, 2013, 01:49:21 pm »


               That's different from what you said before, though. It may be that it flakes out on subsequent uses.
Your statement was that it would only be active for the next use, which is not the case... but your suggestion is the right workaround for multi-shot triggers.

I knew I had read something about that but didn't find it last night.
               
               

               
            

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #6 on: June 01, 2013, 09:51:23 pm »


               This is something I can work with. I'll just have to mess around with it. Thanks.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #7 on: June 02, 2013, 04:08:23 am »


               Would it not be simpler to just make the encounter the same faction as the faction of your hostile monsters.    

If if spawns for to large of a range that way.   Make a custom faction for the encounters and then adjust  its reaction to the PC as needed.
               
               

               
            

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #8 on: June 02, 2013, 10:37:56 pm »


               I want to make it so the encounter only fires if the PC is going in hostile. The factions starts out as friendlies.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #9 on: June 03, 2013, 02:08:59 am »


               correct,  Every PC party has its own faction,   So you can set the encounter as either friendly or hostile to the PC.   You can also set the encounter so that it only fires for PC's
               
               

               
            

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #10 on: June 03, 2013, 07:46:24 pm »


               I think I'm starting to understand what you're saying about the encounter's faction. I originally wanted the encounter to only fire if the PC faction is hostile to it.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #11 on: June 03, 2013, 08:33:57 pm »


               

From : Maxam - Introduction To Encounters


Faction
Like creatures, encounters have a faction. It is important to note that the faction of the encounter in no way determines or changes the faction of the creatures spawned. It only controls whether or not the encounter will spawn when a PC or other creature walks over it.


In order for the encounter to trigger properly the player must be hostile to the faction of the trigger - the creatures spawned could be hostile, neutral or even friendly. For this reason most triggers will be set to the 'Hostile' faction.


Its worth noting that encounters set to the standard npc factions, (commoner, merchant and defender,) don't seem to trigger for npc's that are hostile to these factions, they only trigger for PC's and members of their party. However using a custom faction on the encounter, set up with similar likes and dislikes, should work as expected.


So for example you could set a number of encounters, with a faction of 'Commoner', around a village. When triggered, these encounters would spawn groups of guards to deal with the attackers. These encounters will not be triggered when players wander around the village unless the players have been attacking villagers, thus becoming hostile to the villagers ('Commoner') faction.


               
               

               
            

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #12 on: June 04, 2013, 06:59:10 pm »


               Oh cool. Thanks.
               
               

               
            

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #13 on: June 07, 2013, 12:50:00 am »


               Naw, it doesn't work. If I set the encounter to hostile it fires fine, but if I set it to the faction I'm in the process of slaughtering, it never fires.
               
               

               
            

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0
Check condition and fire encounter only if true - Is this possible?
« Reply #14 on: June 07, 2013, 01:43:20 am »


               Is it possible to set the encounter's faction to hostile, or activate it, programmatically? I want it to fire when the leader is attacked. Could I put something in his OnAttacked script?