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);
}
}
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 :()
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.
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);
}
}