Door script 0.3
Appearance
<source lang=lsl>
/*
Fu's talking door script v0.3 - Access Control List (acl) for locking mechanism - acl check function
v0.2 - locking door latch - "CONSTANTS" for code clarity
v0.1 - state changes - passing data between states - llListen() and listen event handler
v0.0 - basic states
(c)2017 - Fu Barr (OSGrid)
- /
integer DEBUG = TRUE;
string code_lock = "Lockus locke"; string code_unlock = "Unlockus locke";
list acl = ["Mr Locke"];
integer latch;
string txt_unlocked = "This door is now unlocked."; string txt_locked = "This door is now locked."; string txt_noentry = "Locked."; string txt_noacl = "You may not command this door."; string txt_welcome = "Welcome, ";
integer acl_check(key uuid) {
//
// an empty acl list implies a lock open to all.
if(DEBUG){llOwnerSay("acl_check() checking: " + uuid);}
if(llGetListLength(acl) > 0) {
if(llListFindList(acl, [llKey2Name(uuid)]) > -1) {
return TRUE;
} else {
return FALSE;
}
} else {
if(DEBUG){llOwnerSay("acl_check(): No ACL entries. Lock disabled.");}
return TRUE; }
}
default {
on_rez(integer r) {
llResetScript(); }
state_entry() {
latch = "UNLOCKED";
llOwnerSay("running " + llGetScriptName());
state closed; }
}
state closed {
state_entry() {
llListen(0, "", NULL_KEY, code_unlock); // using two llListen() for early channel 0 chat filter
llListen(0, "", NULL_KEY, code_lock);
}
state_exit() {
// TODO: swing door open }
touch_end(integer t) {
if(latch == "LOCKED") {
llSay(0, txt_noentry);
} else {
state open;
}
}
listen(integer channel, string name, key uuid, string msg) {
if(DEBUG){llOwnerSay("closed::listen() key: " + uuid);}
if(acl_check(uuid)) {
if(msg == code_unlock){
latch = "UNLOCKED";
llSay(0, txt_unlocked);
} else if(msg == code_lock) {
latch = "LOCKED";
llSay(0, txt_locked);
}
} else {
llSay(0, txt_noacl);
}
}
}
state open {
state_entry() {
llSay(0, txt_welcome + llKey2Name(avatar_uuid));
state closed; }
state_exit() {
// TODO: swing door shut }
}
</source>