Files
dsrc/sku.0/sys.server/compiled/game/script/player/alarm_clock.script
T

136 lines
3.5 KiB
Plaintext

/**
*
* Title: alarm_clock.script
* Description: Allows the player to set a messaged alarm at a given time interval.
*/
/***** INCLUDES ********************************************************/
include library.sui;
include library.prose;
include prose_package;
/***** CONSTANTS *******************************************************/
const string_id SID_ALARM_CLOCK_FORMAT = new string_id("player/player_utility.stf", "alarm_clock_format");
const string_id SID_ALARM_CLOCK_1_1000 = new string_id("player/player_utility.stf", "alarm_clock_1_1000");
const string_id SID_ALARM_CLOCK_SET = new string_id("player/player_utility.stf", "alarm_clock_set");
/***** TRIGGERS ********************************************************/
/***** MESSAGEHANDLERS *************************************************/
messageHandler msgAlarmClock()
{
// params holds the dictionary passed from the messageTo
if (params == null)
{
return SCRIPT_OVERRIDE;
}
String sentAlarmMsg = params.getString("message");
sui.msgbox(self, self, sentAlarmMsg, 0,"Alarm Clock", 0, "noHandler");
LOG("LOG_CHANNEL", "Received Alarm Clock message: " + sentAlarmMsg);
return SCRIPT_OVERRIDE;
}
/***** COMMANDHANDLERS *************************************************/
commandHandler alarmClock()
{
//Tokenize text and place tokens in parsedText
java.util.StringTokenizer st = new java.util.StringTokenizer(params);
int totalWords = st.countTokens();
string[] parsedText;
//Format is alarmclock <time> <message>.
if (totalWords > 0)
{
parsedText = new string[totalWords];
}
else
{
return SCRIPT_OVERRIDE;
}
for (int i = 0; st.hasMoreTokens(); i++)
{
parsedText[i] = st.nextToken();
LOG("LOG_CHANNEL", "parsedText[" + i + "] " + parsedText[i]);
}
long alarmDelay = 0;
if (totalWords < 2)
{
//debugConsoleMsg(self, "This is a test!");
sendSystemMessage(self, SID_ALARM_CLOCK_FORMAT);
LOG("LOG_CHANNEL", "Format: /alarmclock <time> <message>");
return SCRIPT_OVERRIDE;
}
else
{
//Convert <time> string into a long
Long time;
try
{
time = new Long(parsedText[0]);
alarmDelay = time.longValue();
}
catch (NumberFormatException err)
{
sendSystemMessage(self, SID_ALARM_CLOCK_FORMAT);
LOG("LOG_CHANNEL", "Format: /alarmclock <time> <message>");
return SCRIPT_OVERRIDE;
}
//LOG("LOG_CHANNEL", "alarmDelay:" + alarmDelay);
if (alarmDelay < 1 || alarmDelay > 1000)
{
sendSystemMessage(self, SID_ALARM_CLOCK_1_1000);
LOG("LOG_CHANNEL", "Alarm time must be from 1 to 1000 minutes");
return SCRIPT_OVERRIDE;
}
else
{
// The remaining array elements are the message. Put them together in a new message string
StringBuffer sb = new StringBuffer();
for (int i = 1; i < parsedText.length; i++)
{
// Add a space after the token unless it's the last one
if (parsedText.length - i == 1)
{
sb.append(parsedText[i]);
}
else
{
sb.append(parsedText[i] + " ");
}
}
String alarmMessage = sb.toString();
LOG("LOG_CHANNEL", "Sending Alarm Clock Message (in "+ alarmDelay + " minutes): " + alarmMessage);
prose_package ppAlarm = prose.getPackage(SID_ALARM_CLOCK_SET);
prose.setDI(ppAlarm, (int)alarmDelay);
sendSystemMessageProse(self, ppAlarm);
//Set up a messageTo using alarmDelay and alarmMessage
dictionary dctMsg = new dictionary();
dctMsg.put("message", alarmMessage);
messageTo(self, "msgAlarmClock", dctMsg, alarmDelay * 60, false);
}
return SCRIPT_OVERRIDE;
}
}