GetDay() GetNight() Help

I have 4 dryads already placed on my map. They are already worshipping and dancing and are set to - SetCommandable(FALSE_OBJECT_SELF); I need a script that will spawn the dryads only at night.

My code is fubar - `void main()
{
object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;

if ( GetIsDay() )
{
SetLocalInt(oPC, "DAY_SET__", 1);

object oDryad1 = GetObjectByTag("NW_DRYAD_001");
object oDryad2 = GetObjectByTag("NW_DRYAD_002");
object oDryad3 = GetObjectByTag("NW_DRYAD_003");
object oDryad4 = GetObjectByTag("NW_DRYAD_004");

DestroyObject(oDryad1, 0.5);
DestroyObject(oDryad2, 1.0);
DestroyObject(oDryad3, 1.5);
DestroyObject(oDryad4, 2.0);
}
else if ( !GetIsDay() )
{
    location lLoc1 = GetLocation(GetWaypointByTag("WP_DRYAD_01"));
    location lLoc2 = GetLocation(GetWaypointByTag("WP_DRYAD_02"));
    location lLoc3 = GetLocation(GetWaypointByTag("WP_DRYAD_03"));
    location lLoc4 = GetLocation(GetWaypointByTag("WP_DRYAD_04"));
    CreateObject(OBJECT_TYPE_CREATURE, "dryad001", lLoc1);
    CreateObject(OBJECT_TYPE_CREATURE, "dryad002", lLoc2);
    CreateObject(OBJECT_TYPE_CREATURE, "dryad001", lLoc3);
    CreateObject(OBJECT_TYPE_CREATURE, "dryad002", lLoc4);
}

}
`
Thanks for any help. :frowning:

Hehe :smiley:

if (GetIsNight() ) // there will be a dusk and a dawn as well
{
  if (GetLocalInt(GetArea(oPC), "DAY_SET__") == -1) return; // do only once per day/night
  SetLocalInt(GetArea(oPC), "DAY_SET__", -1);  //-1 to bypass the initial value of 0

  // spawn dryads here
}
else // and nothing else here
{
  if (GetLocalInt(GetArea(oPC), "DAY_SET__") == 1) return; // do only once per day/night
  SetLocalInt(GetArea(oPC), "DAY_SET__", 1);  // set to area, since there might be more than one area with DN

  // destroy dryads here
}

(written without the toolset, there might be small errors)

Code now.

void main()
{
    object oPC = GetEnteringObject();
    if (!GetIsPC(oPC)) return;

    if (GetIsNight() ) // there will be a dusk and a dawn as well
    {
        if (GetLocalInt(GetArea(oPC), "DAY_SET__") == -1) return; // do only once per day/night
        SetLocalInt(GetArea(oPC), "DAY_SET__", -1);  //-1 to bypass the initial value of 0

        // spawn dryads here
        location lLoc1 = GetLocation(GetWaypointByTag("WP_DRYAD_01"));
        location lLoc2 = GetLocation(GetWaypointByTag("WP_DRYAD_02"));
        location lLoc3 = GetLocation(GetWaypointByTag("WP_DRYAD_03"));
        location lLoc4 = GetLocation(GetWaypointByTag("WP_DRYAD_04"));
        CreateObject(OBJECT_TYPE_CREATURE, "dryad001", lLoc1);
        CreateObject(OBJECT_TYPE_CREATURE, "dryad002", lLoc2);
        CreateObject(OBJECT_TYPE_CREATURE, "dryad001", lLoc3);
        CreateObject(OBJECT_TYPE_CREATURE, "dryad002", lLoc4);
    }
    else // and nothing else here
    {
    if (GetLocalInt(GetArea(oPC), "DAY_SET__") == 1) return; // do only once per day/night
    SetLocalInt(GetArea(oPC), "DAY_SET__", 1);  // set to area, since there might be more than one area with DN

    // destroy dryads here
    DestroyObject(GetObjectByTag("NW_DRYAD_001"), 0.5);
    DestroyObject(GetObjectByTag("NW_DRYAD_002"), 0.5);
    }
}



Always the same problem. The dryads won’t disappear. The code I was currently writing had the same problem, although that code was for OnHeartbeat:

void main()
{
    object oPC = GetFirstPC();
    if (!GetIsPC(oPC)) return;

    if ( GetIsNight() )
    {
        location lLoc1 = GetLocation(GetWaypointByTag("WP_DRYAD_01"));
        location lLoc2 = GetLocation(GetWaypointByTag("WP_DRYAD_02"));
        location lLoc3 = GetLocation(GetWaypointByTag("WP_DRYAD_03"));
        location lLoc4 = GetLocation(GetWaypointByTag("WP_DRYAD_04"));
        CreateObject(OBJECT_TYPE_CREATURE, "dryad001", lLoc1);
        CreateObject(OBJECT_TYPE_CREATURE, "dryad002", lLoc2);
        CreateObject(OBJECT_TYPE_CREATURE, "dryad001", lLoc3);
        CreateObject(OBJECT_TYPE_CREATURE, "dryad002", lLoc4);

        if ( GetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF)) )
             return;
        SetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE);
    }
    else if ( GetIsDay() )
    {
        object oDryad1 = GetObjectByTag("NW_DRYAD_001");
        SetCommandable(TRUE, oDryad1);
        AssignCommand(oDryad1, ClearAllActions());
        DestroyObject(oDryad1, 0.5);

        object oDryad2 = GetObjectByTag("NW_DRYAD_002");
        SetCommandable(TRUE, oDryad2);
        AssignCommand(oDryad2, ClearAllActions());
        DestroyObject(oDryad2, 0.5);

        object oDryad3 = GetObjectByTag("NW_DRYAD_003");
        SetCommandable(TRUE, oDryad3);
        AssignCommand(oDryad3, ClearAllActions());
        DestroyObject(oDryad3, 0.5);

        object oDryad4 = GetObjectByTag("NW_DRYAD_004");
        SetCommandable(TRUE, oDryad4);
        AssignCommand(oDryad4, ClearAllActions());
        DestroyObject(oDryad4, 0.5);
    }
}

At this point I was even toying with SetCommandable, but I think that has no effect on DestroyObject().

Anyway, thanks Mmat… :slight_smile: :upside_down_face:

Edit: Since the dryads spawn with dance animations playing, would it be necessary to ClearAllActions() first, then call DestroyObject()?

Are the tags OK? Remember tags are case sensitive.

I got it working now. I should say Mmat got it working! I had the script on the wrong handler. :slight_smile: :crazy_face:

Thanks again Mmat!

Nope. No errors. :slight_smile:

Edit: Since the dryads spawn with dance animations playing, would it be necessary to ClearAllActions() first, then call DestroyObject()?

Nope, it’s useless, as well as SetCommandable. If the creature doesn’t disappear, but the code is correct, then you probably need to use “SetDestroyable(TRUE);”

Hows about to learn something about functions?

To spawn an object you need several lines of code:

object SpawnDryad (string blueprint, string waypoint)
{
  location l = GetLocation(GetWaypointByTag(waypoint));
  object o = CreateObject(OBJECT_TYPE_CREATURE, blueprint, l);
  return o;
}

in the main, you need just a single line, something like

object dryad1 = SpawnDryad ("dryad001",  "WP_DRYAD_01");

This way, you can spawn the hordes of the underdark with single lines, and avoid to repeat endlessly multiple-line statements (bloating the main code this way). It improves readability greatly.

The code could improved further with a loop.

Thanks for the pointer - god knows I can use them.