// Door Lock script -- JohnG Linden ¡¡¡¡// To make this script open/close an actual door, the door should listen ¡¡¡¡// for the following messages on the following chat channel. One lock ¡¡¡¡// can control multiple doors if they all listen on the same channel. ¡¡¡¡// ¡¡¡¡// It is advisable for you to pick your own channel number so other locks ¡¡¡¡// in the area don't inadvertently open/close your door. ¡¡¡¡// ¡¡¡¡integer gLockChannel = 9394834; ¡¡¡¡string gOpenMsg = "MSG_OPEN"; ¡¡¡¡string gCloseMsg = "MSG_CLOSE"; ¡¡¡¡// ¡¡¡¡// Final note: if you need to open doors a long way from the lock, look ¡¡¡¡// for the functions door_open_msg() and door_close_msg() below, and ¡¡¡¡// change the llSay() to llShout(). ¡¡¡¡// who owns this door ¡¡¡¡// this is changed by on_rez to whoever rezzed the door ¡¡¡¡string gAdministrator = ""; ¡¡¡¡// who's in and who's out ¡¡¡¡// can be changed by the admin at runtime ¡¡¡¡list gAdmittedList = ¡¡¡¡[ ¡¡¡¡]; ¡¡¡¡list gBannedList = ¡¡¡¡[ ¡¡¡¡]; ¡¡¡¡// return values from permissions funcs ¡¡¡¡integer PERM_BANNED = -1; ¡¡¡¡integer PERM_NO = 0; ¡¡¡¡integer PERM_ADMIN = 1; ¡¡¡¡integer PERM_OK = 2; ¡¡¡¡// permission given to people not on any list ¡¡¡¡// if you just want to exclude people on the banned list and admit ¡¡¡¡// everyone else, set to PERM_OK ¡¡¡¡integer gDefaultPerm = PERM_NO; ¡¡¡¡// Note: this all would be much easier with lists that can contain lists, ¡¡¡¡// as people could have multiple properties hanging on them. Currently ¡¡¡¡// it's better than arrays but is still somewhat broken, because you have ¡¡¡¡// to assume a # of data fields instead of being able to traverse a list ¡¡¡¡// of lists. ¡¡¡¡// ¡¡¡¡// Helper functions here ¡¡¡¡// ¡¡¡¡func_debug(string str) ¡¡¡¡{ ¡¡¡¡// llSay(0, str); ¡¡¡¡} ¡¡¡¡debug(string str) ¡¡¡¡{ ¡¡¡¡// llSay(0, str); ¡¡¡¡} ¡¡¡¡say(string str) ¡¡¡¡{ ¡¡¡¡llSay(0, str); ¡¡¡¡} ¡¡¡¡// is name on admitted list? ¡¡¡¡integer check_admitted_list (string name) ¡¡¡¡{ ¡¡¡¡if ( llListFindList(gAdmittedList, [name]) >= 0 ) ¡¡¡¡{ ¡¡¡¡return TRUE; ¡¡¡¡} else ¡¡¡¡{ ¡¡¡¡return FALSE; ¡¡¡¡} ¡¡¡¡} ¡¡¡¡// is name on banned list? ¡¡¡¡integer check_banned_list (string name) ¡¡¡¡{ ¡¡¡¡if ( llListFindList(gBannedList, [name]) >= 0 ) ¡¡¡¡{ ¡¡¡¡return TRUE; ¡¡¡¡} else ¡¡¡¡{ ¡¡¡¡return FALSE; ¡¡¡¡} ¡¡¡¡} ¡¡¡¡// does name have perms to open the door? ¡¡¡¡integer check_permission (string name) ¡¡¡¡{ ¡¡¡¡say("check_permission: " + name); ¡¡¡¡// admin always wins (and cannot ban themselves) ¡¡¡¡if ( name == gAdministrator ) return PERM_ADMIN; ¡¡¡¡// now check the plebeians ¡¡¡¡if ( check_banned_list(name) == TRUE ) return PERM_BANNED; ¡¡¡¡if ( check_admitted_list(name) == TRUE ) return PERM_OK; ¡¡¡¡// not on any lists, check default ¡¡¡¡return gDefaultPerm; ¡¡¡¡} ¡¡¡¡add_to_admitted_list (string name) ¡¡¡¡{ ¡¡¡¡func_debug("add_to_admitted_list"); ¡¡¡¡gAdmittedList = gAdmittedList + name; ¡¡¡¡} ¡¡¡¡add_to_banned_list (string name) ¡¡¡¡{ ¡¡¡¡func_debug("add_to_banned_list"); ¡¡¡¡gBannedList = gBannedList + name; ¡¡¡¡} ¡¡¡¡integer remove_from_admitted_list (string name) ¡¡¡¡{ ¡¡¡¡func_debug("remove_from_admitted_list"); ¡¡¡¡list lyst; ¡¡¡¡debug("admit: looking for " + name); ¡¡¡¡// search and destroy ¡¡¡¡integer index = llListFindList(gAdmittedList, [name]); ¡¡¡¡if ( index >= 0 ) ¡¡¡¡{ ¡¡¡¡debug("admit: found " + name); ¡¡¡¡// remove entry ¡¡¡¡gAdmittedList = llDeleteSubList(gAdmittedList, index, index); ¡¡¡¡return TRUE; ¡¡¡¡} ¡¡¡¡// couldn't find ¡¡¡¡debug("admit: can't find " + name); ¡¡¡¡return FALSE; ¡¡¡¡} ¡¡¡¡integer remove_from_banned_list (string name) ¡¡¡¡{ ¡¡¡¡func_debug("remove_from_banned_list"); ¡¡¡¡list lyst; ¡¡¡¡debug("ban: looking for " + name); ¡¡¡¡// search and destroy ¡¡¡¡integer index = llListFindList(gBannedList, [name]); ¡¡¡¡if ( index >= 0 ) ¡¡¡¡{ ¡¡¡¡debug("ban: found " + name); ¡¡¡¡// remove entry ¡¡¡¡gBannedList = llDeleteSubList(gBannedList, index, index); ¡¡¡¡return TRUE; ¡¡¡¡} ¡¡¡¡// couldn't find ¡¡¡¡debug("ban: can't find " + name); ¡¡¡¡return FALSE; ¡¡¡¡} ¡¡¡¡show_list (list src) ¡¡¡¡{ ¡¡¡¡integer i; ¡¡¡¡integer len = llGetListLength(src); ¡¡¡¡for ( i = 0; i gOpenTime ) ¡¡¡¡{ ¡¡¡¡// stop timer interrupts ¡¡¡¡llSetTimerEvent(0.0); ¡¡¡¡// door is now open ¡¡¡¡state door_open; ¡¡¡¡} ¡¡¡¡} ¡¡¡¡state_exit() ¡¡¡¡{ ¡¡¡¡llStopSound(); ¡¡¡¡} ¡¡¡¡} ¡¡¡¡state door_open ¡¡¡¡{ ¡¡¡¡on_rez(integer arg) { llResetscript(); } ¡¡¡¡state_entry() ¡¡¡¡{ ¡¡¡¡func_debug("door_open state_entry"); ¡¡¡¡// make us permeable ¡¡¡¡llSetStatus(STATUS_PHANTOM, TRUE); ¡¡¡¡} ¡¡¡¡listen(integer channel, string name, key id, string msg) ¡¡¡¡{ ¡¡¡¡if ( msg == gCloseMsg ) ¡¡¡¡{ ¡¡¡¡state door_closing; ¡¡¡¡} ¡¡¡¡} ¡¡¡¡} ¡¡¡¡state door_closing ¡¡¡¡{ ¡¡¡¡on_rez(integer arg) { llResetscript(); } ¡¡¡¡state_entry() ¡¡¡¡{ ¡¡¡¡func_debug("door_closing state_entry"); ¡¡¡¡// audio ¡¡¡¡llLoopSound(gCloseSound, gSoundVolume); ¡¡¡¡// start opening process ¡¡¡¡llResetTime(); ¡¡¡¡gOpenTimer = 0.0; ¡¡¡¡llSetTimerEvent(gOpenTimeStep); ¡¡¡¡} ¡¡¡¡timer() ¡¡¡¡{ ¡¡¡¡float time = llGetTime(); ¡¡¡¡// interpolate transparency from closed to open ¡¡¡¡float alpha = (time / gOpenTime) * (gClosedAlpha - gOpenAlpha) + gOpenAlpha; ¡¡¡¡llSetAlpha(alpha, ALL_SIDES); ¡¡¡¡if ( time > gOpenTime ) ¡¡¡¡{ ¡¡¡¡// stop timer interrupts ¡¡¡¡llSetTimerEvent(0.0); ¡¡¡¡// door is now closed ¡¡¡¡state door_closed; ¡¡¡¡} ¡¡¡¡} ¡¡¡¡state_exit() ¡¡¡¡{ ¡¡¡¡// kill closing sound ¡¡¡¡llStopSound(); ¡¡¡¡}
Door script // ·Åµ½ÃÅÎïÌåÖÐ
// materialize/dematerialize door movement script ¡¡¡¡// JohnG Linden ¡¡¡¡// NOTE: these definitions should be the same as those from the lock ¡¡¡¡// object or the door will not actually work ¡¡¡¡integer gLockChannel = 9394834; ¡¡¡¡string gOpenMsg = "MSG_OPEN"; ¡¡¡¡string gCloseMsg = "MSG_CLOSE"; ¡¡¡¡// where we are when closed ¡¡¡¡vector gClosedPos; ¡¡¡¡rotation gClosedRot; ¡¡¡¡// internal timer for opening ¡¡¡¡float gOpenTimer; ¡¡¡¡// how long it takes to open/close ¡¡¡¡float gOpenTime = 1.3; ¡¡¡¡// how many steps along the way ¡¡¡¡float gOpenTimeStep = 0.2; ¡¡¡¡// how transparent when open ¡¡¡¡float gOpenAlpha = 0.00; ¡¡¡¡float gClosedAlpha = 1.0; ¡¡¡¡// sound we loop when opening/closing ¡¡¡¡string gOpenSound = "open"; ¡¡¡¡string gCloseSound = "close"; ¡¡¡¡float gSoundVolume = 0.6; ¡¡¡¡// ¡¡¡¡// helper functions ¡¡¡¡// ¡¡¡¡func_debug(string str) ¡¡¡¡{ ¡¡¡¡// llSay(0, str); ¡¡¡¡} ¡¡¡¡debug(string str) ¡¡¡¡{ ¡¡¡¡// llSay(0, str); ¡¡¡¡} ¡¡¡¡say(string str) ¡¡¡¡{ ¡¡¡¡llSay(0, str); ¡¡¡¡} ¡¡¡¡// ¡¡¡¡// states begin here ¡¡¡¡// ¡¡¡¡default ¡¡¡¡{ ¡¡¡¡on_rez(integer arg) { llResetscript(); } ¡¡¡¡state_entry() ¡¡¡¡{ ¡¡¡¡func_debug("default state_entry"); ¡¡¡¡// no physics ¡¡¡¡llSetStatus(STATUS_PHYSICS, FALSE); ¡¡¡¡// open/close timer ¡¡¡¡gOpenTimer = 0.0; ¡¡¡¡// listen for open/close messages ¡¡¡¡llListen(gLockChannel, "", "", ""); ¡¡¡¡// and go to closed state ¡¡¡¡state door_closed; ¡¡¡¡} ¡¡¡¡} ¡¡¡¡state door_closed ¡¡¡¡{ ¡¡¡¡on_rez(integer arg) { llResetscript(); } ¡¡¡¡state_entry() ¡¡¡¡{ ¡¡¡¡func_debug("door_closed state_entry"); ¡¡¡¡// make us impermeable ¡¡¡¡llSetStatus(STATUS_PHANTOM, FALSE); ¡¡¡¡} ¡¡¡¡listen(integer channel, string name, key id, string msg) ¡¡¡¡{ ¡¡¡¡if ( msg == gOpenMsg ) ¡¡¡¡{ ¡¡¡¡state door_opening; ¡¡¡¡} ¡¡¡¡} ¡¡¡¡} ¡¡¡¡state door_opening ¡¡¡¡{ ¡¡¡¡on_rez(integer arg) { llResetscript(); } ¡¡¡¡state_entry() ¡¡¡¡{ ¡¡¡¡func_debug("door_opening state_entry"); ¡¡¡¡// start opening sound ¡¡¡¡llLoopSound(gOpenSound, gSoundVolume); ¡¡¡¡// start opening process ¡¡¡¡llResetTime(); ¡¡¡¡gOpenTimer = 0.0; ¡¡¡¡llSetTimerEvent(gOpenTimeStep); ¡¡¡¡} ¡¡¡¡timer() ¡¡¡¡{ ¡¡¡¡float time = llGetTime(); ¡¡¡¡// interpolate transparency from closed to open ¡¡¡¡float alpha = (1 - (time / gOpenTime)) * (gClosedAlpha - gOpenAlpha) + gOpenAlpha; ¡¡¡¡llSetAlpha(alpha, ALL_SIDES); ¡¡¡¡if ( time > gOpenTime ) ¡¡¡¡{ ¡¡¡¡// stop timer interrupts ¡¡¡¡llSetTimerEvent(0.0); ¡¡¡¡// door is now open ¡¡¡¡state door_open; ¡¡¡¡} ¡¡¡¡} ¡¡¡¡state_exit() ¡¡¡¡{ ¡¡¡¡llStopSound(); ¡¡¡¡} ¡¡¡¡} ¡¡¡¡state door_open ¡¡¡¡{ ¡¡¡¡on_rez(integer arg) { llResetscript(); } ¡¡¡¡state_entry() ¡¡¡¡{ ¡¡¡¡func_debug("door_open state_entry"); ¡¡¡¡// make us permeable ¡¡¡¡llSetStatus(STATUS_PHANTOM, TRUE); ¡¡¡¡} ¡¡¡¡listen(integer channel, string name, key id, string msg) ¡¡¡¡{ ¡¡¡¡if ( msg == gCloseMsg ) ¡¡¡¡{ ¡¡¡¡state door_closing; ¡¡¡¡} ¡¡¡¡} ¡¡¡¡} ¡¡¡¡state door_closing ¡¡¡¡{ ¡¡¡¡on_rez(integer arg) { llResetscript(); } ¡¡¡¡state_entry() ¡¡¡¡{ ¡¡¡¡func_debug("door_closing state_entry"); ¡¡¡¡// audio ¡¡¡¡llLoopSound(gCloseSound, gSoundVolume); ¡¡¡¡// start opening process ¡¡¡¡llResetTime(); ¡¡¡¡gOpenTimer = 0.0; ¡¡¡¡llSetTimerEvent(gOpenTimeStep); ¡¡¡¡} ¡¡¡¡timer() ¡¡¡¡{ ¡¡¡¡float time = llGetTime(); ¡¡¡¡// interpolate transparency from closed to open ¡¡¡¡float alpha = (time / gOpenTime) * (gClosedAlpha - gOpenAlpha) + gOpenAlpha; ¡¡¡¡llSetAlpha(alpha, ALL_SIDES); ¡¡¡¡if ( time > gOpenTime ) ¡¡¡¡{ ¡¡¡¡// stop timer interrupts ¡¡¡¡llSetTimerEvent(0.0); ¡¡¡¡// door is now closed ¡¡¡¡state door_closed; ¡¡¡¡} ¡¡¡¡} ¡¡¡¡state_exit() ¡¡¡¡{ ¡¡¡¡// kill closing sound ¡¡¡¡llStopSound(); ¡¡¡¡} ¡¡¡¡}
|