Skip to content

Use item to spawn placeable at targeted location ERROR

I have an item tagged pkegit, and a script named pkegit.
When using the item it should spawn 1 pkegplc, however it spawns multiple pkegplc at once at the same location. What am I doing wrong?

void OnActivate(object oEventItem, object oActTarget, location lActTarget, object oActivator)
{
object oSpawn;
object oPC = oActivator;

// This item must target a location (not an object).
if ( GetIsObjectValid(oActTarget) )
return;

// Spawn "pkegplc".
oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "pkegplc", lActTarget);
}

Comments

  • CyrusJVCyrusJV Member Posts: 36
    Nevermind. I found the cause. In module properties it activates all the on acquire, unacquire ,activate scripts all at once.
  • ProlericProleric Member Posts: 1,286
    edited January 29
    Yes, you need to determine which event is firing the tag-based script - see this example:
    https://nwnlexicon.com/index.php/Grimlar_-_Introduction_To_Tag_Based_Scripting
  • MelkiorMelkior Member Posts: 181
    I never use tag-based scripting, but that's my personal preference.

    Using non-tag scripting, I came up with a multi-use tool (which was mainly for DMs) and which uses the OnActivateItem event to trigger one of five or six conversations, depending on how the tool was used. The script also stores important parameters on the tool so that a conversation script can find out what it needs to know.

    Using tag-based scripting, I doubt I could have implemented the tool as easily as I did.
  • meaglynmeaglyn Member Posts: 149
    That's a little confusing... The tag base scripting bit just gets you to the OnActivateItem handler part w/o having to put a hook in the module's event handler. The rest of your script would be the same. You just need to check the event (GetUserDefinedItemEventNumber()) and only do your activate stuff if it's X2_ITEM_EVENT_ACTIVATE.
Sign In or Register to comment.