31 December 2011
DJ List
(previously the description said it should be named DJ Timeout
). As a note, all my notecard systems have to contain a blank new line at the end. Thus, after you add the DJ names, and keys, line-by-line, make sure you have at least one blank line after that.
If you own a club and have DJs entertaining people with a live event, it sometimes happens that the DJ leaves or permanently crashes and forgets or is unable to set the parcel music URL back to the radio station you usually have on when there is no live event. This script helps you do that automatically without intervention so you do not need to attend every live event or be asked to set the music back to the radio. The script also supports a notecard based configuration so you can add your DJs and it will automatically stop trying to set the music URL back to the radio station as soon as it detects one of your DJs in range.
The script takes a notecard called DJ List
(the name is important) which should contain a list of DJs who are able to manipulate the music URL of the land parcel your club is on. Here is what an example notecard looks like with only one DJ:
Morgan LeFay#cb2b66d7-4ca3-6f5e-a126-3108d4a634e9
The first field before the hash represents the Dj's username, in this case Morgan LeFay and the second field after the has represents the key of that DJ.
To set this system up:
DJ List
(the name is important) like described above and list DJs line by line with their usernames and keys.string RADIO_URL = "http://www.google.com"; integer SCAN_INTERVAL = 30; integer SCAN_RANGE = 10; integer ALLOWED_SCAN_FAILS = 10;
the RADIO_URL
is self-explanatory, it represents the URL of the radio station you have on when there is no live event going on. The SCAN_INTERVAL
represents how often (in seconds) the script will attempt to scan for a DJ and check if they are still there. The SCAN_RANGE
represents how far (in meters) the script will scan in order to find a DJ. The last setting, ALLOWED_SCAN_FAILS
is the number of times the script will not find a DJ after which it will set the parcel music URL to the RADIO_URL
: sometimes a DJ may crash or, in very busy clubs, a scan might fail to find a DJ. In that case, it would be annoying to set the music URL to the RADIO_URL
right away. Instead, this setting will allow you to relax the scans and make sure that only after a certain number of times that it fails to find a DJ, it should consider that DJ gone and set the music url to the radio station.
In this, given the configuration above, the script will scan for Morgan LeFay every 30 seconds in a range of 10 meters. If it does not find the DJ Morgan LeFay, 10 times one after the other, it will set the parcel music URL to "http://www.google.com".
/////////////////////////////////////////////////////////////////////////// // Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // // rights of fair usage, the disclaimer and warranty conditions. // /////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // CONFIGURATION // ////////////////////////////////////////////////////////// // // // Set this to the URL of a radio station to which the // land parcel should switch to once the DJ leaves. string RADIO_URL = "http://www.google.com"; // This represents the interval in seconds between scans. integer SCAN_INTERVAL = 30; // This represents the range for the scans. integer SCAN_RANGE = 10; // Whenever a DJ is not found after a scan, the script // will decrement this value. When this value reaches 0, // the script will consider that the DJ has left and // it will switch to the configured radio station. This // is done this way, because sometimes scans fail and // they are unable to locate a DJ. This is some sort of // error fuzz that the script will allow. integer ALLOWED_SCAN_FAILS = 10; // // // END CONFIGURATION // ////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // INTERNALS // /////////////////////////////////////////////////////////////////////////// key dQuery = NULL_KEY; integer dLine = 0; list dList = []; init() { integer itra; for(itra=0; itra<llGetInventoryNumber(INVENTORY_NOTECARD); ++itra) { if(llGetInventoryName(INVENTORY_NOTECARD, itra) == "DJ List") jump found_djlist; } return; @found_djlist; dLine = 0; dQuery = llGetNotecardLine("DJ List", dLine); } default { state_entry() { init(); } on_rez(integer num) { init(); } changed(integer change) { if(change & CHANGED_INVENTORY) llResetScript(); } timer() { if(!dLine) { llSetTimerEvent(.0); llSetParcelMusicURL(RADIO_URL); return; } llSetTimerEvent(30); } sensor (integer num) { integer itra; for(itra=0; itra<num; ++itra) { if(~llListFindList(dList, (list)llDetectedKey(itra))) { dLine = ALLOWED_SCAN_FAILS; llSetTimerEvent(30); return; } } if(dLine > 0) { --dLine; } } dataserver(key query_id, string data) { if(query_id == dQuery) { if(data == EOF) { dLine = ALLOWED_SCAN_FAILS; llSetTimerEvent(30); llSensorRepeat("", "", AGENT, SCAN_RANGE, TWO_PI, SCAN_INTERVAL); return; } if(data == "") jump next_line; list pData = llParseString2List(data, ["#"], [""]); if(llKey2Name(llList2Key(pData, 1)) == llList2String(pData, 0)) dList += llList2Key(pData, 1); @next_line; dQuery = llGetNotecardLine("DJ List", ++dLine); } } }