// Davan Camus, 2005 October // Generic template starter script // a little of everything integer COMMAND_CHANNEL = 80; // set to zero to disable integer gListenerNumber = 0; float gTickSize = 0; integer gDebug = 1; integer gDialogCommandChannel; // temporary, during dialog up integer gDialogListenerNumber = 0; // temporary, during dialog up float gChatTime = 0; //chat commands only work while positive... doDialog resets it. float gChatTimeout = 50.0; // how long the channel is active after a dialog starts. string gVersion = "0.0"; // wrapper for set timer event, where we keep track of it. setTimerEvent(float t) { gTickSize = t; llSetTimerEvent(t); } // d([this, that, the other]); prints debug stuff // (I find it easier to type the [list,notation] than all // that tedious casting-to-string and adding stuff d(list debugList) { if(!gDebug) return; else { string s = (string)(debugList); llOwnerSay("(dbg) "+s); } } // All commands (link or chat) come through here // Empty command brings up dialog. doCommand(key av,string message) { gChatTime = gChatTimeout; if(message == "") { doDialog(av); return; } list messageL = llParseString2List(message,[" "],[]); string cmd = llToLower(llList2String(messageL,0)); integer arg1 = llList2Integer(messageL,1); string arg1S = llList2String(messageL,1); integer arg1OnOff = 0; if(llToLower(arg1S) == "on" || ((integer)arg1S > 0) || arg1S == "" ) arg1OnOff = 1; if(cmd == "cmd1") { llSay(0,"cmd1: " + arg1S); } else if(cmd == "cmd2") { llWhisper(0,"cmd2: " + arg1S); } // ... } integer doListen() { noListen(); // clear out any old one... gDialogCommandChannel = COMMAND_CHANNEL + 100 + (integer)(llFrand(10000)); gDialogListenerNumber = llListen(gDialogCommandChannel,"","",""); gChatTime = gChatTimeout; // start the countdown return gDialogCommandChannel; } noListen() { gChatTime = 0; llListenRemove(gDialogListenerNumber); } // dialogs start by getting a random temporary listener number, which // stays active for a little while. You can use over and over, // the timeout gets reset each time a command is received. doDialog(key av) { doListen(); // turn on the chat listener for the next command. list choices = [ "cmd 1","cmd 2","cmd 3" ]; string s = "Device" + "\nVersion" + gVersion + "\nMechanism by Davan Camus"; llDialog(av,s,choices,gDialogCommandChannel); // a short-lived channel number } init() { llListenRemove(gListenerNumber); if(COMMAND_CHANNEL) { gListenerNumber = llListen(COMMAND_CHANNEL,"","",""); d(["listening on ",COMMAND_CHANNEL]); } setTimerEvent(10); } default { on_rez(integer n) { llResetScript(); } state_entry() { init(); d(["state_entry"]); } touch_start(integer total_number) { d(["touched by: ",llDetectedName(0)]); doDialog(llDetectedKey(0)); } listen(integer channel,string name,key id,string message) { d(["listen (",name," on ",channel,"): ",message]); doCommand(id,message); } timer() { // dialog timeout if(gChatTime > 0) { gChatTime -= gTickSize; // if(gChatTime <= 0) noListen(); // no more chat. } } } // end of file