Author Topic: Hostile but not agro  (Read 463 times)

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Hostile but not agro
« on: August 16, 2011, 05:48:24 pm »


                <gingerly tip-toes across the forum...>

One of the effects I'd like to create is the PC and party walking nervously through a crowd of very angry, tough creatures.  The hostiles will (grudgingly) move out of the PC's way and fill in behind them, growling and threatening and *wanting* to attack.

Example: When invited to visit the troll matriarch, the PC receives a troll-claw necklace that guarantees safe passage.  The troll-kin - small and large - that protect the matriarch *must* be hostile and focused on the PC party (I want them glowing vicious red!), but they also must *not* attack unless the PCs do something stupid.

Currently I'm looking to adapt henesua's  AI: Light Shy Creatures script so they are "necklace-shy".
Has anyone done (or know the location of) another repulsion-equipment script in a similar vein?

I'm particularly interested in efficient tracking of the PC (necklace) and removing all the shyness if the PCs enter combat. 

<...blushing furiously>
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Hostile but not agro
« Reply #1 on: August 16, 2011, 10:47:20 pm »


               You could easily do that with the lightshy creature's ai script. Feel free to rip it apart and modify.

Basically all the lightshy system does is flag a PC with an integer so that certain creatures will not attack, and the flag has a value equivalent to how strong the light is. The value is a measure of how big the radius is. (value of 1 = 5 meters, 2 = 10 m etc...)

The flagging and deflagging of the PC occurs in the onequip and onunequip module events. This would work fine for you. (What you will probably not need is tracking whether the lightsource expires. I am using consumable lightsources - and I think I included that code in the lightshy scripts on the vault.)

One more thing that might not be of interest to you: it determines whether another creature which is not carrying the light, is within the light radius. The creatures will not target a creature within a light radius. You'd save some processing cycles by removing this. But it depends on how you want your aversion effect to work.

One bug with my code that may cause problems for you, is that sometimes creatures overcome their shyness, and I have not yet found the hole in my code that allows this. This could disrupt the other feature you want to add - that once a creature overcomes the "aura" of the necklace, they are no longer afraid. However it might function as you want as is. Typically the repulsion fails for a couple rounds when the PC attacks a lightshy NPC.

Some ways I have considered handling what you describe is to:
(1) Flag an NPC as immune to the necklace's effects under certain circumstances (when they have damaged the PC perhaps)
(2) Remove the repulsion flag from the PC if they attack one of the creatures which will enable all to attack.
(3) Flag all NPCs within 20 meters as immune to the effects if a PC attacks.
               
               

               


                     Modifié par henesua, 16 août 2011 - 10:09 .
                     
                  


            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Hostile but not agro
« Reply #2 on: August 16, 2011, 11:09:46 pm »


               <looks puzzled as the trollkin run away...>

I was just working through _ai_lshy_percep...

The flag will work great for tracking the "passport" item.

And I do want the area effect to protect associates.

So, I need to check a radius and see if anyone is within it... whenever anyone moves and while moving... That's the part that stinks of lag. A hb loop for the area that cycles through creatures?

I think I'll also make the area of effect larger for smaller trollkin... the big bruisers will kinda push the boundaries, and the pipsqueaks hang back. And they will overcome repulsion if combat starts.

And I'll take #2, for the game :-) The item only works if the PCs behave, otherwise it's (rather ugly and frightening) jewelry.

<...but understands after checking his armpits>
               
               

               


                     Modifié par Rolo Kipp, 16 août 2011 - 10:13 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Hostile but not agro
« Reply #3 on: August 16, 2011, 11:33:01 pm »


               I want to state clearly that while the frame work I have set up will help guide you in the creation of your own scripts, I do think that ultimately you'll want to rethink the logic I am using because I wrote those behaviors with light in mind rather than a repulsive necklace. There are likely some subtleties of the code that should be changed so that the behaviors make sense. And you might be able to achieve what you want more efficiently than I did.

Regarding lag: The lightshy system gets laggy when you have about 20+ creatures in a small space and they all encounter the PC at the same time. With groups of 5 at a time I have not noticed any lag - even if there are 30 creatures in the area. However that would change if you had four PCs dealing with four groups of creatures all at the same time. After the intial perception event however the lag crisis seems to subside.

Also, I am using the creature's HB to enable the constant reaction to the PC, and to enable the NPC to realize that the light was gone if a lantern ran out of oil (which does not unequip the lantern). The perception event only fires when the NPC first sees the PC. I needed the HB event to enable the creatures to continue to see the PC.

