Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Elevate yourself OS

Sleepy Xue
I script Pretty HUDs
Join date: 22 Jun 2008
Posts: 57
08-24-2008 21:23
!Open Source!
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
Urrong Urnst
Registered User
Join date: 12 Jul 2008
Posts: 49
08-24-2008 23:16
Heya Sleepy. Nice to see u on forums. If u wanna put this script in to library u should mark the topic Library: OS Elevator or something so the moderrator will move it into library where most of ppl look for scripts that r free. Im gonna check it out :D
Urrong Urnst
Registered User
Join date: 12 Jul 2008
Posts: 49
08-24-2008 23:24
oh and one more thing. A lot of scripters in sl uses dialog timeout. So u should only make that llListen filter listen to the agent that touched the elevator. Cuz now that u posted script everyone knows what channel does it use to communicate and someone could easily make a grief script that would send elevator up and down in time interval. It is just for safety cause. Otherwise very well scripted.
Sleepy Xue
I script Pretty HUDs
Join date: 22 Jun 2008
Posts: 57
08-25-2008 18:47
Thanks! I may also add some safe guards for keeping the same rotation. If anyone wants the newer script just send me an IM.
-Ok I kinda fixed that.
A griefer can always mess with it though. It's best that the owner change the channel from the default one.
Nexii Malthus
[Cubitar]Mothership
Join date: 24 Apr 2006
Posts: 400
08-25-2008 22:48
lols, put it on the wiki/lsl portal rather.
_____________________

Geometric Library, for all your 3D maths needs.
https://wiki.secondlife.com/wiki/Geometric

Creator of the Vertical Life Client
Sleepy Xue
I script Pretty HUDs
Join date: 22 Jun 2008
Posts: 57
08-26-2008 17:14
Under llMoveToTarget?
Eristic Strangelove
Registered User
Join date: 16 Nov 2005
Posts: 39
04-25-2009 13:31
Great script, I've been playing around with the free elevator version from xstreet...

...but is it possible to make it work with more accurate distances between floors? At the moment it rounds to the nearest integer and that makes it difficult to implement in some builds.

Can it be made to work with floats instead of integers?
Sleepy Xue
I script Pretty HUDs
Join date: 22 Jun 2008
Posts: 57
05-14-2009 16:57
Yeah. That was a mistake. simply change the llList2Integer to llList2Float....That will fix the problem =p
_____________________
I script pretty HUDs.