Some scripts

RegionControls is a set of simple scripts I use to control the color and
alpha of parts of my sims.  SLDB is the LSL half of a database system
for OS/SL that writes to an external MySQL database.
This commit is contained in:
Jessica Pixel
2013-05-14 13:58:48 -04:00
commit b7ad3ccfb7
19 changed files with 1384 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
+215
View File
@@ -0,0 +1,215 @@
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
*.pubxml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#############
## Windows detritus
#############
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
+18
View File
@@ -0,0 +1,18 @@
key requestid; // just to check if we're getting the result we've asked for; all scripts in the same object get the same replies
default
{
touch_start(integer number)
{
requestid = llHTTPRequest("http://liftedpixel.net/sldb/test_remote.php",
[HTTP_METHOD, "POST",
HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
"parameter1=something&parameter2=anotherthing");
}
http_response(key request_id, integer status, list metadata, string body)
{
if (request_id == requestid)
llWhisper(0, "Web server said: " + body);
}
}
+19
View File
@@ -0,0 +1,19 @@
integer CHANNEL = 8654;
string COMMAND = "please die";
default
{
state_entry()
{
llListen( 8654, "", NULL_KEY, "" );
}
listen(integer channel, string name, key id, string message)
{
if ( llToLower(message) == llToLower(COMMAND) )
{
llSay( PUBLIC_CHANNEL, "Cleaning up " + llGetObjectName() + " [" + llGetKey() + "]." );
llDie();
}
}
}
+447
View File
@@ -0,0 +1,447 @@
// This script is licensed under Creative Commons BY-NC-SA
// See <http://creativecommons.org/licenses/by-nc-sa/3.0/>
//
// You may not use this work for commercial purposes.
// You must attribute the work to the author, Jeff Kelley.
// You may distribute, alter, transform, or build upon this work
// as long as you do not delete the name of the original author.
integer DEBUG_ON = TRUE;
DEBUG(string message) {if (DEBUG_ON) llOwnerSay(message);}
///////////////////////////////////////////////////////////////////
// Part 1 : Datasource
///////////////////////////////////////////////////////////////////
// The goal of the datasource is to read a file in script's memory
// At the moment, we support three datasources:
//
// http:// A web file
// card://cardname A notecard in the objects's inventory
// card://uuid/cardname A notecard from the LSL server 'uuid'
// (requires a server script, not included)
//
// Edit the 'datasource' string to fit your need
//
//string datasource = "card://Destinations";
//string datasource =
//"card://e511d6c0-7588-4157-a684-8ca5f685a077/Destinations";
//string datasource = "http://my_web_server/path_to_file/Destinations";
string datasource = "card://Destinations";
string datasorceData; // The content of the datasource
readFile(string source) {
list parse = llParseString2List (source, ["/"],[]);
string s0 = llList2String (parse, 0);
string s1 = llList2String (parse, 1);
string s2 = llList2String (parse, 2);
// Web server: fall through http_response event
if (s0 == "http:") sendHTTPRequest (source);
// LSL server : fall through dataserver event
// If no UUID : fall through dataserver event
if (s0 == "card:")
if (isUUID(s1)) osMessageObject ((key)s1, "READ "+s2);
else readNotecard (s1);
}
integer isUUID (string s) {
list parse = llParseString2List (s, ["-"],[]);
return ((llStringLength (llList2String (parse, 0)) == 8)
&& (llStringLength (llList2String (parse, 1)) == 4)
&& (llStringLength (llList2String (parse, 2)) == 4)
&& (llStringLength (llList2String (parse, 3)) == 4)
&& (llStringLength (llList2String (parse, 4)) == 12));
}
///////////////////
// Notecard reader
///////////////////
// Since osGetNotecard has Threat Level = VeryHigh
// we stick to the old, slow, clumsy notecard reader
string ncName; // Name of the notecard to be read
key ncQueryID; // id of dataserver queries
integer ncLine; // Current line being read
readNotecard (string name) {
ncName = name;
ncLine = 0;
ncQueryID = llGetNotecardLine(ncName, ncLine++); // request first line
}
addtoNotecard (string data) {
datasorceData += data+"\n";
ncQueryID = llGetNotecardLine(ncName, ncLine++); // Request next line
}
///////////////////
// Http stuff
///////////////////
key httpQueryId;
sendHTTPRequest (string url) {
httpQueryId = llHTTPRequest(url,
[ HTTP_METHOD, "GET", HTTP_MIMETYPE,"text/plain;charset=utf-8" ], "");
}
string URI2hostport (string uri) {
list parse = llParseString2List (uri, [":"], []);
return llList2String (parse, 0)
+":" + llList2String (parse, 1);
}
///////////////////////////////////////////////////////////////////
// Part 2 : Parsing & accessors
///////////////////////////////////////////////////////////////////
list destinations; // Strided list for destinations
integer NAME_IDX = 0; // Index of region name in list
integer COOR_IDX = 1; // Index of grid coordinates in list
integer HURL_IDX = 2; // Index of hypergrid url in list
integer HGOK_IDX = 3; // Index of validity flag in list
integer LAND_IDX = 4; // Index of landing point in list
integer N_FIELDS = 5; // Total number of fields
parseFile (string data) {
list lines = llParseString2List (data,["\n"],[]);
integer nl = llGetListLength (lines);
integer i; for (i=0;i<nl;i++)
parseLine (llList2String(lines,i));
}
parseLine (string line) {
if (line == "") return; // Ignore empty lines
if (llGetSubString (line,0,1) == "//") { // Is this a comment?
llOwnerSay ("(Comment) "+line);
return;
}
list parse = llParseStringKeepNulls (line, ["|"],[]);
string grid = llList2String (parse, 0); // Grid name
string name = llList2String (parse, 1); // Region name
string gloc = llList2String (parse, 2); // Coordinates
string hurl = llList2String (parse, 3); // HG url
string coor = llList2String (parse, 4); // Landing
// Parse and check grid location
parse = llParseString2List (gloc, [","],[]);
integer xloc = llList2Integer (parse, 0); // X grid location
integer yloc = llList2Integer (parse, 1); // Y grid location
vector hisLoc = <xloc, yloc, 0>;
vector ourLoc = llGetRegionCorner()/256;
integer ok =( llAbs(llFloor(hisLoc.x - ourLoc.x)) < 4096 )
&& ( llAbs(llFloor(hisLoc.y - ourLoc.y)) < 4096 )
&& ( hisLoc != ourLoc);
// Parse and check landing point
parse = llParseString2List (coor, [","],[]);
integer xland = llList2Integer (parse, 0); // X landing point
integer yland = llList2Integer (parse, 1); // Y landing point
integer zland = llList2Integer (parse, 2); // Z landing point
vector land = <xland, yland, zland>;
if (land == ZERO_VECTOR) land = <128,128,20>;
// Note: grid and region names merged into one field
destinations += [grid+" "+name, gloc, hurl, ok, land];
}
///////////////////
// List accessors
///////////////////
string dst_name (integer n) { // Get name for destination n
return llList2String (destinations, N_FIELDS*n +NAME_IDX);
}
string dst_coord (integer n) { // Get coords for destination n
return llList2String (destinations, N_FIELDS*n +COOR_IDX);
}
vector dst_landp (integer n) { // Get landing point for destination n
return llList2Vector (destinations, N_FIELDS*n +LAND_IDX);
}
string dst_hgurl (integer n) { // Get hypergrid url for destination n
return llList2String (destinations, N_FIELDS*n +HURL_IDX);
}
integer dst_valid (integer n) { // Get validity flag for destination n
return llList2Integer (destinations, N_FIELDS*n +HGOK_IDX);
}
////////////////////////////////////////////////////////////
// Part 3 : Drawing
////////////////////////////////////////////////////////////
integer TEXTURE_SIZE = 512;
integer DISPLAY_SIDE = 1;
integer FONT_SIZE = 10; // Depends on TEXTURE_SIZE
integer COLUMNS = 3;
integer ROWS = 16;
string validCellColor = "CadetBlue";
string invalCellColor = "IndianRed";
string emptyCellColor = "DarkGray";
string cellBorderColor = "White";
string backgroundColor = "Gray";
string drawList;
displayBegin() {
drawList = "";
}
displayEnd() {
osSetDynamicTextureData ( "", "vector", drawList,
"width:"+(string)TEXTURE_SIZE+",height:"+(string)TEXTURE_SIZE, 0);
}
drawCell (integer x, integer y) {
integer CELL_HEIGHT = TEXTURE_SIZE / ROWS;
integer CELL_WIDHT = TEXTURE_SIZE / COLUMNS;
integer xTopLeft = x*CELL_WIDHT;
integer yTopLeft = y*CELL_HEIGHT;
// Draw grid
drawList = osSetPenColor (drawList, cellBorderColor);
drawList = osMovePen (drawList, xTopLeft, yTopLeft);
drawList = osDrawRectangle (drawList, CELL_WIDHT, CELL_HEIGHT);
integer index = (y+x*ROWS);
string cellName = dst_name(index);
integer cellValid = dst_valid(index);
string cellBbackground;
if (cellName == "") cellBbackground = emptyCellColor; else
if (cellValid) cellBbackground = validCellColor; else
cellBbackground = invalCellColor;
// Fill background
drawList = osSetPenColor (drawList, cellBbackground);
drawList = osMovePen (drawList, xTopLeft+2, yTopLeft+2);
drawList = osDrawFilledRectangle (drawList, CELL_WIDHT-3, CELL_HEIGHT-3);
xTopLeft += 2; // Center text in cell
yTopLeft += 6; // Center text in cell
drawList = osSetPenColor (drawList, "Black");
drawList = osMovePen (drawList, xTopLeft, yTopLeft);
drawList = osDrawText (drawList, cellName);
}
drawTable() {
displayBegin();
drawList = osSetPenSize (drawList, 1);
drawList = osSetFontSize (drawList, FONT_SIZE);
drawList = osMovePen (drawList, 0, 0);
drawList = osSetPenColor (drawList, backgroundColor);
drawList = osDrawFilledRectangle (drawList, TEXTURE_SIZE, TEXTURE_SIZE);
integer x; integer y;
for (x=0; x<COLUMNS; x++)
for (y=0; y<ROWS; y++)
drawCell (x, y);
displayEnd();
}
integer getCellClicked(vector point) {
integer y = (ROWS-1) - llFloor(point.y*ROWS); // Top to bottom
integer x = llFloor(point.x*COLUMNS); // Left to right
integer index = (y+x*ROWS);
return index;
}
///////////////////////////////////////////////////////////////////
// Part 4 : Action routnes: when clicked, when http test succeed
///////////////////////////////////////////////////////////////////
string CLICK_SOUND = "clickSound"; // Sound to play when board clicked
string TELPT_SOUND = "teleportSound"; // Sound to play when teleported
integer JUMP_DELAY = 2; // Time to wait before teleport
string hippo_url; // URL for http check
string telep_url; // For osTeleportAgent
key telep_key; // For osTeleportAgent
vector telep_land; // For osTeleportAgent
integer action (integer index, key who) {
string name = dst_name (index);
string gloc = dst_coord (index);
vector land = dst_landp (index);
string hurl = dst_hgurl (index);
integer ok = dst_valid (index);
if (name == "") return FALSE; // Empty cell
if (!ok) llWhisper (0, "This region is too far ("+gloc+")");
if (!ok) return FALSE; // Incompatible region
llWhisper (0, "You have selected "+name+", location "+gloc);
// Pri??parer les globales avant de sauter
telep_key = who; // Pass to postaction
telep_url = hurl; // Pass to postaction
telep_land = land; // Pass to postaction
hippo_url = "http://"+URI2hostport(hurl); // Pass to http check
DEBUG ("Region name: " +name +" "+gloc+" (Check="+(string)ok+")");
DEBUG ("Landing point: " +(string)land);
DEBUG ("Hypergrid Url: " +hurl);
DEBUG ("Hippochek url: " +hippo_url);
llTriggerSound (CLICK_SOUND, 1.0);
return TRUE;
}
postaction (integer success) {
if (success) {
llWhisper (0, "Fasten your seat belt, we move!!!");
llPlaySound (TELPT_SOUND, 1.0); llSleep (JUMP_DELAY);
osTeleportAgent(telep_key, telep_url, telep_land, ZERO_VECTOR);
} else {
llWhisper (0, "Sorry, host is not available");
}
}
///////////////////////////////////////////////////////////////////
// State 1 : read the data and draw the board
///////////////////////////////////////////////////////////////////
default {
state_entry() {
llOwnerSay ("Reading data from "+datasource);
readFile (datasource);
}
// Handler for card:// datasource
dataserver(key id, string data) {
// Internal card reader
if (id == ncQueryID) {
if (data != EOF) addtoNotecard (data);
else state ready; // File in datasorceData
// External card server
} else {
datasorceData = data;
state ready; // File in datasorceData
}
}
// Handler fot http:// datasource
http_response(key id,integer status, list meta, string body) {
if (id != httpQueryId) return;
datasorceData = body;
state ready; // File in datasorceData
}
state_exit() {
llOwnerSay ("Done. Initializing board");
parseFile(datasorceData);
drawTable();
}
}
///////////////////////////////////////////////////////////////////
// State 2 : running, we pass most of our time here
///////////////////////////////////////////////////////////////////
state ready {
state_entry() {
llWhisper (0, "Ready");
}
touch_start (integer n) {
key whoClick = llDetectedKey(0);
vector point = llDetectedTouchST(0);
integer face = llDetectedTouchFace(0);
integer link = llDetectedLinkNumber(0);
//if (link != LINK_ROOT)
//if (whoClick == llGetOwner()) llResetScript();
//else return;
if (point == TOUCH_INVALID_TEXCOORD) return;
if (face != DISPLAY_SIDE) return;
integer ok = action (getCellClicked(point), whoClick);
if (!ok) return; // Incompatible grid coordinates
integer USE_MAP = (llGetObjectDesc() == "usemap");
// llMapDestination works only in touch events
// We must invoke it here, bypassing http check
// Return so osTeleportAgent will not be called
if (USE_MAP) {
llMapDestination (telep_url, telep_land, ZERO_VECTOR);
return;
}
// Proceed to http check which
// will chain to osTeleportAgent
llWhisper (0, "Checking host. This may take up to 30s, please
wait...");
state hippos; // Perform HTTP check
}
changed(integer what) {
if (what & CHANGED_REGION) llResetScript();
if (what & CHANGED_INVENTORY) llResetScript();
if (what & CHANGED_REGION_RESTART) llResetScript();
}
}
///////////////////////////////////////////////////////////////////
// State 3 : HTTP host check
///////////////////////////////////////////////////////////////////
state hippos {
state_entry() {
sendHTTPRequest (hippo_url);
llSetTimerEvent (60);
}
http_response(key id,integer status, list meta, string body) {
if (id == httpQueryId)
postaction (status == 200);
state ready;
}
timer() {
llSetTimerEvent (0);
postaction (FALSE);
state ready;
}
}
+12
View File
@@ -0,0 +1,12 @@
string message = "xxxxx"; // What text to set
vector color = < 0, 0, 1 >; // The text color
float alpha = 1; // How transparent the text is
default
{
state_entry()
{
// Set the text
llSetText( message , color , alpha );
}
}
+117
View File
@@ -0,0 +1,117 @@
//Note: this code was adapted from someone.
// added option to play the first animation in inventory
// if there isn't one, you'll just 'turn180' like normal
key mkLoungingAgentKey = NULL_KEY;
integer miPermissionsAcquired = FALSE;
string animation; // What animation to play
default
{
touch_end(integer x)
{
llResetScript();
}
state_entry()
{
animation = llGetInventoryName( INVENTORY_ANIMATION, 0 ); // get the first animation in the object
if ( animation == "" )
{
llSay( PUBLIC_CHANNEL, "Insert animation." );
}
else
{
llSay( PUBLIC_CHANNEL, "Animation: " + animation );
}
//overriden sit target
//lower them a bit
vector vLoungeTarget = <0.00, 0.00, 1.50>;
rotation rX;
rotation rY;
rotation rZ;
rotation r;
//build rotations
//Note: this is broken out like this to simplify the
// process of finding the correct sit angle. I
// use the following form until I have the rotation
// that I want perfect, and then I simply
// hardcode the perfected quaterion and remove
// this mess.
//
rX = llAxisAngle2Rot( <1,0,0>, 0 * DEG_TO_RAD); //cartwheel
rY = llAxisAngle2Rot( <0,1,0>, 0 * DEG_TO_RAD); //sumersault
rZ = llAxisAngle2Rot( <0,0,1>, 0 * DEG_TO_RAD); //turn in place
//combine rotations
r = rX * rY * rZ;
//override 'sit' on pie menu
llSetSitText( "Stand" );
//override default sit target and rotation on prim
llSitTarget( vLoungeTarget, r );
}
changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if ( mkLoungingAgentKey == NULL_KEY && agent != NULL_KEY )
{
//changed user
//cache new user key and request their permissions
mkLoungingAgentKey = agent;
llRequestPermissions(mkLoungingAgentKey,PERMISSION_TRIGGER_ANIMATION);
}
else if ( mkLoungingAgentKey != NULL_KEY && agent == NULL_KEY)
{
//user is getting up
if ( miPermissionsAcquired )
{
//restore anims
llStopAnimation("turn_180");
}
//reset the script to release permissions
llResetScript();
}
}
}
run_time_permissions(integer parm)
{
if(parm == PERMISSION_TRIGGER_ANIMATION)
{
//set permission flag
miPermissionsAcquired = TRUE;
//cancel the sit anim
llStopAnimation("sit");
if ( animation == "" )
{
// if there is no animation, default to turn_180
llStartAnimation("turn_180");
}
else
{
// otherwise play the first animation in the inventory
llStartAnimation( animation );
}
}
}
}
+86
View File
@@ -0,0 +1,86 @@
//// For SLDB ////
string url = "http://www.liftedpixel.net/sldb/pp_data.php"; // Location of PHP script
string secret = ""; // Minimal security
string separator = "|"; // for between values
// for the http_request
key put_id;
key get_id;
key del_id;
// Write to the database
PutData(key id, list fields, list values, integer verbose)
{
string args;
args += "?key="+llEscapeURL(id)+"&action=put&separator="+llEscapeURL(separator);
args += "&fields="+llEscapeURL(llDumpList2String(fields,separator));
args += "&values="+llEscapeURL(llDumpList2String(values,separator));
args += "&secret="+llEscapeURL(secret);
put_id = llHTTPRequest(url+args,[HTTP_METHOD,"GET",HTTP_MIMETYPE,"application/x-www-form-urlencoded"],"");
}
// Read from the database
GetData(key id, list fields, integer verbose)
{
string args;
args += "?key="+llEscapeURL(id)+"&action=get&separator="+llEscapeURL(separator);
args += "&fields="+llEscapeURL(llDumpList2String(fields,separator))+"&verbose="+(string)verbose;
args += "&secret="+llEscapeURL(secret);
get_id = llHTTPRequest(url+args,[HTTP_METHOD,"GET",HTTP_MIMETYPE,"application/x-www-form-urlencoded"],"");
}
// Delete from the database
DelData(key id, list fields, integer verbose)
{
string args;
args += "?key="+llEscapeURL(id)+"&action=del&separator="+llEscapeURL(separator);
args += "&fields="+llEscapeURL(llDumpList2String(fields,separator))+"&verbose="+(string)verbose;
args += "&secret="+llEscapeURL(secret);
del_id = llHTTPRequest(url+args,[HTTP_METHOD,"GET",HTTP_MIMETYPE,"application/x-www-form-urlencoded"],"");
}
//// End For SLDB ////
default
{
touch_start(integer total_number)
{
//Everything must be formatted to a string
//PutData(llGetOwner(),["name","size","location"],[name,sSize,sLocation],TRUE);
//GetData(llGetOwner(),["name","size","location"],FALSE);
//DelData(llGetOwner(),["ALL_DATA"],TRUE);
}
http_response(key id, integer status, list metadata, string body)
{
if((id != put_id) && (id != get_id) && (id != del_id))
{
// If the keys didn't match, ignore
return;
}
if(status != 200)
{
// If an error, say so
body = "ERROR: CANNOT CONNECT TO SERVER";
}
// Say the returned message
llOwnerSay(body);
// Write the returned info to a list
list listData = llParseStringKeepNulls(body, ["|"], []);
// Save the values to variables
string name = llList2String(listData, 0);
string size = (string)llList2String(listData, 1);
string location = (string)llList2String(listData, 2);
// Return the info
llOwnerSay("-----");
llOwnerSay("Name:" + name);
llOwnerSay("Size:" + size);
llOwnerSay("Location:" + location);
}
}
+6
View File
@@ -0,0 +1,6 @@
A collection of scripts written in LSL.
I'm sure most will work in Second Life, but I have not tested them.
Jessica Pixel
http://liftedpixel.net/pixelplanet
@@ -0,0 +1,17 @@
integer channel = 1234; // The channel to listen on
string objectName = "Color changer"; // The name of the object doing the talking
default
{
state_entry()
{
// Start listening on the channel for the object
llListen( channel , objectName , NULL_KEY, "" );
}
listen( integer channel, string name, key id, string message )
{
// Set color to the heard vector
llSetColor( (vector)message, ALL_SIDES );
}
}
@@ -0,0 +1,91 @@
float time = 60.0; // How often to check status
// Some colors for later
vector GREEN = <0,1,0>;
vector RED = <1,0,0>;
// The UUID and name of the object owner
key UUID;
string name;
//// For SLDB ////
string url = "http://www.liftedpixel.net/sldb/pp_data.php";
string secret = "";
string separator = "|";
key put_id;
key get_id;
key del_id;
PutData(key id, list fields, list values, integer verbose)
{
string args;
args += "?key="+llEscapeURL(id)+"&action=put&separator="+llEscapeURL(separator);
args += "&fields="+llEscapeURL(llDumpList2String(fields,separator));
args += "&values="+llEscapeURL(llDumpList2String(values,separator));
args += "&secret="+llEscapeURL(secret);
put_id = llHTTPRequest(url+args,[HTTP_METHOD,"GET",HTTP_MIMETYPE,"application/x-www-form-urlencoded"],"");
}
//// End For SLDB ////
default
{
state_entry()
{
llWhisper ( PUBLIC_CHANNEL, "Starting up..." );
// Start the update timer
llSetTimerEvent( time );
// Get the UUID and name of the object owner
UUID = llGetOwner();
name = llKey2Name( UUID );
// Change the object name
llSetObjectName( name + "'s Online Status" );
// Check online status now
llRequestAgentData( UUID , DATA_ONLINE );
}
timer()
{
// Check online status
llRequestAgentData( UUID , DATA_ONLINE );
}
dataserver(key queryid, string data)
{
if ( data == "1" ) // If they're online
{
llSetColor( GREEN , ALL_SIDES ); // Set the object color to green
llSetText( name + "\nis Online", GREEN, 1 ); // Set the hover text
PutData( UUID, ["status"], ["online"], TRUE ); // Write status to database
}
if ( data == "0" ) // If they're offline
{
llSetColor( RED , ALL_SIDES ); // Set the object color to red
llSetText( name + "\nis Offline", RED, 1 ); // Set the hover text
PutData( UUID, ["status"], ["offline"], TRUE ); // Write status to database
}
}
http_response(key id, integer status, list metadata, string body)
{
// If the keys don't match, ignore
if((id != put_id) && (id != get_id) && (id != del_id)) return;
if( status != 200 ) // If there is an error
{
llWhisper( PUBLIC_CHANNEL , "Error writing status." );
}
if ( status == 200 ) // If everything is fine
{
//llWhisper( PUBLIC_CHANNEL , "Status written." );
}
// llOwnerSay(body);
}
}
@@ -0,0 +1,73 @@
// Listen 2234
// Repeats what's heard on the specified channel on the public channel
// Touch to toggle on and off
// What channel to listen on
integer channel = 0;
// Name to listen to
string name = "";
// Key to listen to
key id = NULL_KEY;
// Message to listen for
string message = "";
// Color of hovertext
vector green = <0,1,0>;
vector red = <1,0,0>;
// Alpha of hovertext
float alpha = 1.0;
default
{
state_entry()
{
// Create the hovertext
string hovertext = "Listening to channel\n+[" + (string)channel + "]+";
// Set the hovertext
llSetText( hovertext, green, alpha );
// Start listening
llListen( channel , name , id , message );
// Whisper the hovertext message for good measure
llWhisper( PUBLIC_CHANNEL, hovertext );
}
listen( integer channel, string name, key id, string message )
{
// Repeast the heard message on the public channel
llWhisper( PUBLIC_CHANNEL, name + " said " + message );
}
touch_start(integer x)
{
// When touched, switch to off state
state off;
}
}
state off
{
state_entry()
{
// Create the hovertext
string hovertext = "Not listening to channel\n+[" + (string)channel + "]+";
// Set the hovertext
llSetText( hovertext, red, alpha );
// Whisper the hovertext message for good measure
llWhisper( PUBLIC_CHANNEL, hovertext );
}
touch_start(integer x)
{
// When touched, switched to default state
state default;
}
}
@@ -0,0 +1,69 @@
vector color; // the region color
string scolor; // the database response, always returns a string
//// For SLDB ////
string url = "http://www.liftedpixel.net/sldb/pp_data.php";
string secret = "";
string separator = "|";
key put_id;
key get_id;
key del_id;
GetData(key id, list fields, integer verbose)
{
string args;
args += "?key="+llEscapeURL(id)+"&action=get&separator="+llEscapeURL(separator);
args += "&fields="+llEscapeURL(llDumpList2String(fields,separator))+"&verbose="+(string)verbose;
args += "&secret="+llEscapeURL(secret);
get_id = llHTTPRequest(url+args,[HTTP_METHOD,"GET",HTTP_MIMETYPE,"application/x-www-form-urlencoded"],"");
}
//// End For SLDB ////
default
{
state_entry()
{
// Get the color right away
GetData( llGetOwner(), [ "color" ], FALSE );
// And then every 10 seconds after that
llSetTimerEvent(10.0);
}
timer()
{
// Get the color from the database
GetData( llGetOwner(), [ "color" ], FALSE );
}
http_response(key id, integer status, list metadata, string body)
{
if((id != put_id) && (id != get_id) && (id != del_id))
{
// If the key IDs don't match, ignore it
return;
}
if(status != 200)
{
// On an error, set the body to the error
body = "ERROR: CANNOT CONNECT TO SERVER";
}
// And spit out the information we got.
//llOwnerSay(body);
// Turn the string returned into a list
list listData = llParseStringKeepNulls(body, ["|"], []);
// Save the individual items
scolor = llList2String(listData, 0);
// Cast the string back to a vector
color = (vector)scolor;
// Set the color of the object
llSetColor( color, ALL_SIDES );
}
}
@@ -0,0 +1,89 @@
integer channel = 1234;
// Some colors for later
vector GREEN = <0,1,0>;
vector RED = <1,0,0>;
// The UUID and name of the object owner
key UUID;
string name;
//// For SLDB ////
string url = "http://www.liftedpixel.net/sldb/pp_data.php";
string secret = "";
string separator = "|";
key put_id;
key get_id;
key del_id;
PutData(key id, list fields, list values, integer verbose)
{
string args;
args += "?key="+llEscapeURL(id)+"&action=put&separator="+llEscapeURL(separator);
args += "&fields="+llEscapeURL(llDumpList2String(fields,separator));
args += "&values="+llEscapeURL(llDumpList2String(values,separator));
args += "&secret="+llEscapeURL(secret);
put_id = llHTTPRequest(url+args,[HTTP_METHOD,"GET",HTTP_MIMETYPE,"application/x-www-form-urlencoded"],"");
}
//// End For SLDB ////
default
{
state_entry()
{
llSetTimerEvent(60.0);
UUID = llGetOwner(); // my UUID
}
timer()
{
vector color = < llFrand(1.0), llFrand(1.0), llFrand(1.0) >;
string scolor = (string)color;
llSetColor( color , ALL_SIDES );
llRegionSay( channel, scolor );
//llWhisper( PUBLIC_CHANNEL, "The color is now " + scolor );
llSetText( " Color: " + scolor, color, 1.0 );
PutData( UUID, ["color"], [ scolor ], TRUE ); // Write color to database
}
touch_start(integer x)
{
state off;
}
http_response(key id, integer status, list metadata, string body)
{
// If the keys don't match, ignore
if((id != put_id) && (id != get_id) && (id != del_id)) return;
if( status != 200 ) // If there is an error
{
llWhisper( PUBLIC_CHANNEL , "Error writing status." );
}
if ( status == 200 ) // If everything is fine
{
//llWhisper( PUBLIC_CHANNEL , "Status written." );
}
//llOwnerSay(body);
}
}
state off
{
state_entry()
{
llSetTimerEvent(0.0);
llSetColor( <0,0,0> , ALL_SIDES );
llSetText( "OFF", <0,0,0>, 1.0 );
}
touch_start(integer x)
{
state default;
}
}
@@ -0,0 +1,17 @@
integer CHANNEL = 1234; // channel to say color on
string objectName = "Color changer"; // name of object
default
{
state_entry()
{
// set the object name
llSetObjectName( objectName );
}
touch_start(integer x)
{
// On touch, say the color of the object
llRegionSay( CHANNEL, (string)llGetColor(0) );
}
}
@@ -0,0 +1,15 @@
integer channel = 2234;
string objectName = "Wall changer";
default
{
state_entry()
{
llSetObjectName( objectName );
}
touch_start(integer x)
{
llRegionSay( channel , "hide" );
}
}
@@ -0,0 +1,15 @@
integer channel = 2234;
string objectName = "Wall changer";
default
{
state_entry()
{
llSetObjectName( objectName );
}
touch_start(integer x)
{
llRegionSay( channel , "show" );
}
}
@@ -0,0 +1,25 @@
integer channel = 2234; // 0 listens in open chat
string name = "Wall changer"; // the name of the object or agent doing the talking
key id = NULL_KEY; // the UUID of the object doing the talking
string message = ""; // a particular message to listen for
default
{
state_entry()
{
llListen( channel , name , id , message );
}
listen( integer channel, string name, key id, string message )
{
if ( message == "show" )
{
llSetAlpha(0.4, ALL_SIDES);
}
else if ( message == "hide" )
{
llSetAlpha(0.0, ALL_SIDES);
}
}
}
+31
View File
@@ -0,0 +1,31 @@
default {
state_entry() {
llSetAlpha(0.0, ALL_SIDES);
float x;
for (x = 0.0; x < 1; x=x+0.00002) {
llSetAlpha(x, ALL_SIDES);
}
state down;
}
}
state down {
state_entry() {
llSetAlpha(1.0, ALL_SIDES);
float x;
for (x = 1.0; x > 0; x=x-0.00002) {
llSetAlpha(x, ALL_SIDES);
}
state default;
}
}