Table of Contents

ChangeLog

12 October 2011

  • Fixed some trash in the init() handler.

25 September 2011

  • Fixed different sound volumes thanks to Marie Nebestanka

Introduction

This script was tested and works on OpenSim version 0.7.4!

The script will emit a sound while you are walking. This might be ideal for attached bells, footsteps or whatever you may choose. By default, the script uses the SecondLife built-in bell sound. You can change this by dropping any sound clip in the same primitive where the script resides.

Motivation

A script with the same functionality is available on the marketplace for a couple thousand L$. I recreated the script but I have added my own concepts to it. It listens by default on the channel 1, so any commands given to it will have to be issued with /1 prefixed. It also adds a feature to close the channel intermittently to free up resources: when the avatar wearing the primitive containing this script moves, the channel is closed. In order to reopen the channel and make the script accept commands, the avatar has to stand still.

Setup

Supported Commands

All commands work while you are standing still. You have to type one of these commands on the main chat:

/1 jingle on
/1 jingle off
/1 jvolume 7
/1 jhelp

Code

jingle.lsl
///////////////////////////////////////////////////////////////////////////
//  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.        //
///////////////////////////////////////////////////////////////////////////
 
//////////////////////////////////////////////////////////
// --------------------- INTERNALS -------------------- //
integer comHandle;
integer jingle = 1;
integer volume = 10;
key sound = "ed124764-705d-d497-167a-182cd9fa2e6c";
 
init() {
    if(llGetInventoryNumber(INVENTORY_SOUND)) sound = llGetInventoryName(INVENTORY_SOUND, 0);
    comHandle = llListen(1, "", llGetOwner(), "");
    llOwnerSay("Jingle is now listening on channel 1.");
    llOwnerSay("Type /1 jhelp in main chat for a list of commands."); 
}
 
default
{
    state_entry() {
        init();
    }
 
    on_rez(integer num) {
        init();
    }
 
    changed(integer change) {
        if(change & CHANGED_INVENTORY)
            llResetScript();
    }
 
    listen(integer chan,string name,key id,string mes) {
        if(id != llGetOwner()) return;
        if(mes == "jhelp") {
            llOwnerSay("------- START JINGLE COMMANDS -------");
            llOwnerSay("To turn the jingle on:");
            llOwnerSay("/1 jingle on");
            llOwnerSay("To turn the jingle off:");
            llOwnerSay("/1 jingle off");
            llOwnerSay("To change the jingle volume (from 1 to 10):");
            llOwnerSay("/1 jvolume 7");
            llOwnerSay("------- END JINGLE COMMANDS -------");
            return;
        }
        if(mes == "jingle on") {
            jingle = 1;
            llOwnerSay("Jingle is now on.");
            return;
        }
        if(mes == "jingle off") {
            jingle = 0;
            llOwnerSay("Jingle is now off.");
            return;
        }
        if(llList2String(llParseString2List(mes, [" "], [""]), 0) == "jvolume") {
            integer tmpVolume = llList2Integer(llParseString2List(mes, [" "], [""]), 1);
            if(tmpVolume < 1) { 
                volume = 1;
                jump say_volume;
            }
            if(tmpVolume > 10) {
                volume = 10;
                jump say_volume;
            }
            volume = tmpVolume;
@say_volume;
            llOwnerSay("Volume is now: " + (string)volume);
            return;
        }
    }
    moving_start() {
        if(jingle) llPlaySound(sound, ((float)volume/10.0));
        comHandle = llListen(0, "", llGetOwner(), "");
    }
    moving_end() {
        llStopSound();
        llListenRemove(comHandle);
    }
}