Towncrier

From Second Life Wiki
Jump to: navigation, search

Created by Kira Komarov.

Introduction

This is a simple towncrier, probably best suited for roleplay SIMs however it could be used for any location where updates and news have to be broadcasted on the SIM. This script reads lines from a notecard called News and shouts a random line on the main chat at random intervals.

Setup

To set it up, create a notecard called News and populate it with lines. The current limitation is 255 characters per line. Then drop the notecard in a primitive along with the script below. After that, touch the primitive to get a menu which will allow you to configure the intervals between the cries.

The script also allows shared access. To allow other people to configure the towncrier, simply add their avatar names to the list:

list ACCESS_LIST = [ "Kira Komarov", "Lance Lenoirre" ];

in the script below. Any avatar listed in the ACCESS_LIST, as well as the owner of the primitive, will be able to configure the towncrier.

Code

//////////////////////////////////////////////////////////
// [K] Kira Komarov - 2011, License: GPLv3              //
// Please see: http://www.gnu.org/licenses/gpl.html     //
// for legal details, rights of fair usage and          //
// the disclaimer and warranty conditions.              //
//////////////////////////////////////////////////////////
 
//////////////////////////////////////////////////////////
//                   CONFIGURATION                      //
//////////////////////////////////////////////////////////
 
// Change this to include names of avatars who will be 
// able to confiugure this towncrier via a menu. By 
// default, anybody in this list as well as the owner of 
// the towncrier will be able to access the menu.
 
list ACCESS_LIST = [ "Kira Komarov", "Lance Lenoirre" ];
 
//////////////////////////////////////////////////////////
 
//////////////////////////////////////////////////////////
//                     INTERNALS                        //
//////////////////////////////////////////////////////////
key qQuery;
integer qLine;
list qList = [];
 
integer comHandle;
 
default
{
    state_entry()
    {
        integer itra;
        for(itra=0; itra<llGetInventoryNumber(INVENTORY_NOTECARD); ++itra) {
            if(llGetInventoryName(INVENTORY_NOTECARD, itra) == "News")
                jump found_quotes;
        }
        llSay(0, "News notecard not found, please add a notecard called News.");
        return;
@found_quotes;
        qQuery = llGetNotecardLine("News", qLine);
    }
 
    changed(integer change) {
        if(change & CHANGED_INVENTORY) {
            llResetScript();
        }
    }
 
    touch_start(integer total_number)
    {
        if(!~llListFindList(ACCESS_LIST, (list) llDetectedName(0)) || llDetectedKey(0) != llGetOwner())
            return;
        integer comChannel = ((integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
        comHandle = llListen(comChannel, "", llDetectedKey(0), "");
        llDialog(llDetectedKey(0), "Welcome to the Towncrier:\n\nPlease specify the time delay between each cry or turn the towncrier off.", [ "8s","16s","32s","64s","256s", "512s", "1024s", "2048s", "[ OFF ]" ], comChannel);
    }
 
    listen(integer chan,string name,key id,string mes) {
        if(mes == "[ OFF ]") {
            llSetTimerEvent(0.0);
            llInstantMessage(id, "The towncrier is now off.");
            jump close_channel;
        }
        if((integer)mes && !(((integer)mes) & ((integer)mes-1))) {
            llSetTimerEvent((integer)mes);
            llInstantMessage(id, "The towncrier will now shout in " + (string)((integer)mes) + " second intervals."); 
        }
@close_channel;
        llListenRemove(comHandle);
    }
 
    timer() {
        if(!llGetListLength(qList)) return;
        llShout(0, llList2String(qList, (integer)llFrand(llGetListLength(qList))));
    }
 
    dataserver(key id, string data) {
        if(id != qQuery) return;
        if(data == EOF) return;
        if(data == "") jump next_line;
        qList += data;
@next_line;
        qQuery = llGetNotecardLine("News", ++qLine);
    }
}