Skip to content

What's the best way to have an NPC "use" an item

sippelmcsippelmc Member Posts: 45
edited April 2018 in Builders - Scripting
I feel kind of silly if there is a command for this, but I'm looking for the equivalent of ActionUseItem(object oTarget, location lLocation) or something similar.

My use case is I have wand with a cast spell property and want the NPC to use the wand, depleting charges and all, if it is in inventory. I can't find anything like the above, so I am assuming I have to simulate it. Is there a best practice way to do this? I've been googling for a while and can't find anything, and while I have some ideas like getting the itemproperty, casting a fake spell, and setting the charges, I am wondering if there is a better way. Also if I go the above route, how would I simulate the animation where the NPC (humanoid) extends their arms, etc., like they used an item and don't do the actual spellcast?

Thanks!

Comments

  • squattingmonksquattingmonk Member Posts: 59
    edited April 2018

    For doing the actual item activation, you need EventActivateItem(), which can be signaled with SignalEvent(). Note that the first parameter of SignalEvent() needs to be the module, not the NPC doing the activation.

    For the animation, you can use ActionCastFakeSpellAtObject() using SPELLABILITY_ACTIVATE_ITEM as the spell to cast.

    You could create an ActionUseItemOnObject() function like so:
    void ActionUseItemOnObject(object oItem, object oTarget) { event eActivate = EventActivateItem(oItem, GetLocation(oTarget), oTarget); ActionDoCommand(SignalEvent(GetModule(), eActivate)); ActionCastFakeSpellAtObject(SPELLABILITY_ACTIVATE_ITEM, oTarget); }

    Note that I put the event signaling before the animation. When the animation comes first, the signaling doesn't happen until the animation is completely finished, which looks weird. Your mileage may vary.

  • sippelmcsippelmc Member Posts: 45
    Thank you very much kind sir!
Sign In or Register to comment.