Author Sticky: Post Working Scripts Here
Dscaper Posted: Friday, 05 July 04:11PM
Name: DS_GLOBAL_SDIAL

Function: Displays Time in hh:mm format, hh format at dawn/dusk and no time at night. Thanks to Zinderin for minute/second workaround.

If anyone has functions to grab any environmental vars that will relay weather, please forward them to the address in the code header.

Keywords for forum search: sundial, time, hours, minutes

NWScript:
//::///////////////////////////////////////////////

//:: FileName: ds_global_sdial

//:://////////////////////////////////////////////

/*

Shows the time in hh:mm[am/pm] style for daytime and

hh[am/pm] for dawn and dusk. Will not show time at night.

If you know of a way to grab the weather conditions, please

mail me at craig [at] derby.co.uk.

Attach to OnUsed event.

*/

//:://////////////////////////////////////////////

//:: Created By: Dscaper

//:: with thanks to Brett Lathrope (aka Zinderin) for his beautiful minute and second twink.

//:: Created On: 5th July 2002

//:://////////////////////////////////////////////

void main()

{

  if (GetIsNight()) {

    SpeakString("It is night, therefore you cannot tell the time.",TALKVOLUME_TALK);

    return;

  } else {

    // Get Current Hour

    int workHour = GetTimeHour();

    // Get Current Minute, then Multiply up by 30 (as value returned is 0 or 1)

    int workMinute = GetTimeMinute();

    workMinute = workMinute * 30;

    // Get Current Second, then calc through to generate 15 minute markers

    int workSecond = GetTimeSecond();

    if (workSecond >= 30) workMinute = workMinute + 15;

// DEBUGGER

// string workResult = "Debug ";

// workResult = workResult + IntToString(workHour);

// workResult = workResult + ":";

// workResult = workResult + IntToString(workMinute);

    // Setup Checker Vars

    int workShowMinute;

    string workShowTimeframe;

    string workSMinute;

    if (GetIsDawn()) {

      // Dawn

      workShowMinute = 0;

      workShowTimeframe = "dawn";

    } else {

      if (GetIsDusk()) {

        // Dusk

        workShowMinute = 0;

        workShowTimeframe = "dusk";

      } else {

        // Daytime

        workShowMinute = 1;

        workShowTimeframe = "daytime";

        workSMinute = IntToString(workMinute);

        if (GetStringLength(workSMinute) == 1) {

          // Append 0 to minute

          workSMinute = "0" + workSMinute;

        }

      } // End Daytime Code

    } // End Not Dawn

    // Generate AM - PM

    string workDesignate = "AM";

    if (workHour >= 13) {

      workHour = workHour - 12;

      workDesignate = "PM";

    }

    string workResult = "Because it is ";

    workResult = workResult + workShowTimeframe;

    workResult = workResult + ", you can work out that the time is ";

    if (workShowMinute == 0) {

      workResult = workResult + "roughly ";

    }

    workResult = workResult + IntToString(workHour);

    if (workShowMinute == 1) {

      workResult = workResult + ":" + workSMinute;

    }

    workResult = workResult + workDesignate;

    SpeakString(workResult,TALKVOLUME_TALK);

  } // End Not Night

}