A couple of friends of mine were making an AWESOME elevator, and they needed a script, so I made them one. I have decided to OPEN SOURCE IT! That's right =p They had bought a few from SLX and none fit their needs exactly, so I made one for them. I checked, and they don't mind me OS'ing it. Here you guys go! Please comment!
P.S. -For those who just take it and don't read it-
-The object desc matters!!!!
-There are a couple of lines which might not make sense unless because the script has been made to go with a couple of door scripts which I wont post, but you can grab them from inside the elevator, which is free, on my slx
CODE
//Scripted by Sleepy Xue
//This script is Open Source, so please don't sell it
//Enjoy!
string SOUND = ""; //If you have a sound please put its name in the quotation marks.
//If there is no sound leave the quotation marks empty: ""
float SPEED = 2.0; //This is the elevator speed
integer LISTEN_CHANNEL = -2453564345;
integer CHANNEL = -12324332;
integer SHAFT_CHANNEL = -254346534;
float MASS;
float GRAVITY = 9.8;
integer gTemp;
integer gFloor = 0;
integer gCurrent = 1;
integer gFloorAmount = 0;
integer targetID;
vector gPos;
key gPerson;
move(float floor)
{
if(floor > gCurrent)
{
llMessageLinked(LINK_SET,0,"Door","Close");
llSay(SHAFT_CHANNEL,"Close");
floor -= gCurrent;
gCurrent += (integer)floor;
floor = gFloor * floor;
play();
llSetStatus(STATUS_PHYSICS,TRUE);
llSetForce(<0.0,0.0,GRAVITY+3> * MASS, FALSE);
llTargetRemove(targetID);
gPos += <0.0,0.0,floor>;
targetID = llTarget( gPos, 0.1 );
llMoveToTarget(gPos,SPEED);//2.5
return;
}
else if(floor < gCurrent)
{
llMessageLinked(LINK_SET,0,"Door","Close");
llSay(SHAFT_CHANNEL,"Close");
gTemp = (integer)floor;
floor = llAbs((integer)floor - gCurrent);
gCurrent = gTemp;
floor = gFloor * floor;
play();
llSetStatus(STATUS_PHYSICS,TRUE);
llSetForce(<0.0,0.0,GRAVITY+3> * MASS, FALSE);
llTargetRemove(targetID);
gPos -= <0.0,0.0,floor>;
targetID = llTarget( gPos, 0.1 );
llMoveToTarget(gPos,SPEED);//2.5
return;
}
llSay(SHAFT_CHANNEL,(string)gCurrent);
llMessageLinked(LINK_SET,0,"Door","Open");
}
play()
{
if(SOUND != "")
llPlaySound(SOUND,1.0);
}
vector ground;
default
{
on_rez(integer s) //Delete these four lines if you want. They are no longer needed. (This one)
{//This one
llResetScript(); //This one
}//This one
state_entry()
{
llSetStatus(STATUS_PHYSICS|STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z,FALSE);
llOwnerSay(" Please place your object on the bottom floor.");
llOwnerSay("\n Now change the object description. Put two numbers seperated by a comma.\n The first number is how many meters you have between floors.\n The second number is how many floors your have.\n Example: 9.5,2 \n \n -9.5 meters between each floor, and a total of 2 floors \n THEN RESET THE SCRIPT!");
list temp = llParseString2List(llGetObjectDesc(),[","],[]);
MASS = llGetMass();
gFloor = llList2Integer(temp,0);
gFloorAmount = llList2Integer(temp,1);
gPos = llGetPos();
ground = gPos;
llListen(CHANNEL,"","","");
llListen(LISTEN_CHANNEL,"","","");
if(SOUND != "")
llPreloadSound(SOUND);
}
touch_start(integer num)
{
if(llGetLinkName(llDetectedLinkNumber(0)) == "Door")
{
llMessageLinked(LINK_SET,0,"Door","");
return;
}
else if(llGetLinkName(llDetectedLinkNumber(0)) == "Button")
{
llSay(SHAFT_CHANNEL,(string)gCurrent);
llMessageLinked(LINK_SET,0,"Door","Open");
return;
}
gPerson = llDetectedKey(0);
llDialog(llDetectedKey(0),"Would you like to move up or down?",["Up","Down"],CHANNEL);
}
listen(integer channel, string name, key id, string message)
{
message = llToLower(message);
if(channel == CHANNEL && gPerson == id)
{
if(message == "up")move(gCurrent+1);
else if(message == "down")move(gCurrent -1);
}
else if(channel == LISTEN_CHANNEL && llGetOwnerKey(id) == llGetOwner())
move((integer)message);
}
at_target( integer number, vector targetgPos, vector ourgPos )
{
llSay(0, "We've arrived!");
llSay(SHAFT_CHANNEL,(string)gCurrent);
llTargetRemove(targetID);
llStopMoveToTarget();
llSetStatus(STATUS_PHYSICS, FALSE);
llMessageLinked(LINK_SET,0,"Door","Open");
}
}
I may optimize this code a little bit, so expect some edits!
EDIT: I edited the script for a different friend, and it is designed for her elevator =p
Please pick one up for free from my SLX: http://xstreetsl.com/modules.php?name=Marketplace&file=item&ItemID=1130133

