Page 1 of 1

encounters at night

PostPosted: Fri Oct 27, 2006 10:57 am
Author: Schaek
hi guys, hopefully one of you can help me with this. I wish to have certain encounters only spawn between dusk and dawn (18:00-06:00 in game). I'm fairly new to the toolset and scripting and have no idea to make this work.

Thanks :D

PostPosted: Fri Oct 27, 2006 11:27 am
Author: Jonezie
Time of day limitations isn't something that you can setup with a standard encounter trigger. There's a couple of options for getting it to work, though.

A) Use a trigger/waypoint combination with a custom OnEnter script instead
B) Add an OnEnter or OnHeatbeat script to the area that runs through and sets the encounter to active/inactive depending on the time of day.

The first one is probably the better option. The script would look something like:

Code: Select all
void main()
{
    if (!GetIsPC(GetEnteringObject()))
        return;   

    if (GetLocalInt(OBJECT_SELF, "TTimeout"))
        return;

    if (!GetIsNight())
        return;

    string sTag = GetTag(OBJECT_SELF);
   
    //Insert Values here
    string sResRef1 = "xxxx"
    string sResRef2 = "yyyy"
    string sResRef3 = "zzzz"

    int iNo1 = #;
    int iNo2 = #;
    int iNo3 = #;
   
    int i;

    object oWP = GetNearestObjectByTag("WP_" + sTag);
    object oNew;

    location lWP = GetLocation(oWP);

    if (sResRef1 != "")
    {
        while (i < iNo1 && i < 10)
        {
            oNew = CreateObject(OBJECT_TYPE_CREATURE, sResRef1, lWP, TRUE);
            SetLocalInt(oNew, "despawn", TRUE);
            i++;
        }
    }

    i = 0;

    if (sResRef2 != "")
    {
        while (i < iNo2 && i < 10)
        {
            oNew = CreateObject(OBJECT_TYPE_CREATURE, sResRef2, lWP, TRUE);
            SetLocalInt(oNew, "despawn", TRUE);
            i++;
        }
    }

    i = 0;

    if (sResRef3 != "")
    {
        while (i < iNo3 && i < 10)
        {
            oNew = CreateObject(OBJECT_TYPE_CREATURE, sResRef3, lWP, TRUE);
            SetLocalInt(oNew, "despawn", TRUE);
            i++;
        }
    }

    SetLocalInt(OBJECT_SELF, "TTimeout", TRUE);
    DelayCommand(1800.0, DeleteLocalInt(OBJECT_SELF, "TTimeout"));
}

WARNING: Untested code

Basically, you need a trigger with a unique tag. You also have a waypoint with tag 'WP_<trigger tag>'. Fill out the blanks for creature resrefs and numbers in the script there, and put it in the OnEnter event of the trigger. Then, it'll function like an encounter, firing when it's stepped on and creating creatures at the waypoint, but only when it's night time. It's set to a respawn timer of 30 RL minutes, is capped at 10 of each creature, and can have 3 different creature types. Creatures will despawn with the avlis despawner. You can get much more complicated than this if you want, but it should do basically what you need.

PostPosted: Fri Oct 27, 2006 1:20 pm
Author: Schaek
Ok thanks a lot Jonezie!

As I said I'm a noob with scripting so I'll see if anyone can make this work for me instead of fucking it up myself. Anyone interested in building this encouter please send me a pm :P

thanks again

PostPosted: Fri Oct 27, 2006 1:41 pm
Author: Czarcasm
There's a script hanging around the Avlis modules for the OnEnter script of the encounter, called "encset_atnight." Here's the script:

Code: Select all
// Name     : encset_atnight.nss
// Purpose  :
// Author   : n.a.
// Modified : March 7, 2004 by Mistcaller
// ** Sets the encounter active only during night times **


void ResetEncounter(float fTimeToWait, int nValue, object encounter)
{
DelayCommand(fTimeToWait, SetEncounterActive(nValue, encounter));
DelayCommand(fTimeToWait, DeleteLocalInt(encounter, "Disabled"));
}
void main()
{
    object oPlayer = GetEnteringObject();
    if (!GetIsPC(oPlayer)) return;
    int nHour = GetTimeHour();
    if((nHour < 6 || nHour > 18) && GetLocalInt(OBJECT_SELF, "Disabled") == 0)
        {
        SetEncounterActive(TRUE,OBJECT_SELF);
        //1500 is 25 minutes
        ResetEncounter(1500.0, TRUE, OBJECT_SELF);
        SetLocalInt(OBJECT_SELF, "Disabled", 1);
        }
    ResetEncounter(3.0, FALSE, OBJECT_SELF);
}

PostPosted: Mon Oct 30, 2006 8:21 am
Author: Kooshy
One neat approach is to make an NPC with a null body model, give them cutscene invisibility, all that concealment stuff to keep them from being seen.

And then in their OnPercieve event, you can do whatever tests and such you need to, and then spawn whatever, based on time of day, level of person/party percieved, a dice roll, intimidate skill ranks that people have.. Some combination.. Whatever you want, really.

It's quite a handy trick, and one of the few ideas used in the Gigaschatten engine that I really liked.

I just thought I'd mention it 'n stuff. :)