Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //***************************
- // Master Opening Door Script s_doorsA
- //
- // Door is linked and second wing contains slave script (s_doorsB)
- // and its name must be same as this one with a postfix "_B"
- //***************************
- integer LINK_DA=LINK_THIS;
- integer LINK_DB;
- float openingTime=1; // time to open
- float openingAngle=-120.0; // angle to open
- float autocloseTime=0.0; // auto close time (0-door remains open)
- float omega=0.0;
- vector axis;
- rotation closedRot; rotation closedRot2;
- rotation openRot; rotation openRot2;
- integer swinging;
- integer open;
- integer access = 3; // 0-public, 2-group, 3-owner
- //==============================================
- default
- //==============================================
- {
- state_entry()
- {
- integer i;
- string pname=llGetLinkName(LINK_THIS)+"_B";
- for(i=2;i<=llGetNumberOfPrims();i++)
- if(pname==llGetLinkName(i))
- LINK_DB=i;
- else if(llGetLinkName(i)==llGetLinkName(LINK_THIS))
- LINK_DA=i;
- string pdesc = llToLower(llGetObjectDesc());
- if( (i=llSubStringIndex(pdesc,"acc="))>=0)
- access = (integer)llGetSubString(pdesc,i+4,-1);
- if( (i=llSubStringIndex(pdesc,"ang="))>=0)
- openingAngle = (integer)llGetSubString(pdesc,i+4,-1);
- if( (i=llSubStringIndex(pdesc,"t1="))>=0)
- openingTime = (float)llGetSubString(pdesc,i+3,-1);
- if( (i=llSubStringIndex(pdesc,"t2="))>=0)
- autocloseTime = (float)llGetSubString(pdesc,i+3,-1);
- llOwnerSay("ANGLE="+(string)openingAngle);
- llOwnerSay("Started, accsess allowed to "+llList2String(["public","group","owner"],access) );
- swinging=FALSE;
- open=FALSE;
- omega=TWO_PI/360*openingAngle/openingTime;
- llTargetOmega(ZERO_VECTOR,1.0,1.0);
- }
- on_rez(integer sp) { llResetScript(); }
- changed(integer change)
- {
- if(change & CHANGED_LINK)
- {
- integer links = 0;
- if(llGetObjectPrimCount(llGetKey()) < (links = llGetNumberOfPrims()))
- ; // Seated on...
- else
- llResetScript();
- }
- }
- touch_start(integer dummy)
- {
- llMessageLinked(LINK_THIS,100,"",llDetectedKey(0));
- }
- link_message(integer src, integer cmd, string msg, key id)
- {
- if( (src!=LINK_DA) && (src!=LINK_DB) ) return;
- if(cmd==100) // TOUCHED
- {
- if( ((access==2) && (id!=llGetOwner()))
- || ((access==1) && (!llSameGroup(id)) ) )
- return;
- if(!swinging)
- {
- if(!open)
- llMessageLinked(LINK_SET,110,"","");
- llMessageLinked(LINK_SET,111,(string)(!open),"");
- }
- }
- else if (cmd==110)
- {
- axis=llRot2Up(llGetLocalRot());
- closedRot=llGetLocalRot();
- closedRot2=llEuler2Rot(<0, 0, 180>*DEG_TO_RAD)*closedRot;
- openRot=llEuler2Rot(<0, 0, openingAngle>*DEG_TO_RAD)*closedRot;
- // openRot2=llEuler2Rot((<0,0,180>-llRot2Euler(openRot)*RAD_TO_DEG)*DEG_TO_RAD);
- openRot2=llEuler2Rot(<0, 0, 180-openingAngle>*DEG_TO_RAD)*closedRot;
- }
- else if(cmd==111)
- {
- if(!(open=(integer)msg))
- llMessageLinked(LINK_SET,112,(string)(-axis),(string)omega);
- else
- llMessageLinked(LINK_SET,112,(string)(axis),(string)omega);
- swinging=TRUE;
- llSetTimerEvent(openingTime);
- }
- else if(cmd==112)
- {
- llTargetOmega((vector)msg,(float)((string)id),1.0);
- }
- else if(cmd==124)
- {
- llTargetOmega((vector)msg,0.0,0.0);
- llSetLocalRot((rotation)((string)id));
- }
- }
- timer()
- {
- if(swinging)
- {
- swinging=FALSE;
- if(open)
- {
- llMessageLinked(LINK_DA,124,(string)axis,(string)openRot);
- llMessageLinked(LINK_DB,124,(string)axis,(string )openRot2);
- llSetTimerEvent(autocloseTime);
- }
- else
- {
- llMessageLinked(LINK_DA,124,(string)axis,(string )closedRot);
- llMessageLinked(LINK_DB,124,(string)axis,(string )closedRot2);
- llSetTimerEvent(0.0);
- }
- }
- else
- llMessageLinked(LINK_SET,111,(string)(!open),"");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement