EffectSummonCreature Issue
I'm trying to create a custom creature summon item using tag-based scripting, and I'm stumped as to why it's not working.
Attempting to use creature resref "celestialsummon," and nothing spawns when using a (location targeted) 'activate item.' The script is firing when I use the item in question. No typos that I'm seeing, but nothing is being spawned.
I also have the scripts set on the creature to the corresponding summon scripts as per this nwn wiki page.
Any suggestions?
Here is my small script:
Attempting to use creature resref "celestialsummon," and nothing spawns when using a (location targeted) 'activate item.' The script is firing when I use the item in question. No typos that I'm seeing, but nothing is being spawned.
I also have the scripts set on the creature to the corresponding summon scripts as per this nwn wiki page.
Any suggestions?
Here is my small script:
#include "x2_inc_switches"
void main()
{
int nEvent = GetUserDefinedItemEventNumber(); // Which event triggered this
object oPC; // The player character using the item
object oItem; // The item being used
location lLoc;
// Set the return value for the item event script
// * X2_EXECUTE_SCRIPT_CONTINUE - continue calling script after executed script is done
// * X2_EXECUTE_SCRIPT_END - end calling script after executed script is done
int nResult = X2_EXECUTE_SCRIPT_END;
switch (nEvent)
{
case X2_ITEM_EVENT_ACTIVATE:
// * This code runs when the Unique Power property of the item is used or the item
// * is activated. Note that this event fires for PCs only
oPC = GetItemActivator(); // The player who activated the item
oItem = GetItemActivated(); // The item that was activated
lLoc = GetItemActivatedTargetLocation();
//AssignCommand(oActivator, ClearAllActions());
effect eSummon = EffectSummonCreature("celestialsummon", VFX_IMP_UNSUMMON);
//summon lasts 15min
ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eSummon, lLoc, 900.0);
//SendMessageToPC(GetFirstPC(), "tagbased scripting is alive");
break;
}
// Pass the return value back to the calling script
SetExecutedScriptReturnValue(nResult);
}
0
Comments
Try AssignCommand(oPC, ApplyEffectAtLocation....
Thanks for your help so far.
Is celestialsummon the resref of a creature template in your module?
The Lexicon recommends assigning "a whole code block" to the PC (by which I imagine they mean a function) or ExecuteScript as per the example, though I don't immediately see why either should be necessary.
Try merging the assignation, effect declaration, and application into a single line, like so:
AssignCommand(oPC, ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, EffectSummonCreature("celestialsummon", VFX_IMP_UNSUMMON), lLoc, 900.0));That way the effect is created with the correct owner.
Make you wonder why the Lexicon almost invariably gives examples in which the effect is created first, which I now see is bad practice, as well as redundant.
There's also an argument that inlining makes things less clear/more complex, which might make it more difficult for another to review, or for you when you come back to it. That's a matter of opinion though so.. eh