User:Allen Kerensky/Myriad Lite/Myriad Lite Narrator-Preview6.lsl

From OpenSimulator

Jump to: navigation, search

Myriad_Lite_Narrator-Preview6.lsl

// Myriad_Lite_Narrator-Preview6.lsl
// Copyright (c) 2012 by Allen Kerensky (OSG/SL) All Rights Reserved.
// This work is dual-licensed under
// Creative Commons Attribution (CC BY) 3.0 Unported
// http://creativecommons.org/licenses/by/3.0/
// - or -
// Modified BSD License (3-clause)
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, 
//   this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
// * Neither the name of Myriad Lite nor the names of its contributors may be
//   used to endorse or promote products derived from this software without
//   specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
// NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The Myriad RPG System was designed, written, and illustrated by Ashok Desai
// Myriad RPG System licensed under:
// Creative Commons Attribution (CC BY) 2.0 UK: England and Wales
// http://creativecommons.org/licenses/by/2.0/uk/
 
string  VERSION = "0.0.9"; // version number
string  VERDATE = "20120704"; // version date
 
// GLOBALS - CUSTOMIZE THESE IN SETUP() FUNCTION
string MESSAGE; // the description
integer BECOME_PHANTOM; // become phantom, such as an area detect, or stay non-phantom such as when used in floor prim?
integer IGNORE_OBJECTS; // do not send narration to objects (like bullets!) which blunder in
integer RPEVENT_FLAG; // send as Myriad Lite RP event, or as play Say into local chat? HINT - make secrets just for HUD users and public tour stuff for everyone
 
// GLOBAL RUNTIME variables which change as the script runs
list agents; // list of UUIDs active in sim
key agent_key; // key of who we're narrating to
integer dynachan; // temporary place to calculate the player dynamic channel
 
// MYRIAD LITE MESSAGE REFERENCE
// CHANPLAYER - OUT - RPEVENT|narrationtext
 
integer CHAN_REGION = -999;
integer HAND_RUMOR;
integer CHAN_RUMOR;
string  API_RUMOR_FIND = "RUMOR_SERVER_FIND";
string  API_RUMOR_FOUND = "RUMOR_SERVER_FOUND";
string  API_RUMOR_PUT = "RUMOR_PUT";
 
integer FLAG_DEBUG;
string CHAN_PREFIX          = "0x"; // channel prefix for calculating dynamic channel numbers
string API_DIVIDER          = "|"; // The field divider within BAM messages
string  RUMOR_VISITED; // sent as rumor suffix
 
//============================================================================
// DEBUG
//============================================================================
DEBUG(string debugmsg) {
    if ( FLAG_DEBUG == TRUE ) llInstantMessage(llGetOwnerKey(llGetKey()),"DEBUG: "+debugmsg);
}
 
//============================================================================
// DEFAULT STATE
//============================================================================
default {
    //------------------------------------------------------------------------
    // COLLISION_START EVENT
    //------------------------------------------------------------------------    
    collision_start(integer detected) {        
        while ( detected-- ) {
            agent_key = llDetectedKey(detected); // who hit us?
            if ( IGNORE_OBJECTS == TRUE && llGetOwnerKey(agent_key) != agent_key ) return; // ignoring objects
            if ( llListFindList(agents,[agent_key]) == -1 ) { // does this key already appear in agents list?
                if ( llGetFreeMemory() <= 256 ) { // is memory low?
                    agents = []; // free some memory by emptying agents list
                }
                agents = [agent_key] + agents; // add this agent
                if ( RPEVENT_FLAG == TRUE ) { // say as Myriad Lite RP event, or plain local chat say?
                    dynachan = (integer)("0x"+llGetSubString(agent_key,0,6)); // calculate avatar's dynamic HUD channel
                    llSay(dynachan,"RPEVENT|"+MESSAGE); // send them the narration as an RP event
                } else {
                    llSay(PUBLIC_CHANNEL,MESSAGE); // say to anyone, HUD or not
                }
                // Send a rumor that the player progressed in the quest
                if ( CHAN_RUMOR != 0 ) {
                    string who = llKey2Name(agent_key);
                    string rumor = API_RUMOR_PUT+API_DIVIDER+who+API_DIVIDER+who+RUMOR_VISITED;
                    llRegionSay(CHAN_RUMOR,rumor);
                }                
            }
        }
    }
 
    //------------------------------------------------------------------------
    // LISTEN EVENT
    //------------------------------------------------------------------------
    listen(integer channel,string name,key id,string message) {
        channel = 0; // LSLINT
        name = ""; // LSLINT        
        // Rumor server found, save its channel number
        if ( message == API_RUMOR_FOUND ) {
            CHAN_RUMOR = (integer)(CHAN_PREFIX + llGetSubString((string)id,0,6));
            return;
        }        
    }
 
    //------------------------------------------------------------------------
    // ON_REZ EVENT
    //------------------------------------------------------------------------
    on_rez(integer params) {
        params = 0; // LSLINT
        llResetScript(); // on rez, reset the script from the top
    }
 
    //------------------------------------------------------------------------
    // STATE_ENTRY EVENT
    //------------------------------------------------------------------------
    state_entry() {
        // EDIT ME TO SAY The SHORT NAME and LONG DESCRIPTION of this area
        // Be sure to mention what is seen to the north, east, south, west, above, below, and any RP clues for this area
        MESSAGE = "(Myriad Lite Central Example BAM Area) An example of the Myriad Lite implementation of Baroun's Adventure Machine (BAM) for implementing roleplaying quests. Wear a Myriad Lite HUD with BAM Module, and click the BAM Adventure Giver NPC. To the east is the Myriad_Future example region. To the north is the tabletop roleplaying area with Myriad_Modern example region beyond it. To the northwest is the example combat and healing area. To the west is the Myriad Lite character builder area and Myriad_Medieval region beyond it. To the south is the Myriad Combat region.";
        // EDIT ME TO SAY a rumor that the person visited this area
        RUMOR_VISITED=" visited the Myriad_Central example BAM area.";
        // DONE EDITING
        BECOME_PHANTOM = TRUE; // become phantom, such as an area detect, or stay non-phantom such as when used in floor prim?
        IGNORE_OBJECTS = TRUE; // do not send narration to objects (like bullets!) which blunder in
        RPEVENT_FLAG = TRUE; // send as Myriad Lite RP event, or as play Say into local chat? HINT - make secrets just for HUD users and         
        agents = []; // start with an empty list of who we've shown the narration to
        if ( BECOME_PHANTOM == TRUE ) { //if we're not in a floor prim
            llVolumeDetect(TRUE); // set us up to detect collisions with the prim volume
        } else {
            llVolumeDetect(FALSE); // only detect collisions when run into, rather than through
        }
        if ( HAND_RUMOR != 0 ) llListenRemove(HAND_RUMOR);
        CHAN_RUMOR = (integer)(CHAN_PREFIX + llGetSubString((string)llGetKey(),0,6));
        HAND_RUMOR = llListen(CHAN_RUMOR,"",NULL_KEY,"");
        llRegionSay(CHAN_REGION,API_RUMOR_FIND); // send request for rumor server channel
    }
}
Personal tools
General
About This Wiki