Trying to create a custom summon via item Unique Power

Hey there,

I’m new to nwn scripting (but not scripting in general)

I’ve made a custom summon and am trying to summon it from a 1/per day unique power on a weapon.

From what i’ve been able to find so far online this is as far as i’ve gotten:

In the OnActivateItem Script:

if (GetTag(oItem) == “SmithingAssistant”)
{
location lTarget = GetItemActivatedTargetLocation();
effect eSummon = EffectSummonCreature(“smithinghammer”, VFX_FNF_SUMMON_MONSTER_1, 0.0f, 0);
int nDuration = GetCasterLevel(OBJECT_SELF);
ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eSummon, lTarget, TurnsToSeconds(nDuration ));
}

When I use this nothing happens, whereas a few test things I put there (such as spawning visual effects or non-summon creatures) works.

One post i’ve read suggests that this script is treating the item as the “Summoner” not the player using it, thus the summon doesn’t work, but the post didn’t show how they got around it. Anyone able to help with this?

The module event scripts run as the module not the PC or the item, which also means OBJECT_SELF is the module. You can use GetItemActivator() to get the PC who activated the item and then assign them commands to the PC as needed.

Ah that makes sense! Thanks.

So how do I call the functions using the GetItemActivator object? Something like this?

object bob = GetItemActivator();
bob.ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eSummon, lTarget, TurnsToSeconds(nDuration ));

Or so I need to call this summoning script from a different place?

Take a look at the lexicon. It’s your friend.

https://nwnlexicon.com/index.php?title=EffectSummonCreature

This shows one way to get the code you need to run as the PC. In this case it’s not the application of the effect that matters but the creation of the effect. The PC has to run the EffectSummonCreature call.

You can also do this by making the code into a function (which returns void) and using AssignCommand(). e.g. AssignCommand(bob, doSummon(lTarget));
Then you don’t need an extra script. But the ExecuteScript method show in the lexicon will work just fine.

Ah I understand it now! Got it working with the execute script stuff, that’s making a lot sense how to do stuff in general now too. Thanks a lot man.