vibrokatana
New Member
I was so bored out of my mind I spent a half an hour creating this monstrocity of a script:
I wanted to see how close I could come to single, double click mouse functions in second life. Now I am bored again :\
Tomorrow I guess I will go up to college and try to bury my nose in something to read. I am going insane, I need something interesting to do!
Please save me from my own insanity, I have spent time writing a door script, nothing good can come of this!
I wanted to see how close I could come to single, double click mouse functions in second life. Now I am bored again :\
Code:
integer gAllowEveryone = FALSE; //To allow anyone to open/close the door
integer gRotationalDependant = TRUE; //To move based on the rotation of the object, useful for unlinked doors that may be rezzed at different angles
vector gOffset = <0,-2,0>; //The amount to move (negative)
float gDelay = 0.3; //The delay to allow for the second click and beginning movement
integer gCommandChannel = -1234; //The base channel +FRand(200)
list gAdmins = ["Some Newb"]; //List of names to allow menu access, capitalization counts
//internal - do not modify
integer gTrigger = FALSE; //Goes to true on first click, false on second and aborts movement
integer gClosed = TRUE; //The integer that varies the direction for opening/closing
GeberateMenu(key id) //Generate the menu and display the dialog
{
list Options = [];
if(gAllowEveryone)
Options += "lock";
else
Options += "unlock";
Options += ["reset", "status"];
llDialog(id, "Please select and option", Options, gCommandChannel);
}
StartTrigger()
{
llSetTimerEvent(gDelay);
gTrigger = TRUE;
}
EndTrigger()
{
gTrigger = FALSE;
llSetTimerEvent(0);
}
ScriptInit() //Add in the owner if he is not in there
{
string OwnerName = llKey2Name(llGetOwner());
if(!~llListFindList(gAdmins, [OwnerName]))
gAdmins += OwnerName;
}
ShowStatus()
{
string Message = "\n\t";
Message += " Locked: ";
if(gAllowEveryone)
Message += "No";
else
Message += "Yes";
Message += "\n\t Open: ";
if(gClosed > 0) //-1 is open, 1 is closed
Message += "No";
else
Message += "Yes";
Message += "\n\t Admins: ";
Message += llDumpList2String(gAdmins, ", ");
llWhisper(0, Message);
}
default
{
changed(integer change)
{
if(change & CHANGED_OWNER)
llResetScript();
}
state_entry()
{
ScriptInit();
gCommandChannel += llRound(llFrand(200)); //Generate a random channel so they don't collide.
llListen(gCommandChannel, "", NULL_KEY, "");
}
touch_start(integer total_number)
{
key id = llDetectedKey(0);
integer Verified;
if((Verified = ~llListFindList(gAdmins, [llKey2Name(id)])) || gAllowEveryone) //Verify as an admin (!=0) or allow everyone
{
if(Verified && llGetAndResetTime() < gDelay && gTrigger) //must be verified, on the second click and within the delay
{
EndTrigger();
GeberateMenu(id);
}
else //The first click
StartTrigger();
}
}
timer()
{
if(gTrigger) //Incase the event fires check to see if it really needs to
{
vector MoveTo = llGetPos();
if(gRotationalDependant)
MoveTo += (gOffset * (gClosed = -gClosed)) * llGetRot();
else
MoveTo += (gOffset * (gClosed = -gClosed));
llSetPos(MoveTo);
}
EndTrigger();
}
listen(integer channel, string name, key id, string message)
{
string AVName = llKey2Name(llGetOwnerKey(id)); //Generate the owner name -> naming object as an avatar doesnt work
if(~llListFindList(gAdmins, [AVName])) //verify they are an admin
{
if(message == "lock")
{
gAllowEveryone = FALSE;
llWhisper(0,"Door Locked");
}
else if(message == "unlock")
{
gAllowEveryone = TRUE;
llWhisper(0,"Door Unlocked");
}
else if(message == "reset")
{
llWhisper(0,"Resetting Script");
llResetScript();
}
else if(message == "status")
ShowStatus();
}
}
}
Tomorrow I guess I will go up to college and try to bury my nose in something to read. I am going insane, I need something interesting to do!
Please save me from my own insanity, I have spent time writing a door script, nothing good can come of this!