Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Very simple swing door script.

ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
09-05-2006 20:55
This is a very simple swing door script that I have been playing with. The door can be stand alone and prims can be linked to it. Also, this script does not require the door to be cut.

Do with it what you want. You are free to use this script anyway you want, though I will be very unhappy if I see it being sold by itself.

The swing parameters are in the door description. It can be a root prim so you should be able to link other prims to it, eg, doorknob and knockers etc (but not the rest of the house, or you will see that move too). Don't edit the door position while it is in the open position (In the description field should be 'H0').

The description controls the way the door moves. For example:
CODE
H0Q9;<0, -1.1, 0.0>;<0, 0, 9>

H0 establishes that this door is at the home position, Q9 indicates we want 10 steps, moving the door a total of 90 degrees. Make sure that it is H0 when you position the door. The script allows for the initial door position to have any rotation.

The first vector is the position of the fulcrum wrt the centre of the door and will be multiplied by the rotation of the door. The second is the rotation angle (euler and in degrees) for each positional move. Negative angles will move anticlockwise.

There is a hook for a bell, but I have not yet incorporated any bell or announcement yet. There is also no lock and no listen api.

I have not yet tried this as a prim linked to another root prim. I may need to substitute setLocalRot for setRot etc on condition of the link number (>1 would be linked to another root prim).

Ed
CODE

//description parameters
// B - want bell
// H0 - home position
// Q9 - number of steps - 1 (eg, 9 (max) produces 10 steps)

integer debug = FALSE;

integer gSetUp = FALSE;
//vector turnPos;

vector gEulDegStep;
string gsEulDegStep; // keep ascii source for brevity
rotation gRotStep;
vector gRelFulcrum;
string gsRelFulcrum; // keep ascii source for brevity

integer gH = 0; // step counter
integer gQ = 0; // step quantitu target

string gSettings; // the first part of the description
integer gSettingsPtr;

list gDescWords; // list from description

vector gHomePos;
rotation gHomeRot;

vector gActFulcrum;
vector gLever;

integer gEnableBell = FALSE;
integer itisSet = FALSE;




string getSettingsChar () {
string c = ";";
if (gSettingsPtr < llStringLength (gSettings))
c = llGetSubString (gSettings, gSettingsPtr, gSettingsPtr);
++gSettingsPtr;
return c;
}



integer getDigitNo () {
string nums = "0123456789";
string c = getSettingsChar ();
integer pos = llSubStringIndex (nums, c);
return pos;
}





getH () {
gH = getDigitNo ();
if (gH == 0) {
gHomeRot = llGetRot ();
gHomePos = llGetPos ();
--gH;
}

}



integer getSettings () {
string z = "getParams ";
itisSet = 0; // FALSE
if (debug)
llOwnerSay (z + "gSettingsPtr=" + (string) gSettingsPtr);
string c = getSettingsChar ();
if (debug)
llOwnerSay ("c=" + c);
if (c == "B") {gEnableBell = TRUE; return FALSE;}
if (c == "H") {getH (); gSetUp = TRUE; return FALSE;}
if (c == "Q") {gQ = getDigitNo (); gSetUp = TRUE; return FALSE;}
if (c == ";") {return TRUE;}
llOwnerSay (z + " error want B, H or Q, got " + c);
return (TRUE);
}



integer isSetup () {
integer ok;
ok = TRUE;
return gSetUp;
}







getParams()
{
//if (llGetLinkNumber () == 1)
// llOwnerSay ("This prim is not allowed to be the root prim");
// gSetUp = FALSE;


gDescWords = llParseString2List(llGetObjectDesc(), [";"], []);
integer len = llGetListLength(gDescWords);
if (len > 2) {
gSettings = llList2String(gDescWords, 0);
if (debug)
llOwnerSay ("gSettings=" + gSettings);
gSettingsPtr = 0;
integer fin = FALSE;
while (!fin && (gSettingsPtr < llStringLength (gSettings)))
fin = getSettings ();
if (debug)
llOwnerSay ("gH=" + (string) gH);
if (gH < 0) {
gsRelFulcrum = llList2String (gDescWords, 1);
gRelFulcrum = ((vector) gsRelFulcrum) * llGetRot ();
gsEulDegStep = llList2String (gDescWords, 2);
gEulDegStep = (vector) gsEulDegStep;
gRotStep = llEuler2Rot(gEulDegStep * DEG_TO_RAD); //convert to quaternion
gLever = (-gRelFulcrum);
gActFulcrum = gHomePos + gRelFulcrum;
if (debug)
llOwnerSay ("actFulcrum = " + (string) gActFulcrum);
}
}
if (debug)
llOwnerSay ("gSetUp=" + (string) gSetUp);
}




setParams() {
string settings = "";
if (gEnableBell)
settings += "B";
settings += "H" + (string) gH;
settings += "Q" + (string) gQ;
string parm = settings + ";" + gsRelFulcrum + ";" +
gsEulDegStep + ";" +
(string) gHomePos + ";" +
(string) gHomeRot;
llSetObjectDesc (parm);
if (debug)
llOwnerSay ("setDoorParams: " + parm);
}








close1 () {
string z = "close1 ";
if (debug)
llOwnerSay (z + "gHomePos=" + (string) gHomePos + " gHomeRot=" + (string) gHomeRot);
if (gHomePos.z > 0.1)
llSetPrimitiveParams( [ PRIM_POSITION, gHomePos, PRIM_ROTATION, gHomeRot] );
gH = 0;

}

close () {
getParams ();
gHomePos = (vector) llList2String(gDescWords, 3);
gHomeRot = (rotation) llList2String(gDescWords, 4);
close1 ();
setParams ();
}




open1 () {
string z = "open1 ";
rotation r = llGetRot();
vector p0 = llGetPos ();
gLever *= gRotStep;
if (debug) {
llOwnerSay (z + "gLever = " + (string) gLever);
llOwnerSay (z + "gLever llVecMag = " + (string) llVecMag (gLever));
}
p0 = gActFulcrum + gLever;
llSetPrimitiveParams( [ PRIM_POSITION, p0, PRIM_ROTATION, r * gRotStep] );

if (debug) {
llOwnerSay (z + "new rot = " + (string) llGetRot ());
llOwnerSay (z + "new pos = " + (string) p0);
}
gH++;
if (debug)
llOwnerSay (z + "exit gH=" + (string) gH);
}


open () {
getParams ();
while (gH < gQ)
open1 ();
setParams ();

}



default
{
state_entry()
{
getParams ();
//gScale = llGetScale ();
//llOwnerSay ("gScale=" + (string) gScale);
if (debug) {
llOwnerSay ("relFulcrum=" + (string) gRelFulcrum);
llOwnerSay ("gEulDegStep=" + (string) gEulDegStep);
}

//llOwnerSay ("llVecMag" + (string) llVecMag(relFulcrum));
//relFulcrum /= rot315;
if (debug)
llOwnerSay ("relFulcrum llVecMag = " + (string) llVecMag(gRelFulcrum));
}


touch_start(integer total_number)
{
if (debug)
llOwnerSay("Touched.");
if (gH > 0) {
if (gQ > 0)
close ();
else
open ();

} else
if (gQ > 0)
open ();
else {
getParams ();
open ();
}
}
}

Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
09-10-2006 13:30
/54/33/136535/1.html
_____________________
i've got nothing. ;)