(Huge tip of the hat to my own mentor, Jillian Callahan, without whom my own library would be an abominable mess. She rescued me when I was trying to do this a long time ago.)
All you have to change is the top code. The first line asks you to identify what the prim's rotation will be relative to the parent prim when it's open. If the parent is set to <0,0,0> then you just take a peek at the prim you're rotating to see what the rot is when you've got it set to where you would want it to be in the open position (otherwise, adjust according to the parent). Similarly, the line below asks you what the rotation should be when this prim is in the closed state, again relative to the parent prim's rotation.
The third statement allows you to indicate whether or not this prim should be in the open or closed state when the object it's attached to is first rezzed.
If this is a cupboard with handles, you'll need to pass a linked message in so that they can talk to each other and each will know when the other's been touched so that their open and closed states are in synch.
This is a staple in my own library. Couldn't do without it.
CODE
vector r_open = <0.0, 90.0, 0.0>; // This prim's rotations in degrees relative to root prim when this prim is open
vector r_closed = <0.0, 0.0, 0.0>; // and when it's in the closed state
integer close_on_rez = TRUE; // Change to false to have the prim open on rez
// ======================================================= Nothing from here down needs modding.
rotation LocalRot(rotation localrot)
{
rotation LocRot = localrot / ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot());
return LocRot;
}
open(string door)
{
llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_open * DEG_TO_RAD))]);
}
close(string door)
{
llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_closed * DEG_TO_RAD))]);
}
default
{
state_entry()
{
if (close_on_rez)
{
state closed;
}
else
{
state opened;
}
}
on_rez(integer rez)
{
llResetScript();
}
}
state opened
{
state_entry()
{
open("left");
}
on_rez(integer rez)
{
llResetScript();
}
touch_start(integer n)
{
state closed;
}
}
state closed
{
state_entry()
{
close("left");
}
on_rez(integer rez)
{
llResetScript();
}
touch_start(integer n)
{
state opened;
}
}
Lovely if you're using a nice round lid on a chest. If you're using it as a door and you want it to rotate around the axis, be sure to cut a box prim's path to begin at 0.375 and end at 0.875. This gives the illusion of the door rotating at it's edge, rather than in it's center of gravity.
Remember, this is just an example. You will have to change the vectors to match the rotations you want for the prim you are using relative to it's own parent.
Cheers

Sue.