vector pos;//Base Postion
vector end;//Target Position
key owner;
default
{
state_entry()
{
owner=llGetOwner();
llListen(0,"",owner,"");
llListen(34,"","","first");
llListen(34,"","","second");
llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z,FALSE);
}
listen(integer a, string n, key id, string m)
{
// When the object hears align, it will grab the base position, and after which, all moves will be made by adjusting the z-coordinate of the base position.
if(m=="align")
{
pos=llGetPos();
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(pos,1.5);
}
// For the first floor, we want the elevator to be at its base position, so end(final resting place of the elevator) is the same as pos. I showed the addition of the vector <0,0,0> merely for continuity. The same comments about tau that apply to the llSetHoverHeight, apply to llMoveTarget.
if(m=="first")
{
end=pos;
llMoveToTarget(end,1.5);
}
if(m=="second")
{
end=pos+<0,0,3.29>;
llMoveToTarget(end,1.5);
}
}
}
// END //
vector alignment;
vector targetVector;
integer travelDistance;
integer numListen;
integer targetFloor;
list floorHeights = [26.1,36,46,56,66,76,86,96,106,116,126,136];//
float fixedFloorHeight = 10; //Set to floor heights, or set to -1 to use floorHeights list
float speed = 0.25; //Valid values are 0.01 to 1.0, a Percentage of maxSpeed;
float maxSpeed = 32;
float precision = 0.5;
integer autoSpeed = TRUE;
integer initialDistance;
elevate (vector end)
{
vector current = llGetPos();
travelDistance = llRound(current.z-end.z);
travelDistance = llAbs(travelDistance);
if (autoSpeed)
{
if (travelDistance < (initialDistance / 2))
{
speed -= (precision / 50);
if (speed < 0.25)
speed = 0.25;
}
else
{
speed += (precision / 25);
if (speed > 1)
speed = 1;
}
}
if (travelDistance > 30)
{
travelDistance = 30;
if (end.z > current.z)
{
end.z = current.z + 30;
}
else
{
end.z = current.z - 30;
}
}
float i = travelDistance/(maxSpeed*speed);
llMoveToTarget(end,i);
}
GotoFloor (integer floor, key id)
{
llWhisper(0, "Moving to floor#" + (string)floor);
llSetStatus(STATUS_PHYSICS, TRUE);
llLoopSound("ElevatorNoises", 1);
targetFloor = floor;
if (fixedFloorHeight > 0)
{
targetVector = alignment;
targetVector.z = alignment.z + (fixedFloorHeight * floor);
}
else
{
targetVector = alignment;
targetVector.z = llList2Float(floorHeights, floor);
}
llWhisper(0, "At " + (string)targetVector.z + " meters...");
vector current = llGetPos();
initialDistance = llRound(current.z-targetVector.z);
initialDistance = llAbs(initialDistance);
if (autoSpeed)
{
speed = 0.01;
}
elevate(targetVector);
llSetTimerEvent(precision);
}
reset()
{
llSay(0, "Resetting Elevator...");
llSetStatus(STATUS_ROTATE_X| STATUS_ROTATE_Y| STATUS_ROTATE_Z, FALSE);
alignment = llGetPos();
llSetStatus(STATUS_PHYSICS, FALSE);
llStopSound();
llListenRemove(numListen);
numListen = llListen( 0, "", "", "" );
}
default
{
state_entry()
{
reset();
}
object_rez(key id)
{
llResetScript();
}
listen(integer a, string n, key id, string m)
{
vector pos;
integer Floor;
float tempFloat;
if (llSubStringIndex(m, "goto floor") == 0)
{
Floor = (integer)llGetSubString(m, 10, llStringLength(m));
GotoFloor(Floor, NULL_KEY);
}
if (llSubStringIndex(m, "speed") == 0)
{
tempFloat = (float)llGetSubString(m, 5, llStringLength(m));
if ((tempFloat > 0.001) && (tempFloat <= 1.0))
{
speed = tempFloat;
}
}
if ((m=="elevator reset") && (id==llGetOwner()))
{
reset();
}
}
timer()
{
vector CurrentPos;
float tempfloat;
CurrentPos = llGetPos();
tempfloat = (CurrentPos.z - targetVector.z);
if (llFabs(tempfloat) < 2)
{
if (llFabs(tempfloat) < 0.05)
{
//Arrived at Floor
llWhisper(0, "Arrived at floor #" + (string)targetFloor);
llSetTimerEvent(0);
llSetStatus(STATUS_PHYSICS, FALSE);
llStopSound();
}
else
{
llMoveToTarget(targetVector,1.0);
}
}
else
{
if (fixedFloorHeight > 0)
{
targetVector = alignment;
targetVector.z = alignment.z + (fixedFloorHeight * targetFloor);
}
else
{
targetVector = alignment;
targetVector.z = llList2Float(floorHeights, targetFloor);
}
elevate(targetVector);
}
}
}
0 件のコメント:
コメントを投稿