Page 1 of 1

Forcing a creature to use an item

PostPosted: Thu Sep 08, 2005 4:23 pm
Author: Deider
I'm looking for a way to force a creature (PC or NPC) to use an item - specifically, drink a potion. Not just standard Bioware potions, but custom potions and even our custom booze. There seems to be no ActionUseItem function. Any thoughts?

PostPosted: Thu Sep 08, 2005 4:42 pm
Author: TiVO25
Okay, I'm no scripting monkey, and only a fledgling tool-set monkey, (i'm tryin' to learn) but I had a notion, so I thought I'd share it, for what it's worth.

If you can't make the individual drink the actual potion (for example) could you at least force the animation, and fire a spell that has the same effect?

PostPosted: Thu Sep 08, 2005 4:59 pm
Author: Deider
TiVO25 wrote:If you can't make the individual drink the actual potion (for example) could you at least force the animation, and fire a spell that has the same effect?


Yes, you can, but there are drawbacks:

- it requires multiple actions, which could generate lag if you were using this for say, a custom AI that has enemies use healkits and custom potions (like the shadowshield pots crafters will one day be able to make)

- it may cast the spell at a different level than is what the potion has, usually a higher level.

- the server window would indicate that the NPC or PC cast a spell instead of drank a potion. Minor, but purists might not like it :)

- this would work for potions, but not our custom booze :(

PostPosted: Thu Sep 08, 2005 5:27 pm
Author: Aloro
Feh. Nope, I don't know how this is done, or if it's even possible. I looked in nwnlexicon, and didn't see anything there that would force an NPC to actually use an item. :?

- Aloro

PostPosted: Thu Sep 08, 2005 5:37 pm
Author: Deider
Tossing some stuff out there that might ignite some minds:

- Sindol mentioned using talents, like TalentBuffSelf or TalentAdvancedBuff. I found a thread on the BioBoards where a guy had modified the talent scripts to get them to make NPCs drink SOME potions, even some custom ones.

- The same poster was able to get NPCs to use healkits, using talents IIRC. I'll link the thread later when I find it again.

PostPosted: Thu Sep 08, 2005 5:43 pm
Author: Krator
yup, talents is the way to go.

PostPosted: Thu Sep 08, 2005 5:53 pm
Author: Aloro
Krator wrote:yup, talents is the way to go.


Nope. :)

TalentBuffSelf works only if you want the NPC to use an item that's recognized as protective or enhancing. It is not a correct general answer to the question, "How can I make an NPC use an item" because it only works on a narrow range of items, which does not include e.g. our custom booze.

Now, you can edit the script x0_i0_talent so that all our custom booze is viewed as protective or enhancing items, but this will then break the utility of TalentBuffSelf for other purposes - because then if you want an NPC to actually buff itself using a potion, it might drink custom booze instead. So tweaking the core AI to allow this to work will break the core AI in undesirable ways.

TalentAdvancedBuff works with spellcasting instead of items, and has the same sorts of restrictions as TalentBuffSelf anyhow.

It's a bit stupid, but I don't know of any generic way to simply make an NPC use an item.

- Aloro

PostPosted: Thu Sep 08, 2005 5:56 pm
Author: Deider
Yeah, those are the downsides. It worked for the guy on the bioboards because he wanted his NPCs to drink Ultravision pots or something. But it wouldn't work for haste potions, because of what Aloro has mentioned above.

PostPosted: Thu Sep 08, 2005 9:19 pm
Author: Sindol
I think just plonking things like booze under the SelfHealing or SelfBuff talents isn't really going to cut it. As far as I can see atm there's no conceivable way to do this nicely. Maybe I'll come up with an ugly fix though. It's getting to be a very complicated problem, where I had initialy suspected a really simple solution. Intriguing.

PostPosted: Thu Sep 08, 2005 10:48 pm
Author: PlasmaJohn
mumbles something about LOCAL vars and conditional branches
Yeah, hackish...

How does it vector into x0_i0_talent? Is it possible to add additional talent categories (TALENT_GET_SLOPPY_WASTED)?

PostPosted: Thu Sep 08, 2005 10:54 pm
Author: Jordicus
what does x0_i0_talent look for anyway? a specific set of tags/resrefs?

PostPosted: Thu Sep 08, 2005 11:09 pm
Author: GG26
griefer!

PostPosted: Thu Sep 08, 2005 11:39 pm
Author: Tigg
For Unique Power and scripted Activate Items, you could add a custom NPC feat via a hak pack, let's call it Activate Item. You could then give that feat to your NPC and give them an item.

When it comes time to use the item, you could set a variable on the creature that holds a reference to the item you want activated.

Next, you'd tell the NPC to use the feat with ActionUseFeat. If your item's action needs a target, then you specify it to ActionUseFeat, if not you could always use OBJECT_SELF or OBJECT_INVALID.

That should call the script for the feat. You'd want to write the script for the feat so that it gets the item to activate off the creature, the target object from ActionUseFeat's second paramater, then gets the target's location, and uses those to construct an EventActivateItem even.

Finally, your script calls SignalEvent to send that event to the module.

The above should run the custom code in your module to fire the unique power or activate item power on your item.


Unfortunately I don't think anyone's actually written this feat. :(

But... maybe it would be worth it to add into a future hak? There sure seem like there's a lot of custom items in Avlis, and writing a feat like that would give an NPC access to all of them.

I don't know, I've actually never written a custom feat before, and certainly not one to suggest what you talented team members should be doing with their time! Just wanted you to be aware of this solution that was suggested.

:) :)