User:Viktoria Dovgal/Simple CB simulator: Difference between revisions
New page: <lsl> // Simple CB simulator, drop in a prim and attach or just use // ====================================================================== // Licensing // =============================... |
No edit summary |
||
| Line 81: | Line 81: | ||
if (change & CHANGED_OWNER) { | if (change & CHANGED_OWNER) { | ||
Setup(); | Setup(); | ||
Hello(); | |||
} | } | ||
} | } | ||
Revision as of 03:12, 25 June 2008
<lsl> // Simple CB simulator, drop in a prim and attach or just use
// ====================================================================== // Licensing // ====================================================================== // Copyright ©2008 Viktoria Dovgal // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // ======================================================================
// the channel you use to talk to your radio
integer local_channel = 19; // it's a CB right?
// The default public channel if you don't pick another. integer broadcast_channel = -4040808;
// global globules key owner; string handle; // resident name by default integer local_listener; integer broadcast_listener; string range;
Setup() {
owner = llGetOwner(); handle = llKey2Name(owner); range = "shout";
// clean up after old listeners, if any llListenRemove(local_listener); llListenRemove(broadcast_listener);
// start up the new ones local_listener = llListen(local_channel, "", "", ""); broadcast_listener = llListen(broadcast_channel, "", "", "");
}
PrintStatus() {
llOwnerSay("Handle \"" + handle + "\", " + range + ", channel " + (string)broadcast_channel);
}
Hello() {
llOwnerSay("CB simulator, type /" + (string)local_channel + "/help for commmands");
PrintStatus();
}
default {
state_entry() {
Setup();
Hello();
}
on_rez(integer rezparam) {
Hello();
}
changed (integer change) {
if (change & CHANGED_OWNER) {
Setup();
Hello();
}
}
listen(integer channel, string name, key id, string message) {
if (channel == local_channel) { // possibly from owner
if (llGetOwnerKey(id) == owner) { // it is!
list command_list = llParseString2List(message, [" "], []);
integer command_list_length = llGetListLength(command_list);
string command = llList2String(command_list, 0);
if (command == "/channel") {
if (command_list_length == 1) { // just asking
PrintStatus();
}
else {
integer new_channel = (integer)llList2String(command_list, 1);
if (new_channel >= 0) {
llOwnerSay("Channel must be a number less than zero.");
}
else {
llListenRemove(broadcast_listener); // close the old one
broadcast_channel = new_channel;
broadcast_listener = llListen(broadcast_channel, "", "", ""); // open the new
PrintStatus();
}
} // "/channel"
}
if (command == "/handle") {
if (command_list_length == 1) { // just asking
PrintStatus();
}
else {
handle = llStringTrim(llGetSubString(message, 7, -1), STRING_TRIM);
PrintStatus();
} // "/handle";
}
else if (command == "/region") { // cover entire region but not across edges
range = "region";
PrintStatus();
}
else if (command == "/shout") { // 100m range, crosses regin boundaries
range = "shout";
PrintStatus();
}
else if (command == "/status") {
PrintStatus();
}
else if (command == "/help") {
llOwnerSay("CB simulator help:");
llOwnerSay(" /"+(string)local_channel+ "/channel -nn : change channel, must be a negative number");
llOwnerSay(" /"+(string)local_channel+ "/handle xxx : change handle");
llOwnerSay(" /"+(string)local_channel+ "/region : talk to entire region, but this region only");
llOwnerSay(" /"+(string)local_channel+ "/shout : talk up to 100m away, including nearby regions");
llOwnerSay(" /"+(string)local_channel+ "/status : show channel and range");
llOwnerSay(" /"+(string)local_channel+ "/help : you're soaking in it");
llOwnerSay(" /"+(string)local_channel+ " (anything else) : text is broadcast");
}
else { // just talking i guess!
if (range == "region") {
llRegionSay(broadcast_channel, message);
}
else {
llShout(broadcast_channel, "[" + handle + "] " + message);
llOwnerSay("<" + handle + "> " + message); // echo
}
} // just talking
} // owner check
} // local_channel
else if (channel == broadcast_channel) { // incoming
llOwnerSay(message);
} // broadcast_channel
}
} </lsl>