The radius check not require heartbeats - rather it is built into the NPC's targeting of the PC. The NPC makes a decision about targeting based upon a number of conditions. It first determines whether the PC is bearing light. Then it determines if a pool of light is overlapping the PC. If either of those resolve to TRUE, the NPC exhibits lightshy behavior as opposed to the default behavior.

BTW - I think the behavior you are trying to achieve is different in one important way. You seem to want the creatures to be drawn to the bearer of the necklace, but unable to get closer than a certain distance. That is not how the lightshy thing works. The lightshy behavior affects targeting, and flight. ie. If you get too close the creature's flee. If they see you but you are at a distance they ignore you (except that I make them face the PC as well to simulate a glance in the PCs direction).

Rather in your case you seem to want the creature to spot the PC, and target them BUT rather than attack the creature follows the PC at a certain distance.
               
               

               


                     Modifié par henesua, 16 août 2011 - 10:38 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Hostile but not agro
« Reply #4 on: August 17, 2011, 05:07:01 am »


               What you are trying to do is most likely best done by using the X2_SPECIAL_COMBAT_AI_SCRIPT.  Here are a few recent posts on its usage. 


- NPC blocked but not by door (Neverwinter Nights 1 - NwN 1 ...


- AI Behavior Priority (Neverwinter Nights 1 - NwN 1 Builders ...



- NPC Combat Behavior - NPC should not attack while fleeing ... 
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Hostile but not agro
« Reply #5 on: August 17, 2011, 05:51:34 pm »


               This might be the right way for him to handle this, since the behavior he desires only comes into play when a hostile creature targets a PC.

It doesn't work in the light shy behavior however as that behavior is not combat dependent.
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Hostile but not agro
« Reply #6 on: August 17, 2011, 09:05:54 pm »


               <He's being vewy vewy qwiet...>

Lightfoot8 wrote...

What you are trying to do is most likely best done by using the X2_SPECIAL_COMBAT_AI_SCRIPT.  Here are a few recent posts on its usage. 
...


Beautiful! Those answer my need, nicely. :-)

What I will do is:

  when necklace is equipped
     for each trollkin
       set the X2_SPECIAL_COMBAT_AI_SCRIPT to (a modification of the "flocking" behavior to give PC room)
       normal (attack) AI turned off by X2_SPECIAL_COMBAT_AI_SCRIPT_OK, TRUE.
       // This will keep them glaring at the PCs but not attacking.

  If PC unequips item or damages trollkin
    unset flag and remove script
    Dogpile!

I can then re-use this script for wolf packs circling a herd protected by a great stag... Woe to the laggard! :-)

Remember the scene in Birds where they walk nervously past the schoolyard full of crows? Or in Godzilla (the funny version with Mathew Broderick) where they walk - don't run! - among the dozens of baby godzillas? I want that kind of tension.  I even want the bigger trollkin to drool =) 

<...hunting troll-bits>
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Hostile but not agro
« Reply #7 on: August 17, 2011, 11:14:47 pm »


               Rolo - if you have one potential bug with going this route. Its small but you should be aware of it. You are depending on keeping the monsters in combat mode. If their combat mode breaks, they will not reacquire a target that is still in plain sight. They will actually ignore them. While this is likely a very rare situation, its worth being aware of and if you are able to try to catch it
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Hostile but not agro
« Reply #8 on: August 17, 2011, 11:55:04 pm »


               <stares off into space...>

henesua wrote...

... If their combat mode breaks, they will not reacquire a target that is still in plain sight. They will actually ignore them. ...


Good lord! What are they smoking?!

Thanks for the heads up.  I'll have to set up a proto and run the gauntlet a few times to look for problems. Should anyway, of course ;-P

Any idea why they don't re-aquire? OnPerception not firing?

<...at all the pretty colored lights...>
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Hostile but not agro
« Reply #9 on: August 18, 2011, 12:21:27 am »


               On perception only fires for an NPC when a creature object is first perceived by the NPC. The NPC would have to lose sight of the creature and then see it again for the perception event to fire.

This is not a problem when an NPC has already acquired a target that it is hostile towards. The combat scripts will keep it busy. But if the combat loop is interrupted, the NPC will not automatically resume hostilities. You need to give it help or its associates need to tell it to get back in the game. Occassional silent shouts in your special AI might solve the problem since you are counting on numerous monsters being involved.

The moral: be careful with ClearAllActions(TRUE);
               
               

               


                     Modifié par henesua, 17 août 2011 - 11:24 .