// materialize/dematerialize door movement script // JohnG Linden // NOTE: these definitions should be the same as those from the lock // object or the door will not actually work integer direction; integer b; integer getLinkWithName(string name) { integer i = llGetLinkNumber() != 0; // Start at zero (single prim) or 1 (two or more prims) integer x = llGetNumberOfPrims() + i; // [0, 1) or [1, llGetNumberOfPrims()] for (; i < x; ++i) if (llGetLinkName(i) == name) return i; // Found it! Exit loop early with result return -1; // No prim with that name, return -1. } integer gLockChannel = 9394832; string gOpenMsg = "MSG_OPEN"; string gCloseMsg = "MSG_CLOSE"; string Lasername = "BridgeDoorLasers"; string DontTouch = "Dematerializing Door V1.1"; //Well ok you can touch it but it involves editing linked prims. vector color_on = <1.0,0.0,0.0>; //change this to the color that you whant the light to be float intensity_on = 0.25; //change this for the intenstity max 1.0 - min 0.0 float radius_on = 5.0; //change this for the radius max 20.0 = min 0.0 float falloff_on = 0.75; //change this for the fulloff max 2.00 - min 0.0 // where we are when closed vector startingSize; vector move; vector scale; vector gClosedPos; rotation gClosedRot; // internal timer for opening float gOpenTimer; // how long it takes to open/close float gOpenTime = 1.3; // how many steps along the way float gOpenTimeStep = 0.2; // how transparent when open float gOpenAlpha = 0.00; float gClosedAlpha = 1.0; // sound we loop when opening/closing string gOpenSound = "open"; string gCloseSound = "close"; float gSoundVolume = 0.6; // // helper functions // func_debug(string str) { // llSay(0, str); } debug(string str) { // llSay(0, str); } say(string str) { llSay(0, str); } slide_prim() { if (direction == 1){scale=<0.01,0.01,0.01>; b = 1;} else {scale = startingSize; b = 2;} //float i; //for (i=0;i<1;i=i+speed) { llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_POSITION, llGetLocalPos() + move*direction*llGetLocalRot(),PRIM_SIZE,scale,PRIM_PHYSICS_SHAPE_TYPE,b ]); } direction *= -1; } // // states begin here // default { on_rez(integer arg) { llResetScript(); } state_entry() { direction = 1; scale = <0.01,0.01,0.01>; startingSize = llList2Vector(llGetLinkPrimitiveParams(LINK_THIS,[PRIM_SIZE]),0); func_debug("default state_entry"); move = startingSize; // no physics llSetStatus(STATUS_PHYSICS, FALSE); // open/close timer gOpenTimer = 0.0; // listen for open/close messages llListen(gLockChannel, "", "", ""); // and go to closed state state door_closed; llSetLinkPrimitiveParamsFast(getLinkWithName(Lasername), [PRIM_PHYSICS_SHAPE_TYPE,2]);//False? } } state door_closed { on_rez(integer arg) { llResetScript(); } state_entry() { func_debug("door_closed state_entry"); // make us impermeable llListen(gLockChannel, "", "", ""); //llSetLinkPrimitiveParamsFast(getLinkWithName(Lasername), [PRIM_PHYSICS_SHAPE_TYPE,2]);//False? llSetLinkPrimitiveParamsFast(getLinkWithName(DontTouch), [PRIM_PHYSICS_SHAPE_TYPE,2]);//False? } listen(integer channel, string name, key id, string msg) { if ( msg == gOpenMsg ) { state door_opening; } } } state door_opening { on_rez(integer arg) { llResetScript(); } state_entry() { func_debug("door_opening state_entry"); // start opening sound llLoopSound(gOpenSound, gSoundVolume); // start opening process llResetTime(); gOpenTimer = 0.0; llListen(gLockChannel, "", "", ""); llSetTimerEvent(gOpenTimeStep); } timer() { float time = llGetTime(); // interpolate transparency from closed to open float alpha = (1 - (time / gOpenTime)) * (gClosedAlpha - gOpenAlpha) + gOpenAlpha; llSetAlpha(alpha, ALL_SIDES); llSetLinkPrimitiveParamsFast (LINK_THIS,[ PRIM_POINT_LIGHT, TRUE, color_on, alpha, radius_on, falloff_on ]); if ( time > gOpenTime ) { // stop timer interrupts llSetTimerEvent(0.0); // door is now open state door_open; } } state_exit() { llStopSound(); } } state door_open { on_rez(integer arg) { llResetScript(); } state_entry() { func_debug("door_open state_entry"); // make us permeable llListen(gLockChannel, "", "", ""); slide_prim(); //llSetLinkPrimitiveParamsFast(getLinkWithName(Lasername), [PRIM_PHYSICS_SHAPE_TYPE,1]);//True? llSetLinkPrimitiveParamsFast(getLinkWithName(DontTouch), [PRIM_PHYSICS_SHAPE_TYPE,1]);//True? } listen(integer channel, string name, key id, string msg) { if ( msg == gCloseMsg ) { state door_closing; } } } state door_closing { on_rez(integer arg) { llResetScript(); } state_entry() { func_debug("door_closing state_entry"); // audio slide_prim(); llLoopSound(gCloseSound, gSoundVolume); // start opening process llResetTime(); gOpenTimer = 0.0; llListen(gLockChannel, "", "", ""); llSetTimerEvent(gOpenTimeStep); } timer() { float time = llGetTime(); // interpolate transparency from closed to open float alpha = (time / gOpenTime) * (gClosedAlpha - gOpenAlpha) + gOpenAlpha; llSetAlpha(alpha, ALL_SIDES); llSetLinkPrimitiveParamsFast (LINK_THIS,[ PRIM_POINT_LIGHT, TRUE, color_on, alpha, radius_on, falloff_on ]); if ( time > gOpenTime ) { // stop timer interrupts llSetTimerEvent(0.0); // door is now closed state door_closed; } } state_exit() { // kill closing sound llStopSound(); } }