Activates but only once Per PC

Alright, here is another script issue I got…

So the scenario:

Player walks to questgiver and gets the quest and needs to walk around the area where the trigger will be activated when walked upon, spawning some goblins to fight the PC.

So here is the problem:
Basically it all works perfectly fine but they spawn every time the player walks over the trigger! I would like to have it set to once per PC but then it does not really work…

#include "nw_i0_generic"


void main()
{
    object oTarget;
    object oSpawn;

 // Get the creature who triggered this event.
    object oPC = GetEnteringObject();

    // Only fire for (real) PCs.
    if ( !GetIsPC(oPC)  ||  GetIsDMPossessed(oPC) )
        return;

    // Only fire once per PC.
    if ( GetLocalInt(oPC, "DO_TWICE__" + GetTag(OBJECT_SELF)) )
        return;
    SetLocalInt(oPC, "DO_TWICE__" + GetTag(OBJECT_SELF), TRUE);

    // Abort if the PC is not exactly at stage 2 of journal quest "FARMHAND".
    if ( GetLocalInt(oPC, "NW_JOURNAL_ENTRYFARMHAND") != 2 )
        return;

    // Spawn some critters.

    oTarget = GetWaypointByTag("WP_GOBO_ATTACK_1");
    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "zep_goblinwor001", GetLocation(oTarget));
    AssignCommand(oSpawn, DetermineCombatRound(oPC));

    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "zep_goblinwor001", GetLocation(oTarget));
    AssignCommand(oSpawn, DetermineCombatRound(oPC));

    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "db_benette_gob", GetLocation(oTarget));
    AssignCommand(oSpawn, DetermineCombatRound(oPC));

    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "db_benette_gob", GetLocation(oTarget));
    AssignCommand(oSpawn, DetermineCombatRound(oPC));

    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "db_benette_gob", GetLocation(oTarget));
    AssignCommand(oSpawn, DetermineCombatRound(oPC));

    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "benette_gob_rang", GetLocation(oTarget));
    AssignCommand(oSpawn, DetermineCombatRound(oPC));

    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "benette_gob_rang", GetLocation(oTarget));
    AssignCommand(oSpawn, DetermineCombatRound(oPC));

    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "benette_g_shaman", GetLocation(oTarget));
    AssignCommand(oSpawn, DetermineCombatRound(oPC));

    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "benette_g_shaman", GetLocation(oTarget));
    AssignCommand(oSpawn, DetermineCombatRound(oPC));
}

So this script I am using but since the PC needs to walk over the trigger but since the PC already had to walk over it since it works on the “untouched” triggers. So how can I make it work?

Use debug messages to see where you are in the script and when, i.e.:

SendMessageToPC(GetFirstPC(), "Testing quest status.");
SendMessageToPC(GetFirstPC(), "Spawning creatures.");

There doesn’t seem to be anything wrong with your code except that the variable check should be after the journal check (or else the trigger will disable itself when walked over before quest is at 2).

What’s the trigger’s tag? Maybe you use it elsewhere.

thanks! It was just me placing it in the wrong order, so thanks for pointing that out for me! <3

But even then that shouldn’t cause the trigger to fire every time as you say.

well, I tried to write a script that would not fire every time a pc steps on it, hence why i added those lines in there BUT it was not firing at all then. Which I assume was just my poor coding skills placing it on the wrong spot :slight_smile: now it seems to fire only once

Ah, OK. Good it works now. As a rule of thumb, this:

    // Only fire once per PC.
    if ( GetLocalInt(oPC, "DO_TWICE__" + GetTag(OBJECT_SELF)) )
        return;
    SetLocalInt(oPC, "DO_TWICE__" + GetTag(OBJECT_SELF), TRUE);

should be placed after all initial exclusion checks or at the very end of the script (assuming you don’t return before).

With one-shot triggers using DestroyObject instead is also a feasible (and more efficient resource-wise) solution.