Aller au contenu

Photo

Is there a way to make an NPC use an item's special property? (Like cast a spell)


  • Veuillez vous connecter pour répondre
11 réponses à ce sujet

#1
ColorsFade

ColorsFade
  • Members
  • 1 271 messages
 I have an enemy carrying a dagger that can cast a spell. I want the NPC to use it in combat. Is there a way to do this, or do I have to "fake" it in a combat script and have them just cast the spell?

#2
kevL

kevL
  • Members
  • 4 074 messages
not sure. Set him to plot and start attacking

( Do i remember seeing a 'Use Equippable items' flag ...? )

#3
-Semper-

-Semper-
  • Members
  • 2 259 messages
i think it's easier to script a specific ai where you define the condition of the spell when to be cast. like for instance if the npc's hp drop below a certain percentage or at a random number.

#4
ColorsFade

ColorsFade
  • Members
  • 1 271 messages
I can't find a Use Equippable Items flag...

I'll probably just fake it then. I can't get the character to cast the spell either, even using bCheat=TRUE. I'll just spawn it in myself.

#5
rjshae

rjshae
  • Members
  • 4 506 messages
A few months back I added a post to the "Broken Functions List" thread about a problem with the creature AI. This issue causes a creature with no items in their non-equipped inventory to ignore an equipped item's useable properties. If that is the case, you might try the HasAnItem() fix and see if it helps; it seemed to work when I tested it.

#6
ColorsFade

ColorsFade
  • Members
  • 1 271 messages
What is the HasAnItem() fix rjshae? Could you elaborate? Is it as simple as placing an item in the character's inventory?

#7
rjshae

rjshae
  • Members
  • 4 506 messages
Yes, placing an item in the character's inventory will work because that will cause GetFirstItemInInventory() to return that item. But inserting the HasAnItem() function call (listed out in the other post) will fix the problem for all creatures because it always searches through every equipment slot until it finds something. The drawback is that you need to use a local copy of the "hench_i0_ai" script in your module/campaign to make that modification.

Modifié par rjshae, 18 mars 2013 - 04:59 .


#8
ColorsFade

ColorsFade
  • Members
  • 1 271 messages

rjshae wrote...

Yes, placing an item in the character's inventory will work because that will cause GetFirstItemInInventory() to return that item. But inserting the HasAnItem() function call (listed out in the other post) will fix the problem for all creatures because it always searches through every equipment slot until it finds something. The drawback is that you need to use a local copy of the "hench_i0_ai" script in your module/campaign to make that modification.


A local copy probably wouldn't kill me. 

Another question however: How do you explicitely tell the NPC to use the item? Is there a way to do that? Because I haven't seen it yet. What causes an NPC to decided to use a charge on an item instead of performing some other attack action or casting another spell? 

I'm thinking if I want fine-grained control over such a tactic, I just need to script it into the event. 

#9
rjshae

rjshae
  • Members
  • 4 506 messages
IIRC, there's a way to make the creature run its own AI script; I think it's a local variable you set to the name of the custom script. Alas I don't have the code in front of me at the moment.

#10
kevL

kevL
  • Members
  • 4 074 messages
( i done Rj's script changes )

the #include is really 'hench_i0_itemsp', function InitializeItemSpells()

and it's been compiled into 'hench_o0_ai', 'hench_o0_heal', 'hench_o0_act'

imo, it's player-side responsibility to correct those. (But if you want to go ahead, natch). Builder-side, just throw a broken item in inventory ...


Making an NPC use an item seems to involve "talents" and relies on the deep, dark bowels of the AI. eg, Forcing an NPC to swig a potion isn't possible, per se.

- at least, the furthest I've got is just give 'em the potion and let the RNG AI do what it does, regarding item use. haven't played w/ ItemProp Activation tho.

Modifié par kevL, 18 mars 2013 - 11:43 .


#11
ColorsFade

ColorsFade
  • Members
  • 1 271 messages

kevL wrote...

Making an NPC use an item seems to involve "talents" and relies on the deep, dark bowels of the AI. eg, Forcing an NPC to swig a potion isn't possible, per se.

- at least, the furthest I've got is just give 'em the potion and let the RNG AI do what it does, regarding item use. haven't played w/ ItemProp Activation tho.


I started looking at talents/skills and was wondering if a skill check like Use Magic Item would cause an NPC to be able to cast a spell from a dagger. It looks like it's possible - the native function calls look like they could get the job done, But I decided it was way easier to "fake" it. 

Right now, what I do is have the NPC (in conversation) do the CastFakeSpellAtLocation, and then I delay a call to a custom function to CreateObject (because CreateObject returns the object, so it won't work with Delay). And that's okay, because my custom wrapper method needed to set faction, etc, anyway. 

Timed just right, it looks like the NPC casts the spell... which is awesome. And the item to do it sits in their hand/inventory, so the player is none the wiser. 

#12
Darin

Darin
  • Members
  • 282 messages
I've noticed that there are certain items creatures won't use (like alchemist fire), but you can give them the ability in the special abilities/spells bit of the creature menus...to solve your issue, you could just give the creature in question that spell at the same level as the item's version; in game you justify it with the item (players will see the item and go "oh, that's how fighter mcgee was able to throw a fireball...or whatever).