Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PhantomDoor
- // Ryonen Moon 21 Nov 2011
- //
- // A door script that becomes phantom and fades to transparent when opened,
- // and then automatically closes again after an interval.
- //
- // License: You may use this script as you please in any of your endeavors or projects, including commercial use.
- // I only ask that you don't claim this script is yours, or charge anyone else for it.
- //
- // Door State enumerator
- integer doorCLOSED = 0;
- integer doorOPENING = 1;
- integer doorOPEN = 2;
- integer doorCLOSING = 3;
- integer NUM_TRANSPARENCY_STEPS = 15;
- float STEP_DELAY; // = 1.5 / (float)NUM_TRANSPARENCY_STEPS;
- float FADE_BASE = 0.9;
- integer gDoorTransparencyStep; // For progressively changing the door to be transparent
- integer gDoorState; // Current state of door (See door state enumerator)
- openDoor()
- {
- gDoorState = doorOPENING;
- llSetLinkPrimitiveParamsFast(0, [PRIM_PHANTOM, TRUE]);
- gDoorTransparencyStep = NUM_TRANSPARENCY_STEPS;
- llSetTimerEvent(STEP_DELAY);
- }
- closeDoor()
- {
- gDoorState = doorCLOSING;
- gDoorTransparencyStep = 0;
- llSetTimerEvent(STEP_DELAY);
- llSetLinkPrimitiveParamsFast(0, [PRIM_PHANTOM, FALSE]);
- }
- default
- {
- state_entry()
- {
- STEP_DELAY = 1.5 / (float)NUM_TRANSPARENCY_STEPS;
- }
- touch_start(integer total_number)
- {
- if (gDoorState == doorOPEN)
- closeDoor();
- else if (gDoorState == doorCLOSED)
- openDoor();
- // Ignore clicks if in transition between open and closed - events will transpire on their own
- }
- timer()
- {
- if (gDoorState == doorOPENING) {
- gDoorTransparencyStep -= 1;
- llSetAlpha(1.0 - llPow(FADE_BASE, gDoorTransparencyStep), ALL_SIDES);
- if (gDoorTransparencyStep < 1) {
- gDoorState = doorOPEN;
- llSetTimerEvent(10.0); // Set delay before door will automatically close
- }
- } else if (gDoorState == doorOPEN) {
- closeDoor();
- } else if (gDoorState == doorCLOSING) {
- gDoorTransparencyStep += 1;
- llSetAlpha(1.0 - llPow(FADE_BASE, gDoorTransparencyStep), ALL_SIDES);
- if (gDoorTransparencyStep >= NUM_TRANSPARENCY_STEPS) {
- gDoorState = doorCLOSED;
- llSetTimerEvent(0.0);
- llSetAlpha(1.0, ALL_SIDES);
- }
- } else { // Shouldn't happen, but...
- gDoorState = doorCLOSED;
- llSetTimerEvent(0.0);
- llSetAlpha(1.0, ALL_SIDES);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement