User:Fritigern/Scripts
From OpenSimulator
m (→The Data Collector) |
m (→Mem Graph) |
||
Line 272: | Line 272: | ||
The data is stored in individual notecards, one notecard at a time, so that the data can be viewed after a restart. | The data is stored in individual notecards, one notecard at a time, so that the data can be viewed after a restart. | ||
+ | |||
+ | Note that this is still a work in progress. The code is nasty, and needs more love. | ||
=== The Grapher === | === The Grapher === |
Revision as of 23:50, 13 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!
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(); } }
Mem Graph
Two scripts that when put together in the same prim, will keep track of the region's memory usage, and plot the data on the containing prim.
The data is stored in individual notecards, one notecard at a time, so that the data can be viewed after a restart.
Note that this is still a work in progress. The code is nasty, and needs more love.
The Grapher
Version 0.2
integer texsize; integer interval = 60; integer n; float stepsize; integer data; integer numcards; draw() { string CommandList = ""; numcards = llGetInventoryNumber(INVENTORY_NOTECARD); stepsize = (texsize/(float)numcards); integer data = (integer)(llStringTrim(osGetNotecard((string)n),STRING_TRIM))/(1024*1024); CommandList = osSetPenSize( CommandList, 1 ); CommandList = osSetPenColor( CommandList, "Red" ); CommandList = osMovePen( CommandList, 0, texsize - data ); for (n=0;n<(texsize/stepsize);++n) { data = (integer)(llStringTrim(osGetNotecard((string)n),STRING_TRIM))/(1024*1024); integer xpos = (integer)(n*stepsize); CommandList = osDrawLine( CommandList, xpos, texsize-data ); } osSetDynamicTextureData( "", "vector", CommandList, "width:"+(string)texsize+",height:"+(string)texsize, 0 ); } default { state_entry() { texsize = (integer)llGetObjectDesc(); draw(); llSetTimerEvent(interval); } timer() { draw(); } touch_start(integer numdet) { draw(); } }
The Data Collector
Version 0.1
integer interval = 10; // Collect data every 10 seconds. One hour = 3600 seconds integer basetime; integer currenttime; integer mem; integer texsize; default { state_entry() { texsize = (integer)llGetObjectDesc(); mem = osGetSimulatorMemory()/(1024*1024); basetime = 0; osMakeNotecard((string)basetime, (string)osGetSimulatorMemory()); llSetTimerEvent(1); } timer() { mem = osGetSimulatorMemory()/(1024*1024); currenttime = (integer)llGetTime()/interval; llSetText("Time : "+(string)llGetTime()+"\nMem : "+(string)mem+"\nBase : "+(string)basetime+"\nCurrent : "+(string)currenttime,<1,1,1>,1); if (currenttime != basetime) { basetime = currenttime; osMakeNotecard((string)basetime, (string)osGetSimulatorMemory()); if (basetime == texsize) { llSetTimerEvent(0); llOwnerSay("Done!"); } } } }