Area OnEnter Script fires only partially (sort of solved)

The following script is entered in the Area’s OnEnter-Event. It is supposed to determine daytime, place NPCs accordingly and lock / unlock doors.

a) It determines time of day
b) It lock / unlocks
c) It does NOT transport the NPC, though I have used those commands dozens of times before.

Does anybody have any idea why it doesn’t work?


void main()
{

object oPC = GetEnteringObject();

if (!GetIsPC(oPC)) return;

    object oActor;
    object oDoor;

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

    // If the time is from 5 to 20.
    if ( 5 <= GetTimeHour()  &&  GetTimeHour() <= 20)
    {

       //Transport her to daypoint
       oActor = GetObjectByTag("ct_Bettler");
       AssignCommand(oActor, ActionJumpToObject(GetObjectByTag("wt_audatg")));

       //Unlock the door
       oDoor = GetObjectByTag("dt_FernToHorne");
       SetLocked(oDoor, FALSE);
    }

    else if ( 21 <= GetTimeHour()  ||  GetTimeHour() <= 4 )

    {
        // Tug her in bed
        oActor = GetObjectByTag("ct_Bettler");
        AssignCommand(oActor, ActionJumpToObject(GetObjectByTag("wt_audant")));

        // And lock the door.
        oDoor = GetObjectByTag("dt_FernToHorne");
        SetLocked(oDoor, TRUE);
    }
}

try clearing oActors actions prior to the jump, also, I recommend to use JumpToObject, I actually never used the action variant…

In addition to clearing actions, it might also be necessary to SetAILevel, if the NPC is in a dormant area.

I suspect the test for day should read

if ( 5 >= GetTimeHour()  &&  GetTimeHour() <= 20)

The test for night is redundant - an unqualified “else” would suffice.

You could use GetIsDay instead, which references the dawn and dusk values set in the module properties.

Thanks for the feedback so far. I take it there is nothing downright wrong with the script.

JumpToObject in combination with ClearAllActions aforehand doesn’t work either.

Yes, GetDay is a way, but I want to keep it flexible. Villagers rise at dawn an close shop at dusk. In a big city, that’s different.

“else if” in this version is redundant, true. Thanks for the hint. That is from the first version of the script which was different. I fixed it. Still doesn’t do what I want (didn’t expect it to, though :()

I am thinking of a different approach.

Is the tag correct and the script is actually finding the NPC? And I assume there is only one such tag in the module?

:slight_smile:

Yes. I was checking the tags ruthlessly, cause they’re the source in 90% of troublelike this.

And double post: I got it working. I will post the complete script tonight after some polishing. Thanks for your attention and support. It helped me clear my mind.

Yeah, I was just checking :slight_smile:

So here it is working. Since the tender approach didn’t work, I used a different method: Brute force. The areas surrounding the village have “doormats” (Generic Triggers) at the entrances that fire the following script. It kills all and replaces NPCs according to daytime. For every NPC I have a day and night blueprint. It’s a bit cumbersome but also yields advantages: Different outfits and different convos for example. It is definetely not elegant but it does its job.


#include "nw_i0_spells"

void main()
{

object oPC = GetEnteringObject();

if (!GetIsPC(oPC)) return;

    effect eEffect;
    object oTarget;
    object oActor;
    object oDoor;
    object oSpawn;

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

    // Abort if the local int is not exactly 0.
    if ( GetLocalInt(oPC, "OrcAttack") != 0 )
    {
        SendMessageToPC(oPC, "Attack is ongoing. There is war!");
        return;
    }

    //Kill them All - that is a very crude solution

    DestroyObject(GetObjectByTag("Veran"));
    DestroyObject(GetObjectByTag("ct_Audarae"));

    // If the time is from 5 to 20.
    if ( 5 <= GetTimeHour()  &&  GetTimeHour() <= 20)// && GetLocalInt(oPC, "OrcAttack") == 0)
    {

    //Create actors at daypoints
        if ( GetLocalInt(oPC, "nHornDead") == 0 )
        {
            oTarget = GetWaypointByTag("wt_bentg");
            oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "veran001", GetLocation(oTarget));
        }

    oTarget = GetWaypointByTag("wt_audatg");
    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "audarae003", GetLocation(oTarget));


    //Unlock the door

    oTarget = GetObjectByTag("dt_FernToHorne");
    SetLocked(oTarget, FALSE);

    }
    else
    {

    // Tug them in bed

        if ( GetLocalInt(oPC, "nHornDead") == 0 )
        {
            oTarget = GetWaypointByTag("wt_bennt");
            oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "veran002", GetLocation(oTarget));
        }

    oTarget = GetWaypointByTag("wt_audant");
    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "audarae004", GetLocation(oTarget));

    // Send them to sleep

    eEffect = EffectSleep();

    oTarget = GetObjectByTag("ct_Audarae");
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, eEffect, oTarget);
    oTarget = GetObjectByTag("Veran");
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, eEffect, oTarget);

    // And lock the door.
    oDoor = GetObjectByTag("dt_FernToHorne");
    SetLocked(oDoor, TRUE);

    }
}