Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

help with a door script

Gareth Qunhua
Registered User
Join date: 11 Apr 2007
Posts: 25
07-26-2007 03:41
ok as the title says i need help with a door script that i have, the problem with it is that although it works fine on its own but once i used it on a house that i building it will starts to react funny, like when i rotate the house 90 degress the dor will start to start to open in a random manner and it won't even return to it's normal place.

heres the script:

[spoiler]
// improved door script by Ezhar Fairlight
// features: automatic closing, workaround for rotating out of position,
// doesn't mess up when moved, adjustable direction (inwards/outwards)
// updated for SL 1.1 damped rotations, small bugfix

// ********** USER SETTINGS HERE **********
float TIMER_CLOSE = 5.0; // automatically close the door after this many seconds,
// set to 0 to disable

integer DIRECTION = -1; // direction door opens in. Either 1 (outwards) or -1 (inwards);
// ********** END OF USER SETTINGS **********



integer DOOR_OPEN = 1;
integer DOOR_CLOSE = 2;

vector mypos; // door position (objects move a tiny amount
// away from their position each time they are rotated,
// thus we need to workaround this by resetting
// the position after rotating)

door(integer what) {
rotation rot;
rotation delta;

llSetTimerEvent(0); // kill any running timers

if ( what == DOOR_OPEN ) {
llTriggerSound("Door open", 0.8);

rot = llGetRot();
delta = llEuler2Rot(<0, -0.2, 0>;);
rot = delta * rot; // rotate by -45 degree
llSetRot(rot);

} else if ( what == DOOR_CLOSE) {
rot = llGetRot();
delta = llEuler2Rot(<0, 0.2, 0>;); // rotate by 45 degree
rot = delta * rot;
llSetRot(rot);

llTriggerSound("Door close", 0.8);
}
}


default { // is closed
on_rez(integer start_param) { // reset, so we store the new position
llResetScript();
}

state_entry() {
mypos = llGetPos(); // remember where we're supposed to be
}

touch_start(integer total_number) {
door(DOOR_OPEN);

state is_open;
}

moving_end() { // done moving me around, store new position
mypos = llGetPos();
}
}

state is_open {
state_entry() {
llSetTimerEvent(TIMER_CLOSE);
}

touch_start(integer num) {
door(DOOR_CLOSE);

llSetPos(mypos); // workaround for tiny movements during rotation

state default;
}

timer() { // it's time to close the door
door(DOOR_CLOSE);

llSetPos(mypos); // workaround for tiny movements during rotation

state default;
}

moving_start() { // close door when door is being moved
door(DOOR_CLOSE);

state default;
}
}
[/spoiler]

HELP!! >.<
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
07-26-2007 04:44
Not sure about this - but you might have to reset the door script once you turned the house, since the door stores it's position and rotation when it's rezzed. So when you turn the house, this position is still active and you get this weird behaviour...

Just a thought though - I might also be completely wrong... :)
Gareth Qunhua
Registered User
Join date: 11 Apr 2007
Posts: 25
07-26-2007 05:38
tried it doesn't seems to work >.<
Dytska Vieria
+/- .00004™
Join date: 13 Dec 2006
Posts: 768
07-26-2007 08:41
Try using llGetLocalRot() and llSetLocalRot() instead in your open/close sections.
_____________________
+/- 0.00004