/* Sundial * AUTHOR: Jon Dewey * SCRIPT VERSION: 0.9 * CREATED WITH NWN VERSION: 1.21 * HISTORY: * -8/6/2002 posted version 0.9 * * * WHAT THIS SCRIPT DOES: * This script makes a sundial work. * It displays the time rounded off to the nearest 10 minutes (you wouldn't be able to know the exact time from looking at a sun dial now would you?) * It also only works during the day time when there is sunlight to make it work. * * HOW TO USE THIS SCRIPT: * Place a sundial object on the map. * Make the sundial usable. * Place this script in the "onUsed" event handler * * * * IMPLIMENTATION NOTES: * Time Compression: * Neverwinter Night's hours are 2 minutes long. GetTimeMinute() will return a 0 or a 1 (by default) * This means that time move 30 times faster in Neverwinter nights (by default) * If you have modified this value you should change the MINUTES_TO_THE_HOUR value to the appropriate value * * Possible Improvements: * It would be nice if the sundial could be made not to work when it was raining, snowing, or when any weather condition that would block the sun was active * Unfortunately NWN has no GetWeather() function so I did not implement this. * If such a function were written it would be easy to implement the test into this script modified by caesarbear 11/10/04 */ void main() {//############################################################################# int miliSecond, second, minute, hour, temp; string displayMinute; int MINUTES_TO_THE_HOUR = 2; // Change this value if you use a different time compression scale and everything else will adjust based off of this value float MILI_SECONDS_TO_SECONDS = 1000.0 / 60.0; object oArea = GetArea(OBJECT_SELF); if (!GetIsDay()) {SpeakString("Sundials only work during day time.");} else if (GetWeather(oArea)==WEATHER_RAIN) //added -cb {SpeakString("Sundials do not work in rain.");} else // is day time { // get time miliSecond = GetTimeMillisecond(); // 0-999 second = GetTimeSecond(); // 0-59 minute = GetTimeMinute(); // 0-1 hour = GetTimeHour(); // 0-23 // convert time // convert minutes temp = 60*minute + second; minute = temp / MINUTES_TO_THE_HOUR; // convert seconds if (minute == 0) {temp = 1000*temp + miliSecond;} else {temp = 1000*(temp % minute) + miliSecond;} second = FloatToInt(temp / MILI_SECONDS_TO_SECONDS); // adjust times for base 60 standards if (second >= 60) { second -= 60; minute++; } if (minute >= 60) { minute -= 60; hour++; } if (hour >= 24) { hour -= 24; //day++; //doesn't display day } // adjust for the acuracy that could reasonably be expected from a sundial... // (I round minutes off the the nearest 10 minutes) // trucates when dividing and thus looses acuracy // minute += 5; //for rounding off minute /= 10; minute *= 10; // adjust time for round off changes if (minute == 60) { minute = 0; hour++; if (hour == 24) {hour = 0;} } // format time if (minute < 10) {displayMinute = "0" + IntToString(minute);} else {displayMinute = IntToString(minute);} // convert from military time to AM and PM and display time if (hour == 12) { SpeakString(IntToString(hour) + ":" + displayMinute + " PM Noon" ); } else if (hour > 12) { hour = hour - 12; SpeakString(IntToString(hour) + ":" + displayMinute + " PM" ); } else {SpeakString(IntToString(hour) + ":" + displayMinute + " AM");} }//END else is day time }//#############################################################################