Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

scripting key and door

JJames Alter
Registered User
Join date: 18 Jul 2008
Posts: 10
09-13-2008 20:57
i want to script a key and door, where if the user is wearing the keyas an attachment to like a hud or something, and when he or she clicks on the door, and then the key whispers the "password" and the door checks the "password" and if its correct, it opens up.
--edit i figured it out :D
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
09-13-2008 23:05
the simplest way I know to achieve this (for those that didn't figure it out) is to have the key listen for the door. when the door is touched it chats a message including the user id of the person that touched it, the key hears this, and if it matches the key owners id the key chat's back a message to open... the door hears this and opens.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Faust Vollmar
llSetAgentSanity(FALSE);
Join date: 3 Feb 2007
Posts: 87
09-14-2008 05:41
Even though I saw the edit that you've said you got it, I'm providing this... Probably has some idiotic scripting but it works, gave it a good test run. :D
(I believe quoting gives out the original indentation.)

DOOR: (The included Open and Close functions use my favorite method of HollowDoor.)



//Door Authorization (Door) Script by Faust Vollmar.
//Released under CC-by 3.0 Licence.
//String Replace Function from the Combined Library, used under Creative Commons.
//
//Uses very simple Xor Encryption to make aquiring the password require more effort than a listener, nothing more.
//Doors don't really stop people, but one functioning on a key makes for a nice RP scenepiece, thus the SayOnFail and SayType variables.

integer SPEAK_WHISPER = 1;
integer SPEAK_INSTANT = 2;
integer SPEAK_OWNER = 3;
/////Start Config Stuff./////
integer channel = -900;
string password = "HiImAPassword";
float TimeThenClose = 10.0;
string SayOnFail = "Authentication Failed."; // Use %w to include an avatar name. Use "" to disable messages.
integer SayType = SPEAK_INSTANT;
/////End Config Stuff./////
integer primtype;
key IdentifyKey = NULL_KEY;
integer AuthTimer = FALSE;
integer AuthListen;


string str_replace(string src, string from, string to)
{
integer len = (~-(llStringLength(from)));
if(~len)
{
string buffer = src;
integer b_pos = -1;
integer to_len = (~-(llStringLength(to)));
@loop;
integer to_pos = ~llSubStringIndex(buffer, from);
if(to_pos)
{
buffer = llGetSubString(src = llInsertString(llDeleteSubString(src, b_pos -= to_pos, b_pos + len), b_pos, to), (-~(b_pos += to_len)), 0x8000);
jump loop;
}
}
return src;
}

open()
{
llSetPrimitiveParams([PRIM_TYPE, primtype , PRIM_HOLE_DEFAULT, <0.0,1.0,0.0>, 0.95, ZERO_VECTOR, <1.0,1.0,0.0>, ZERO_VECTOR]);
}
close()
{
llSetPrimitiveParams([PRIM_TYPE, primtype , PRIM_HOLE_DEFAULT, <0.0,1.0,0.0>, 0.0, ZERO_VECTOR, <1.0,1.0,0.0>, ZERO_VECTOR]);
}

default
{
state_entry()
{
primtype = llList2Integer(llGetPrimitiveParams([PRIM_TYPE]),0);
}
touch_start(integer num)
{
IdentifyKey = llDetectedKey(0);
AuthListen = llListen(channel,"","","";);
llWhisper(channel,"keycheck#" + (string)IdentifyKey);
llSetTimerEvent(5);
}
listen(integer channel, string name, key id, string message)
{
string date = llGetDate();
string decrypt = llBase64ToString(llXorBase64StringsCorrect(message, llStringToBase64(password + date)));
list input = llParseString2List(decrypt, ["#"],[]);
key checkIdentifyKey = llList2Key(input,1);
string checkkey = llList2String(input, 0);
string sender = llGetOwnerKey(id);

if(checkkey == password && checkIdentifyKey == IdentifyKey)
{
llListenRemove(AuthListen);
IdentifyKey = NULL_KEY;
open();
llSetTimerEvent(TimeThenClose);
}
else
{
llListenRemove(AuthListen);
string SayPaste = str_replace(SayOnFail, "%w", llKey2Name(sender));

if(SayOnFail != "";)
{
if(SayType == 1)
{
llWhisper(0, SayPaste);
}
else if(SayType == 2)
{
llInstantMessage(sender, SayPaste);
}
if(SayType == 3)
{
llOwnerSay(SayPaste);
}
}
}
}
timer()
{
if(AuthTimer)
{
llListenRemove(AuthListen);
IdentifyKey = NULL_KEY;
}
else
{
close();
}
llSetTimerEvent(0);
}
}



KEY: Rezzed, Worn (Body or Hud), doesn't matter.




//Door Authorization (Key) Script by Faust Vollmar.
//Free to use or modify, however distribution as-is must be free of charge.

//Start Config Stuff.//
integer channel = -900;
string password = "HiImAPassword";
//End Config Stuff.//

default
{
state_entry()
{
llListen(channel,"","","";);
}

listen(integer channel, string name, key id, string message)
{
key owner = llGetOwner();
list input = llParseString2List(message, ["#"],[]);
string param = llList2String(input, 0);
key ident = llList2Key(input, 1);

if(param == "keycheck" && ident == owner);
{
string date = llGetDate();
string crypt = llXorBase64StringsCorrect(llStringToBase64(password + "#" + (string)owner), llStringToBase64(password + date));
llWhisper(channel, crypt);
}
}
}
Faust Vollmar
llSetAgentSanity(FALSE);
Join date: 3 Feb 2007
Posts: 87
09-14-2008 10:24
If anyone would like, I made a basic system for this.
The included door open/close functions are for a hollow/full door, my favorite type.
Probably has scripting idiocies, but it works.
EDIT: Probably doesn't belong here in hindsight but hey maybe the OP will gain something fro it. XD

---DOOR SCRIPT---

//Door Authorization (Door) Script by Faust Vollmar.
//Free to Use, Modify or Distribute (Distribution as is must be free of charge.)
//
//Uses very simple Xor Encryption to make aquiring the password require more effort than a listener, nothing more.
//Doors don't really stop people, but one functioning on a key makes for a nice RP scenepiece, thus the SayOnFail and SayType variables.

integer SPEAK_WHISPER = 1;
integer SPEAK_INSTANT = 2;
integer SPEAK_OWNER = 3;
/////Start Config Stuff./////
integer channel = -900;
string password = "HiImAPassword";
float TimeThenClose = 10.0;
string SayOnFail = "Authentication Failed."; // Use %w to include an avatar name. Use "" to disable messages.
integer SayType = SPEAK_OWNER;
/////End Config Stuff./////
integer primtype;
key IdentifyKey = NULL_KEY;
integer AuthTimer = FALSE;
integer AuthListen;


string stringfindreplace(string source, string from, string to)
{
integer fromlen = llStringLength(from) -1;
integer tolen = llStringLength(to);
if(fromlen != -1)
{
string tempstore = source;
while(llSubStringIndex(tempstore, from) != -1)
{
integer pos = llSubStringIndex(tempstore, from);
tempstore = llInsertString(llDeleteSubString(source, pos, pos + fromlen),pos, to);
source = tempstore;
}
}
return source;
}

open()
{
llSetPrimitiveParams([PRIM_TYPE, primtype , PRIM_HOLE_DEFAULT, <0.0,1.0,0.0>, 0.95, ZERO_VECTOR, <1.0,1.0,0.0>, ZERO_VECTOR]);
}
close()
{
llSetPrimitiveParams([PRIM_TYPE, primtype , PRIM_HOLE_DEFAULT, <0.0,1.0,0.0>, 0.0, ZERO_VECTOR, <1.0,1.0,0.0>, ZERO_VECTOR]);
}

default
{
state_entry()
{
primtype = llList2Integer(llGetPrimitiveParams([PRIM_TYPE]),0);
}
touch_start(integer num)
{
IdentifyKey = llDetectedKey(0);
AuthListen = llListen(channel,"","","";);
llWhisper(channel,"keycheck#" + (string)IdentifyKey);
llSetTimerEvent(5);
}
listen(integer channel, string name, key id, string message)
{
string date = llGetDate();
string decrypt = llBase64ToString(llXorBase64StringsCorrect(message, llStringToBase64(password + date)));
list input = llParseString2List(decrypt, ["#"],[]);
key checkIdentifyKey = llList2Key(input,1);
string checkkey = llList2String(input, 0);
string sender = llGetOwnerKey(id);

if(checkkey == password && checkIdentifyKey == IdentifyKey)
{
llListenRemove(AuthListen);
IdentifyKey = NULL_KEY;
open();
llSetTimerEvent(TimeThenClose);
}
else
{
llListenRemove(AuthListen);
string SayPaste = stringfindreplace(SayOnFail, "%w", llKey2Name(sender));

if(SayOnFail != "";)
{
if(SayType == 1)
{
llWhisper(0, SayPaste);
}
else if(SayType == 2)
{
llInstantMessage(sender, SayPaste);
}
if(SayType == 3)
{
llOwnerSay(SayPaste);
}
}
}
}
timer()
{
if(AuthTimer)
{
llListenRemove(AuthListen);
IdentifyKey = NULL_KEY;
}
else
{
close();
}
llSetTimerEvent(0);
}
}

---KEY SCRIPT---

//Door Authorization (Key) Script by Faust Vollmar.
//Free to Use, Modify or Distribute (Distribution as is must be free of charge.)

//Start Config Stuff.//
integer channel = -900;
string password = "HiImAPassword";
//End Config Stuff.//

default
{
on_rez(integer start)
{
llResetScript();
}
state_entry()
{
llListen(channel,"","","";);
}
listen(integer channel, string name, key id, string message)
{
key owner = llGetOwner();
list input = llParseString2List(message, ["#"],[]);
string param = llList2String(input, 0);
key ident = llList2Key(input, 1);

if(param == "keycheck" && ident == owner);
{
string date = llGetDate();
string crypt = llXorBase64StringsCorrect(llStringToBase64(password + "#" + (string)owner), llStringToBase64(password + date));
llWhisper(channel, crypt);
}
}
}