Module LockableTwoWayDoors { ' Lockable Doors for multi-player games library. ' R.Rawson-Tetley, October 2001 ' Version 011104 ' ' Modifications: ' ' 011104 Outputs door actions to other players ' 011019 Initial version ' ============================================= ' Code for handling door items. When using doors, you ' must do the following: ' ' 1. Define two items representing each door - ' easiest to create one and clone it. Put them in ' the two locations you want to join, one each. ' 2. Your door items must be invisible and have ' their Can Open? Property set. Set Initially ' open if you want the doors to be open. ' 3. The initial description should contain the when open string ' 4. The readabletext should contain the when closed string. ' 5. You should make a call in the location.ondisplay to displaydoor ' (in both locations where the door appears and for the right door). ' 6. You should make a call to doorhandler in the OnAction event. ' 7. You will have to handle blocking the player yourself in the ' location(x).oninput event. Note that it works better to set ' the location movement properties as if the door wasn't ' there and catch the player trying to go that way and stop ' them if the door is closed. '=============================================== ' If you want your door initially locked, set the userboolean ' "locked" for that object in the IDE. proc open door1 door2 keyitem if ( item(door1).openclosestate = true ) then currentplayer.print The^_&_item(itemno).thename_&_^is^already^open. end endif if ( item(door1).getuserboolean(locked) = true ) then if ( currentplayer.iscarrying(keyitem) = true ) then currentplayer.print (unlocking^it^first,^with^the^_&_item(keyitem).thename_&_) printallinexcept item(door1).currentlocation currentplayer.index currentplayer.name_&_^unlocks^the^_&_item(door1).thename_&_. printallinexcept item(door2).currentlocation currentplayer.index currentplayer.name_&_^unlocks^the^_&_item(door2).thename_&_. item(door1).removeuserboolean(locked) item(door2).removeuserboolean(locked) currentplayer.print Opened. printallinexcept item(door1).currentlocation currentplayer.index currentplayer.name_&_^opens^the^_&_item(door1).thename_&_. printallinexcept item(door2).currentlocation currentplayer.index currentplayer.name_&_^opens^the^_&_item(door2).thename_&_. item(door1).openclosestate = true item(door2).openclosestate = true end endif endif if ( item(door1).getuserboolean(locked) = true ) then currentplayer.print The^_&_item(door1).thename_&_^is^locked. end endif currentplayer.print Opened. printallinexcept item(door1).currentlocation currentplayer.index currentplayer.name_&_^opens^the^_&_item(door1).thename_&_. printallinexcept item(door2).currentlocation currentplayer.index currentplayer.name_&_^opens^the^_&_item(door2).thename_&_. item(door1).openclosestate = true item(door2).openclosestate = true end proc close door1 door2 if ( item(door1).openclosestate = false ) then currentplayer.print The^_&_item(door1).thename_&_^is^already^closed. end endif currentplayer.print Closed. printallinexcept item(door1).currentlocation currentplayer.index currentplayer.name_&_^closes^the^_&_item(door1).thename_&_. printallinexcept item(door2).currentlocation currentplayer.index currentplayer.name_&_^closes^the^_&_item(door2).thename_&_. item(door1).openclosestate = false item(door2).openclosestate = false end proc lock door1 door2 keyitem if ( item(door1).openclosestate = true ) then currentplayer.print (closing^the^_&_item(door1).thename_&_^first) printallinexcept item(door1).currentlocation currentplayer.index currentplayer.name_&_^closes^the^_&_item(door1).thename_&_. printallinexcept item(door2).currentlocation currentplayer.index currentplayer.name_&_^closes^the^_&_item(door2).thename_&_. item(door1).openclosestate = false item(door2).openclosestate = false endif if ( item(door1).getuserboolean(locked) = true ) then currentplayer.print The^_&_item(door1).thename_&_^is^already^locked. end endif if ( currentplayer.iscarrying(keyitem) = true ) and ( input.noun2 = 0 ) then currentplayer.print (with^the^_&_item(keyitem).thename_&_) currentplayer.print Locked. printallinexcept item(door1).currentlocation currentplayer.index currentplayer.name_&_^locks^the^_&_item(door1).thename_&_. printallinexcept item(door2).currentlocation currentplayer.index currentplayer.name_&_^locks^the^_&_item(door2).thename_&_. item(door1).adduserboolean(locked) item(door2).adduserboolean(locked) endif var n2item = getitemfromnoun input.noun2 if ( currentplayer.iscarrying(keyitem) = false ) or ( keyitem <> n2item ) then currentplayer.print What^do^you^want^to^lock^the^_&_item(door1).thename_&_^with? end endif currentplayer.print Locked. printallinexcept item(door1).currentlocation currentplayer.index currentplayer.name_&_^locks^the^_&_item(door1).thename_&_. printallinexcept item(door2).currentlocation currentplayer.index currentplayer.name_&_^locks^the^_&_item(door2).thename_&_. item(door1).adduserboolean(locked) item(door2).adduserboolean(locked) end proc unlock door1 door2 keyitem if ( item(door1).getuserboolean(locked) = false ) then currentplayer.print The^_&_item(door1).thename_&_^is^not^locked. end endif if ( currentplayer.iscarrying(keyitem) = true ) and ( input.noun2 = 0 ) then currentplayer.print (with^the^_&_item(keyitem).thename_&_) currentplayer.print Unlocked. printallinexcept item(door1).currentlocation currentplayer.index currentplayer.name_&_^unlocks^the^_&_item(door1).thename_&_. printallinexcept item(door2).currentlocation currentplayer.index currentplayer.name_&_^unlocks^the^_&_item(door2).thename_&_. item(door1).removeuserboolean(locked) item(door2).removeuserboolean(locked) end endif var n2item = getitemfromnoun input.noun2 if ( currentplayer.iscarrying(keyitem) = false ) or ( keyitem <> n2item ) then currentplayer.print What^do^you^want^to^unlock^the^_&_item(door1).thename_&_^with? end endif currentplayer.print Unlocked. printallinexcept item(door1).currentlocation currentplayer.index currentplayer.name_&_^unlocks^the^_&_item(door1).thename_&_. printallinexcept item(door2).currentlocation currentplayer.index currentplayer.name_&_^unlocks^the^_&_item(door2).thename_&_. item(door1).removeuserboolean(locked) item(door2).removeuserboolean(locked) end proc displaydoor itemno item(itemno).currentlocation = currentplayer.currentlocation if ( item(itemno).openclosestate = true ) then currentplayer.print item(itemno).description else currentplayer.print item(itemno).readabletext endif end proc doorhandler door1 door2 keyitem ;open call LockableTwoWayDoors.open door1 door2 keyitem end endif ;close call LockableTwoWayDoors.close door1 door2 end endif ;unlock call LockableTwoWayDoors.close door1 door2 keyitem end endif ;lock call LockableTwoWayDoors.lock door1 door2 keyitem end endif end }