Author Topic: Scripting a Henchman to Use an Item  (Read 346 times)

Legacy_AndarianTD

  • Hero Member
  • *****
  • Posts: 725
  • Karma: +0/-0
Scripting a Henchman to Use an Item
« on: October 14, 2012, 01:14:17 pm »


               Does anyone know how to script a henchman to use an item? I've observed that henchmen with their "casting" toggle set will often do this with items such as scrolls and the like, but there are situations where I'd like to be able to do this deliberately. I don't seem to be able to find anything in the API that would enable this.

Also, does anyone know how the variable "X2_L_STOPCASTING" is handled by the engine? I've been setting it to 0 and 10 respectively to enable and disable casting, which is consistent with the base game scripts I've looked at. Is it just that "0" is treated as "false" (don't stop casting) and "10" treated as "true" (do stop casting), or are there other values that this can be set to for different behaviors?

Thanks in advance for any feedback!

- Andarian
               
               

               
            

Legacy_Pattycake1

  • Jr. Member
  • **
  • Posts: 98
  • Karma: +0/-0
Scripting a Henchman to Use an Item
« Reply #1 on: October 14, 2012, 09:20:49 pm »


               For the first part, what are you trying to get them to use and when?

For the second part I wish I could help ya with that but I'm not sure...
               
               

               
            

Legacy_AndarianTD

  • Hero Member
  • *****
  • Posts: 725
  • Karma: +0/-0
Scripting a Henchman to Use an Item
« Reply #2 on: October 15, 2012, 01:51:45 am »


               

Pattycake1 wrote...

For the first part, what are you trying to get them to use and when?


I'm thinking in terms of a general capability that I could script for a variety of items. What I have in mind is an item with the "Cast Spell" added to it, giving it to the henchman, and having the henchman use it instead of the player. Henchmen will do this spontaneously with items like spell scrolls if their casting flag is enabled. I'm trying to figure out if this is locked into the engine, or if there is a hook into this behavior that would allow me to initiate it from a script.

Hope that helps --
               
               

               
            

Legacy_Pattycake1

  • Jr. Member
  • **
  • Posts: 98
  • Karma: +0/-0
Scripting a Henchman to Use an Item
« Reply #3 on: October 15, 2012, 02:54:57 am »


               I don't remember if there is a specific hook for it. I do know in Jasper AI system he has NPC's switch from ranged weapons to melee weapons. You should look into that to see how he does it.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripting a Henchman to Use an Item
« Reply #4 on: October 15, 2012, 03:24:48 am »


               Short Answer.   No it is part of the engine.    There is a nwnx function that you can use though.  Here is a recent thread nwnx_funcs ActionUseItem()

Long answer.  ( Well I guess short also) :

There may be a way to do it using the talent system.  But I myself have never figured it out or even seen the talent functions disscused much on the boards.
               
               

               
            

Legacy_AndarianTD

  • Hero Member
  • *****
  • Posts: 725
  • Karma: +0/-0
Scripting a Henchman to Use an Item
« Reply #5 on: October 15, 2012, 04:08:01 am »


               Thanks, Lightfoot. I was afraid of that, but it's better to know so that I can cross that idea off my list.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Scripting a Henchman to Use an Item
« Reply #6 on: October 16, 2012, 10:58:17 pm »


               Interesting problem, Andarian. I would think you could do this by sending an item activation event for a particular item, but I haven't looked into doing this for an NPC, only for PCs. I don't know if NPCs respond to that event at all.