User:Fritigern/Scripts

From OpenSimulator

< User:Fritigern(Difference between revisions)
Jump to: navigation, search
m (User:Fritigern/NPCstuffs moved to User:Fritigern/Scripts: More scripts will be added, not only NPC stuff.)
m
Line 1: Line 1:
Playing around with NPCs. Here are some scripts that i use to play with them. I constantly change the scripts around, so what you see here, is not necessarily what i currently have in-world.
 
 
 
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 ;-)
 
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 ;-)
  
See also [[NPC]] and [[OSSLNPC]].
+
Some of these scripts will eventually end up in the [[User:Fritigern/OSSL_Script_Library|OSSL Script Library]].
  
NOTE! NPC functions need to be enabled in OpenSim.ini before these scripts will work!
+
== NPC stuff ==
 +
'''''NOTE! NPC functions need to be enabled in OpenSim.ini before these scripts will work!'''''
 +
 
 +
See also [[NPC]] and [[OSSLNPC]].
  
== Populate Region ==
+
=== Populate Region ===
  
 
<source lang = "lsl">
 
<source lang = "lsl">
Line 76: Line 77:
 
</source>
 
</source>
  
== Remove All NPCs ==
+
=== Remove All NPCs ===
  
 
<source lang = "lsl">
 
<source lang = "lsl">
Line 106: Line 107:
 
</source>
 
</source>
  
== Dance! ==
+
=== Dance! ===
 +
This script was made to make all NPCs dance, but they also make regular avatars dance.
  
 
<source lang = "lsl">
 
<source lang = "lsl">
Line 210: Line 212:
  
  
== Emergency Break ==
+
=== Emergency Break ===
  
 
<source lang = "lsl">
 
<source lang = "lsl">

Revision as of 00:29, 14 August 2011

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