Table of Contents

Shortnote

This script was tested and works on OpenSim version 0.7.4!

This is a simple spinning bottle script used for spin-the-bottle games. It purposefully does not use llApplyRotationalImpulse and physics since that would require a lot of complicated coding just to get the bottle to float properly.

OpenSim Notes

On OpenSim, the code compiles but the rotations seem a little slow, this may be because of the minimal llSetTimerEvent scheduling value that the script uses.

Code

The code uses the progress bar from the ascii progress bar.

spin_bottle.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.        //
///////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3    //
///////////////////////////////////////////////////////////////////////////
string wasProgress(integer percent, integer length, list symbols) {
    percent /= (integer)((float)100.0/(length));
    string p = llList2String(symbols,0);
    integer itra = 0;
    do {
        if(itra>percent-1) p += llList2String(symbols,2);
        else p += llList2String(symbols,1);
    } while(++itra<length);
    return p + llList2String(symbols,3);
}
 
integer spin = 0;
 
default
{
    state_entry() {
        llSetLocalRot(llEuler2Rot(<0., 90., 50.> * DEG_TO_RAD));
        state arm;
    }
}
 
state arm {
    state_entry() {
        llSetText("☛ Power ☚\n" + wasProgress((integer)(spin*100.0/45.0), 20, ["[", "█", "░", "]"]), <1,1,1>, 1);
    }
    touch(integer num) {
        if(spin > 44) return;
        ++spin;
        llSetText("☛ Power ☚\n" + wasProgress((integer)(spin*100.0/45.0), 20, ["[", "█", "░", "]"]), <1,1,1>, 1);
    }
    touch_end(integer num) {
        state release;
    }
}
 
state release {
    state_entry() {
        llSetTimerEvent(1.175494351E-38);
    }
    timer() {
        if(spin< 1) {
            llSetTimerEvent(0);
            spin = 0;
            state arm;
        }
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROT_LOCAL, llGetLocalRot() * llEuler2Rot(<0., 0., spin> * DEG_TO_RAD)]);
        llSetText("☛ Power ☚\n" + wasProgress((integer)(spin*100.0/45.0), 20, ["[", "█", "░", "]"]), <1,1,1>, 1);
        --spin;
    }
}