// 2006.11.29 Remote-control Texture // version 0.68 2006.12.10 // set with "channels" in setup card list COMMAND_CHANNELS = [99,103]; // listen on any number of channels, for shared control groupings // set with "side" in setup card integer TSIDE = ALL_SIDES; // which texture face to alter. string SETUP = "setup"; // name of notecard to config with key BLANK = "5748decc-f629-461c-9a36-a35a221fe21f"; key MESH = "cb81a363-1513-5eb3-8b45-249c69386fb5"; integer gDebug = 0; integer gCurrentSetupLine; d(list debugList) { if(gDebug) { string s = (string)debugList; llOwnerSay("(dbg) "+s); } } init() { // if there's a config card, commence reading it if(llGetInventoryType(SETUP) == INVENTORY_NOTECARD) { llSetText("[reading " + SETUP + "]",<1,0,0>,1); gCurrentSetupLine = 0; llGetNotecardLine(SETUP,gCurrentSetupLine++); } else doneWithSetup(); } // This method gets called for each line // of the "setup" notecard. The commands // shown below are the allowable // setup lines. gotSetupLine(string message) { if(message == EOF) { doneWithSetup(); return; } // start fetching the next line llGetNotecardLine(SETUP,gCurrentSetupLine++); // and do something with this one list messageL = llParseString2List(message,[" "],[]); string cmd = llList2String(messageL,0); if(cmd == "channels") COMMAND_CHANNELS = llList2List(messageL,1,-1); else if(cmd == "side") TSIDE = llList2Integer(messageL,1); } doneWithSetup() { integer k = llGetListLength(COMMAND_CHANNELS); while(k-- >= 0) llListen(llList2Integer(COMMAND_CHANNELS,k),"","",""); d(["free: ",llGetFreeMemory()]); showText(1); if(!gDebug) { llSleep(5); showText(0); } } list COLORNAME2COLOR = [ "", // so we can use "0" to mean not a color, 1,3,5,7... are color indices. "red",<1,0,0>, "pink",<1,0.7,0.7>, "orange",<1,.5,0>, "yellow",<1,1,0>, "green",<0,1,0>, "blue",<0,0,1>, "purple",<0.8,0,1>, "white",<1,1,1>, "grey",<.4,.4,.4>, "sodium",<1,0.8,0>, "fluorescent",<0.75,0.75,1>, "incandescent",<1,1,0.75>, "black",<0,0,0>, "uv",<0.5,0,1.0> ]; // return a color index (odd integer) or 0 of its not a known color name. integer name2ColorIndex(string colorName) { integer index = llListFindList(COLORNAME2COLOR,[llToLower(colorName)]); if((index & 1) == 0) // color name indices are all odd index = 0; else if(index < 0) index = 0; else index++; // bump forward to the color vector index. return index; } // Handles the commonest colors, or vector name2Color(string colorName) { vector color; integer colorIndex = name2ColorIndex(colorName); if(colorIndex) color = llList2Vector(COLORNAME2COLOR,colorIndex); else color = (vector)colorName; return color; } integer gFullBright; vector gColor; integer gLightOn; float gIntensity = 1.0; float gRadius = 20.0; float gFalloff = 0.5; setColorAndLight(vector color,integer lightOn) { gColor = color; gLightOn = lightOn; llSetColor(gColor,TSIDE); llSetPrimitiveParams([PRIM_POINT_LIGHT,gLightOn,gColor,gIntensity,gRadius,gFalloff,PRIM_FULLBRIGHT,TSIDE,gLightOn | gFullBright]); } showText(float show) { if(show) llSetText((string)["channels: [",llDumpList2String(COMMAND_CHANNELS,", "),"]\nfree: ",llGetFreeMemory()],,1); else llSetText("",<0,0,0>,0); } // texture command is: // scale x y // rotate angle // spin rate // spinpong rate revolutions // slide rate // color // texture key or name doCommand(string message) { d([message]); if(message == "") { // doDialog(av); return; } list messageL = llParseString2List(message,[" "],[]); string cmd = llToLower(llList2String(messageL,0)); integer arg1 = llList2Integer(messageL,1); float arg1F = llList2Float(messageL,1); string arg1S = llList2String(messageL,1); integer arg1OnOff = 0; if(llToLower(arg1S) == "on" || ((integer)arg1S > 0) || arg1S == "" ) arg1OnOff = 1; if(cmd == "debug") { gDebug = arg1; showText(gDebug); // show or hide debug text d(["debug is ",gDebug]); } else if(cmd == "texture") { if(arg1S == "" || arg1S == "blank") arg1S = (string)BLANK; else if(arg1S == "mesh") arg1S = (string)MESH; llSetTexture(arg1S,TSIDE); } else if(cmd == "color") { vector color = name2Color(arg1S); setColorAndLight(color,gLightOn); } else if(cmd == "light") { setColorAndLight(gColor,arg1OnOff); } else if(cmd == "alpha") { llSetAlpha(arg1F,TSIDE); } else if(cmd == "reset") { // do a handful of things... setColorAndLight(<.5,.5,.5>,0); llSetTextureAnim(0,TSIDE,1,1,0,1,0); llSetTexture(BLANK,TSIDE); } else if(cmd == "spin") { llSetTextureAnim(ANIM_ON + LOOP + SMOOTH + ROTATE,TSIDE,1,1,0,2*PI,arg1F); } else if(cmd == "stop") { llSetTextureAnim(0,TSIDE,1,1,0,1,0); llOffsetTexture(0,0,TSIDE); } else if(cmd == "offset") { float x = arg1F; float y = llList2Float(messageL,2); llOffsetTexture(x,y,TSIDE); } else if(cmd == "animate") { integer x = arg1; integer y = llList2Integer(messageL,2); float rate = llList2Float(messageL,3); llSetTextureAnim(ANIM_ON + LOOP, TSIDE,x,y,0,x*y,rate); } else if(cmd == "spinpong") { float revolutions = llList2Float(messageL,2) * 2 * PI; llSetTextureAnim(PING_PONG + ANIM_ON + LOOP + SMOOTH + ROTATE,TSIDE,1,1,0,revolutions,arg1F); } else if(cmd == "slide") { llSetTextureAnim(ANIM_ON + LOOP + SMOOTH,TSIDE,1,1,0,1,arg1F); } else if(cmd == "scale") { float x = arg1F; float y = llList2Float(messageL,2); llScaleTexture(x,y,TSIDE); } else if(cmd == "rotate") { float r = arg1F / 57.29577951; llRotateTexture(r,TSIDE); } else if(cmd == "fullbright") { gFullBright = arg1OnOff; llSetPrimitiveParams([PRIM_FULLBRIGHT,TSIDE,arg1OnOff]); } else if(cmd == "shinybump") { integer bump = llList2Integer(messageL,2); llSetPrimitiveParams([PRIM_BUMP_SHINY,TSIDE,arg1,bump]); } // ... } default { on_rez(integer n) { init(); } dataserver(key queryKey,string message) { gotSetupLine(message); } changed(integer k) { if(k == CHANGED_INVENTORY) llResetScript(); } state_entry() { init(); } touch_start(integer total_number) { if(llDetectedKey(0) == llGetOwner() && !gDebug) { float z; for(z = 1.0; z >= 0; z -= .1) { showText(z); llSleep(.1); } showText(0.0); } } listen(integer channel,string name,key id,string message) { doCommand(message); } timer() { } link_message(integer senderNum,integer keyNum,string message,key id) { } } // end of file