User:Fritigern/Scripts

From OpenSimulator

Jump to: navigation, search

These scripts can be really dirty, with hacks, and code commented out, and most likely weird, inefficient, or otherwise questionable ways of doing things. Such is the result of constant fooling around and changing stuffs ;-)

Some of these scripts will eventually end up in the OSSL Script Library.

Contents

NPC stuff

NOTE! NPC functions need to be enabled in OpenSim.ini before these scripts will work!

See also NPC and OSSLNPC.

Populate Region

// touch to create an NPC at a random position in your region. 
// The NPC will be created at 100m up in the air, just for dramatic effect :-)
// Set npcNum to how many NPCs you want.
 
key npc;
vector toucherPos;
integer n;
integer i;
integer npcNum = 5;
integer wait = 0;
string toucher;
key toucherkey;
 
default
{
    state_entry()
    {
        llSetText("Populate this region",<1,1,1>,1);
    }
 
    touch_start(integer number)
    {
        toucher = llKey2Name(llDetectedKey(0));
        toucherkey = llDetectedKey(0);
        state raise;
    }
}
 
state raise
{
    state_entry()
    {
        for (n=0;n<npcNum;++n)
        {
            llSetText("Creating NPC #"+(string)(n+1)+"...",<1,1,1>,1);
            vector npcPos = <llFrand(255),llFrand(255),100>;
            osNpcCreate(toucher, "", npcPos, toucherkey);
 
            if (wait)
            {
                for (i=wait;i>0;--i)
                {
                    llSetText("Creating NPC #"+(string)(n+2)+" in "+(string)i+"...",<1,1,1>,1);
                    llSleep(1);                
                }
            }
        }
        llSetText("Done",<1,1,1>,1);
    }
 
    touch_start(integer number)
    {
        llSay(0,"Removing all NPCs from this scene!");
        list avies = osGetAvatarList();
        for(n=0;n<llGetListLength(avies);n=n+3)
        {
            llOwnerSay("Attempting to remove "+llList2String(avies,n+2)+" with UUID "+llList2String(avies,n+0));
            osNpcRemove((key)llList2Key(avies,n));
        }
 
        llResetScript();
    }
}

Remove All NPCs

// Sometimes, you just want to kill all NPCs in one fell swoop...
// Unfortunatly, from time to time, one or more NPCs do get stuck in the scene, and can not be removed. They can't be removed by this script either.
 
default
{
    state_entry()
    {
        llSay(0, "Here we go now!");
    }
 
    touch_start(integer num)
    {
        llSay(0,"Removing all NPCs from this scene!");
        list avies = osGetAvatarList();
        integer n;
        for(n=0;n<llGetListLength(avies);n=n+3)
        {
            //llOwnerSay(llList2String(avies,n));
            llOwnerSay("Attempting to remove "+llList2String(avies,n+2)+" with UUID "+llList2String(avies,n+0));
            osNpcRemove((key)llList2Key(avies,n));
        }
 
    }
 
}

Dance!

This script was made to make all NPCs dance, but they also make regular avatars dance.

// Get your NPCs (and whoever else may be in the region) to dance.
// To make this work, create a prim, fill it with (dance) animations, put this script in it, click the prim, and PAR-TAY!.
 
list avies;
list thedance;
list olddance;
list dancers;
integer duration = 10;
 
EverybodyDanceNow()
{
    llSetText("Dancing",<1,1,1>,1);
    avies = osGetAvatarList();
    integer n;
 
    if(llGetListLength(thedance) != 0)
    {
        for(n=0;n<llGetListLength(thedance);++n)
        {
            olddance = olddance + llList2String(thedance,n);
        }
    }
 
 
    for(n=0;n<llGetListLength(avies);n=n+3)
    {
        integer animnum = llFloor(llFrand(llGetInventoryNumber(INVENTORY_ANIMATION)));
        string animation = llGetInventoryName(INVENTORY_ANIMATION,animnum);
        key avieID = llList2Key(avies,n);
        dancers = dancers + [avieID];
        thedance = thedance + [animation];
    }
 
    for(n=0;n<llGetListLength(dancers);++n)
    {
        key avie = llList2Key(dancers,n);
        string dance = llList2String(thedance,n);
        osAvatarPlayAnimation(avie, dance);
 
    }
}
 
Stop_HammerTime()
{
    llSetText("Stopped Dancing",<1,1,1>,1);
    integer n;
    for(n=0;n<llGetListLength(dancers);++n)
    {
        key avie = llList2Key(dancers,n);
        string dance = llList2String(thedance,n);
        osAvatarStopAnimation(avie, dance);
    }
        dancers = [];
        thedance = [];
        avies = [];
}
 
default
{    
    touch_start(integer numdet)
    {
        state on;
    }
}
 
state on
{
    state_entry()
    {
        EverybodyDanceNow();
        llSetTimerEvent(duration);
    }
 
    touch_start(integer numdet)
    {
        state off;
    }
 
    timer()
    {
        EverybodyDanceNow();
    }
}
 
 
state off
{
    state_entry()
    {
        Stop_HammerTime();
    }
 
    touch_start(integer numdet)
    {
        state on;
    }
}


Emergency Break

// An emergency break to stop all NPCs animations.
// To make this work, use the same method as in the previous script. Make sure that the animations in the prim are the exact same ones!
 
 
list avies;
list thedance;
list dancers;
 
Stoppit()
{
    avies = osGetAvatarList();
    integer n;
    integer i;
 
    for(n=0;n<llGetListLength(avies);n=n+3)
    {
        key avieID = llList2Key(avies,n);
        dancers = dancers + [avieID];
    }
 
    integer animnum = llGetInventoryNumber(INVENTORY_ANIMATION);
 
    for(n=0;n<llGetListLength(dancers);++n)
    {
        key avie = llList2Key(dancers,n);
 
        for(i=0;i<=animnum;++i)
        {
            string animation = llGetInventoryName(INVENTORY_ANIMATION,i);
            osAvatarStopAnimation(avie, animation);
            llSetText("Avie : "+(string)avie+"\nDance : "+animation,<1,1,1>,1);
        }
    }
    llSetText("EMERGENCY BREAK",<1,1,1>,1);
}
 
 
default
{    
    state_entry()
    {
        llSetText("EMERGENCY BREAK",<1,1,1>,1);
    }
 
    touch_start(integer numdet)
    {
        Stoppit();
    }
 
}
Personal tools
General
About This Wiki