rotation - put in rootprim (axis)

 

 

Scripts name rotation - put in rootprim (axis)  
Purpose rortates a rootprim (axis), so can be user for doors, drawbridges etc - stores startposition and second touch rotates back to start  
script lanugages used lsl  
important settings for region ./.  
test on osgrid - trunk  6.2 SVN8132, XEngine  
source Ralf Haifisch  

 

// rotate , axis is root prim
// ----------------------------------------
// by Ralf Haifisch@osgrid
// you are allowed to reuse, modify and sell in your products
// as long as the editor and modifier names are keept


string gOpen_message = "";
string gClose_message = "";
string gOpen_sound = "";
string gClose_sound = "";
integer gDoor_open = FALSE;

string replace(string main, string old, string new) // Search and replace
{ // function for strings
string temp = "";
list m = llParseString2List(main,["%"],[]);
integer i;
for(i = 0; i < llGetListLength(m); i ++){
string c = llList2String(m,i);
if (c == old){
temp += new;
}else{
temp += c;
}
}
return temp;
}

integer fOpen(string av_name) // Opens
{
if (gOpen_sound != "")
llTriggerSound(gOpen_sound, 0.5);
if (gOpen_message != "")
llSay(0, replace(gOpen_message,"nn", av_name));
rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,PI/4>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
return TRUE;
}


integer fClose(string av_name) // Close
{
if (gClose_sound != "")
llTriggerSound(gClose_sound, 0.5);
if (gClose_message != "")
llSay(0, replace(gClose_message,"nn",av_name));
rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,-PI/4>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
return FALSE;
}

default
{
on_rez(integer s)
{
llResetScript();
}

state_entry()
{
llSay(0, "script starting....");
// llSetPrimitiveParams([PRIM_PHANTOM, FALSE]);
}

touch_start(integer total_number)
{
if (!gDoor_open){
gDoor_open = fOpen(llDetectedName(0));
} else {
gDoor_open = fClose(llDetectedName(0));
}
}
}