// default values.
integer chatchannel = 12000; // elevator chat channel.
integer sitball = FALSE; // TRUE = show sit ball, FALSE = don´t show sit ball.
integer sittext = TRUE; // TRUE = show sit text, FALSE = don´t show sit text.
integer unsittime = 5; // time to unsit avatar after arrive at selected floor.
integer voices = 0; // voices lenguaje, 0=english, 1=spanish.
// elevator data.
integer nfloors = 0; // number of floors.
list floorsposition = []; // list with vectors for every floor.
list floorsperms = []; // stores permisions for every floor.
// working data.
integer channelID; // id for the chat channel.
integer targetID; // target identification.
vector newpos; // new position when a floor is selected.
integer actualfloor = 0; // floor where the elevator is.
integer newfloor = 0; // selected floor.
integer elevatorstate = 0; // elevatorstate; = 0, stoped.
// = 1, going up.
// = 2, going down.
integer sitted = FALSE; // TRUE if an avatar is sitted, FALSE otherwise.
key sittedid = NULL_KEY; // Key of sitted avatar.
integer timeouttimer = 10;
integer menulocked = TRUE; // if TRUE, working menu is locked, if FALSE, working menu active.
integer rezbox = FALSE; // for rezzing doors.
integer rezzing = FALSE;
// Variables for notecard reading
integer note_line = 0;
key note_queryID;
// Read data from the configuration notecard if
// present.
// --------------------------------------------
readconfignote()
{
if (llGetInventoryType("elproconfig"

== INVENTORY_NOTECARD)
{
nfloors = 0;
floorsposition = [];
floorsperms = [];
llOwnerSay("Reading configuration notecard."

;
llOwnerSay("------------------------------------------------"

;
note_queryID = llGetNotecardLine("elproconfig", note_line);
}
else llOwnerSay("There is not a configuration notecard."

;
}
// parse lines readed from notecard.
parsenoteline(string line)
{
list items = llParseString2List(line, [":"], []);
if (llList2String(items, 0) == "+"

{
floorsposition = floorsposition + [(vector)llList2String(items, 1)];
floorsperms = floorsperms + llList2String(items, 2);
nfloors++;
}
}
// Parses the configuration data if pressent in object
// description field and returns TRUE.
// If not pressent, returns FALSE.
// ------------------------------------------------------
readconfig()
{
string confstr = llGetObjectDesc();
list items = llParseString2List(confstr, [","], []);
chatchannel = (integer)llList2String(items, 1);
sitball = (integer)llList2String(items, 2);
sittext = (integer)llList2String(items, 5);
if (sitball) llMessageLinked(LINK_ALL_CHILDREN, 0, "SITBALLSHOW", NULL_KEY);
else llMessageLinked(LINK_ALL_CHILDREN, 0, "SITBALLHIDE", NULL_KEY);
if (sittext) llMessageLinked(LINK_ALL_CHILDREN, 0, "SITTEXTSHOW", NULL_KEY);
else llMessageLinked(LINK_ALL_CHILDREN, 0, "SITTEXTHIDE", NULL_KEY);
unsittime = (integer)llList2String(items, 3);
voices = (integer)llList2String(items, 4);
}
// Saves the configuration data in the description field.
// ------------------------------------------------------
saveconfig()
{
string theconfig = "conf," + (string)chatchannel + "," + (string)sitball + "," +
(string)unsittime + "," + (string)voices + "," + (string)sittext;
llSetObjectDesc(theconfig);
}
// Says the config to the owner.
// ------------------------------------------------------
sayconfig()
{
llOwnerSay("MWS Elevator PRO 2.0 CONFIG DATA"

;
llOwnerSay("------------------------------------------------"

;
llOwnerSay("Chatchannel: " + (string)chatchannel);
llOwnerSay("Show sit ball (1 = show, 0 = no): " + (string)sitball);
llOwnerSay("Unsit time: " + (string)unsittime);
llOwnerSay("Voices (0 = none, 1 = english, 2 = spanish): " + (string)voices);
llOwnerSay("------------------------------------------------"

;
llOwnerSay("Number of floors: " + (string)nfloors);
llOwnerSay("------------------------------------------------"

;
}
// Rezzes doors and external boxes from ground floor, to
// top floor
// ---------------------------------------------------------
rezzdoors(integer wfloor)
{
// Take data about pos and rot of elevator.
vector elevatorpos = llGetPos();
rotation elevatorrot = llGetRot();
vector objVdest;
rotation objRdest;
integer rezvalue = (chatchannel * 10) + wfloor;
if (llGetInventoryType("Elevator PRO 2.0 Classic (door)"

== INVENTORY_OBJECT)
{
// Calculate final destination and rotation.
objVdest = ( <1.85477, -0.00000, 1.76199> * elevatorrot) + elevatorpos;
objRdest = (<0.00000, 0.00000, 1.00000, 0.00000> * elevatorrot);
// Rez door in proper position.
llRezAtRoot("Elevator PRO 2.0 Classic (door)",objVdest,ZERO_VECTOR,objRdest,rezvalue);
llSleep (1.0);
} else llOwnerSay("Elevator door not in elevator inventory."

;
if (rezbox) {
if (llGetInventoryType("Elevator PRO 2.0 Classic (external box)"

== INVENTORY_OBJECT)
{
// Calculate final destination and rotation.
objVdest = (<0.00537, -0.00000, 1.76840> * elevatorrot) + elevatorpos;
objRdest = (<0.0, 0.0, 0.70711, 0.70711> * elevatorrot);
// Rez ext box in proper position.
llRezAtRoot("Elevator PRO 2.0 Classic (external box)",objVdest,ZERO_VECTOR,objRdest,0);
llSleep(1.0);
} else llOwnerSay("External box not in elevator inventory."

;
}
llOwnerSay("REZZED at floor: " + (string)wfloor);
// if not finished, send the elevator to the next floor.
if (wfloor < (nfloors - 1))
{
wfloor++;
sendtofloor(wfloor);
}
else
{
rezzing = FALSE;
llOwnerSay("REZZING FINISHED"

;
sendtofloor(0);
}
}
// Sends the elevator to a selected floor if floors has been
// configured.
// ---------------------------------------------------------
sendtofloor(integer floor)
{
if (voices == 1)
llTriggerSound((string)floor + "flooreng", 0.0);
if (voices == 2)
llTriggerSound((string)floor + "flooresp", 0.0);
if (nfloors > 0)
{
newfloor = floor;
// looks for permissions
if (sittedid != llGetOwner())
{
if (sittedid != NULL_KEY)
{
if ((llList2String(floorsperms, newfloor) == "owner"

&& (sittedid != llGetOwner()))
{
llWhisper(0, "SORRY!!!, only the owner can go to that floor. Use the"

;
llWhisper(0, "internal touch panel to select another floor."

;
timeouttimer = unsittime;
return;
}
if ((llList2String(floorsperms, newfloor) == "group"

&& (!llSameGroup(sittedid)))
{
llWhisper(0, "SORRY!!!, only the members of the group can go to that floor."

;
llWhisper(0, " Use the internal touch panel to select another floor."

;
timeouttimer = unsittime;
return;
}
}
}
if ((newfloor != actualfloor) || (rezzing))
{
newpos = llList2Vector(floorsposition, newfloor);
if (!rezzing) llLoopSound("elevator", 1.0);
if (newfloor > actualfloor)
{
elevatorstate = 1; // going up.
llRegionSay(chatchannel, "ELPRO2.0:" + (string)llGetOwner() + ":GOINGUP"

;
llMessageLinked(LINK_ALL_CHILDREN, 0, "GOINGUP", NULL_KEY);
}
else
{
elevatorstate = 2; // going down.
llRegionSay(chatchannel, "ELPRO2.0:" + (string)llGetOwner() + ":GOINGDOWN"

;
llMessageLinked(LINK_ALL_CHILDREN, 0, "GOINGDOWN", NULL_KEY);
}
llWhisper(0, "To Floor " + (string)floor);
targetID = llTarget(newpos, 0.2);
llSetPos(newpos);
}
else llWhisper(0, "You are at floor " + (string)floor);
} else llSay(0, "No configured floors."

;
}
// *****************************************************************************
//