Skip to content

EffectSummonCreature Issue

echooechoo Member Posts: 43
edited June 2021 in Builders - Scripting
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:
#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);
}

Comments

  • ProlericProleric Member Posts: 1,282
    The object running item activation is always the module, so implicitly you're asking the module to summon a creature. My understanding is that only creatures can summon anything.

    Try AssignCommand(oPC, ApplyEffectAtLocation....
  • echooechoo Member Posts: 43
    Hmm, that doesn't seem to work for me. With this line in the above script:
    AssignCommand(oPC, ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eSummon, lLoc, 900.0));
    

    Thanks for your help so far.
  • ProlericProleric Member Posts: 1,282
    Well, that is necessary, but clearly not sufficient.

    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.
  • WilliamDracoWilliamDraco Member Posts: 175
    edited June 2021
    As said - the summon effect needs an "owner" - I.E. the summoner, and the way the engine figures that out is by who is running the script. The Owner/creator is the script-runner at the time of effect creation (not effect application).

    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.
  • ProlericProleric Member Posts: 1,282
    @WilliamDraco Good insight - as it happens, I always create effects inline, as per your example, which would explain why I never had that particular problem.

    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.
  • echooechoo Member Posts: 43
    @WilliamDraco This did the trick. Thanks ?
  • WilliamDracoWilliamDraco Member Posts: 175
    Proleric wrote: »
    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.
    I think it perhaps helps to separate the steps and show them as being separate, individual aspects - before being slightly more advanced and inlining.

    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
Sign In or Register to comment.