Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Script: Single Channel Listener with Dialog
- // Author: ThalesMiletus
- //
- // Place script in a prim and rezz. Touch the prim to add your avi to the
- // listening list, touch again to remove. Enter the channel you want to listen
- // to in the dialog. The script will send whatever messages are broadcast on
- // the specified specified channel to all avi's in the list. Changing the
- // channel will change it for all avi's in the list.
- integer dialog_chan = -666; // The evil channel, avoid at all costs. :)
- integer listen_chan; // listening channel set by user
- integer timeout = 30; // seconds for the input dialog to timeout
- integer channel_is_set = FALSE;
- string long_name = "Channel Listener";
- integer dialog_listener;
- integer chan_listener = 0;
- vector text_color = <1.0,1.0,1.0>;
- list users = []; // list of avis that are listening
- SendMessageToAll(integer channel, string message)
- {
- integer i=0;
- integer length = llGetListLength(users);
- while (i < length)
- {
- llRegionSayTo(llList2Key(users, i), 0,
- "(ch "+(string)channel+"): " + message);
- i++;
- }
- }
- default
- {
- state_entry()
- {
- llSetText(long_name, text_color, 1);
- }
- touch_start(integer num_detected)
- {
- key id = llDetectedKey(0);
- // If avi is already in list, remove, otherwise add.
- integer idx;
- idx = llListFindList(users, [id]);
- if (idx == -1)
- {
- string msg;
- users += id;
- llRegionSayTo(id, 0, "Added you to "+long_name+"!");
- if (channel_is_set)
- {
- llRegionSayTo(id, 0, "Listening channel already set to: " +
- (string)listen_chan + ".");
- msg = "\nNOTE!! Current listening channel set to " + (string)listen_chan
- + ".\n\nYou can change the channel for everyone or select Ignore.\n"
- + "You have "+(string)timeout+"s before the dialog times out.";
- }
- else
- {
- msg = "\nListening channel not set. Set a channel.\n\n"
- + "You have "+(string)timeout+"s before the dialog times out.";
- }
- llTextBox(id, msg, dialog_chan); // Ask user what channel to set, if any.
- dialog_listener = llListen(dialog_chan,"",NULL_KEY,"");
- // Set a timer to close the listener in case user gives no input.
- llSetTimerEvent(timeout);
- }
- else
- {
- users = llDeleteSubList(users, idx, idx);
- llRegionSayTo(id, 0, "Removed you from "+long_name+" on channel " +
- (string)listen_chan + ". Bye!");
- }
- }
- listen(integer channel, string name, key id, string message)
- {
- string trim_msg = llStringTrim(message, STRING_TRIM);
- if (channel == dialog_chan)
- {
- llListenRemove(dialog_listener); // clean up dialog listener
- llSetTimerEvent(0);
- integer new_listen_chan = (integer)trim_msg;
- // Convert number back to string to confirm that a valid number was
- // found and not just defaulted to 0.
- integer valid_value = ((string)new_listen_chan == trim_msg);
- if (valid_value)
- {
- if (channel_is_set)
- {
- llListenRemove(chan_listener); // clean up previous listener
- }
- chan_listener = llListen(new_listen_chan,"",NULL_KEY,"");
- SendMessageToAll(new_listen_chan, "!NOTICE! " + llGetUsername(id) +
- " has set the listening channel to: " + (string)new_listen_chan);
- llSetText(long_name + " (chan: "+ (string)new_listen_chan +")",
- text_color, 1);
- listen_chan = new_listen_chan;
- channel_is_set = TRUE;
- }
- }
- else if (channel == listen_chan)
- {
- SendMessageToAll(channel, message);
- }
- }
- //timer event, result of the llSetTimerEvent
- timer()
- {
- llListenRemove(dialog_listener);
- //set timer event to 0
- llSetTimerEvent(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement