Home ] Up ] 

Combination Lock with Variables
by Dreamless Dancer

EXCUSE THE GEOCITIES AD -->
DSPK V02.00 Furcadia


// Combination Lock DS
// Created by Dreamless Dancer, Oct 10, 2003
// title: Combination Lock DragonSpeak
// htmlname: combolock
// complete dream & ds
/*
This code is a little bouncy, and strict in the manner in which it's used.

I will deal with certain specifics within the code itself when I reach it.
One of the things you will note if you download the dream, is that I don't place any of the objects or floors used in this demo, demonstrating the total use of dragonspeak for the creation of dream areas.
*/


(0:9) When a furre arrives in the dream,
    (5:15) move the triggering furre to (12,22), or to someplace nearby if it's occupied.
    (5:200) emit message {Code is 247} to whoever set off the trigger

// begin variable setup

(0:0) When everything is starting up,
    (5:300) set variable %systemreset to the value 0.

/*
It was recommended to my by Ralen [ADM] that the (0:0) may cause problems with server reset resetting all variables to zero, therefore we use a variable to test for this state and restore all our dynamics if needed. We then implement a 1 second tick to check on the 'machine state'.
*/


(0:100) When 1 seconds have passed, offset by 0,
(1:200) and variable %systemreset is equal to 0.
    (5:300) set variable %systemreset to the value 1.

/*
We use a timer for furre leaving the lock zone for automatically clearing the grate. If you already have timers in your code, be certain to avoid using that one here. If you're using variables like this, put this one with the rest.
*/


    (5:300) set variable %combinationtimer to the value 1.

/*
This is the timeout value used for clearing the grate if someone should leave the area by leaving the dream. Note, not tested, but possible for log-off / log-on to put furre back in the lock hallway.
*/


    (5:300) set variable %combinationcheck to the value 5.

/*
This is the .X & .Y point at the end of the hall for the combination lock.

PLEASE NOTE:
I specify a SW to NE direction for the hallway, if you build it in a different direction, you will need to make some adjustments to the script. For reference's to the where's see the big numbered map, Click here for a by the numbers map.
*/


// [1] the position on the map where 'dialing' is to be done.

    (5:300) set variable %combinationdial.x to the value 20.
    (5:300) set variable %combinationdial.y to the value 13.

/*
Note that I place the tile here dynamically, this is not necessary, but is useful in locating position errors, if the square ain't where you want it, ...
*/


    (5:40) set the floor to type 145 at (%combinationdial).

/*
[A:B:C] the location of the three dials, you will note that I copy the dialer position to dial 2 first, then move it NE before copying dial 2 into 1 and 3 and moving them NW and SE. Again, I'm placing the dials dynamically to ensure that the images I manipulate are where I want them without having to locate them on the map ahead of time.
*/


    (5:301) copy the value of variable %combinationdial into variable %combinationdigit2
    (5:352) move the position in variable %combinationdigit2 northeast (up and right) 2 step(s).
    (5:301) copy the value of variable %combinationdigit2 into variable %combinationdigit1
    (5:355) move the position in variable %combinationdigit1 northwest (up and left) 1 step(s).
    (5:301) copy the value of variable %combinationdigit2 into variable %combinationdigit3
    (5:353) move the position in variable %combinationdigit3 southeast (down and right) 1 step(s).

// place the images, I'm using the 'square' digits, your preference may vary

    (5:300) set variable %combozeronumber to the value 465.

/*
This is the upper digit in the combination, '9', you can expand if you desire, in other words, Square 1, Round 2, Triangle 3, ...

Set the upper limit number of the combination dials.
*/


    (5:300) set variable %comborollover to the value 474.

/*
Now place 'zeros', this is repeated in several places, you may feel it's redundant to do it, but hey, I'm a programmer, this is the way I was taught.
*/


    (5:41) place object type %combozeronumber at (%combinationdigit1).
    (5:41) place object type %combozeronumber at (%combinationdigit2).
    (5:41) place object type %combozeronumber at (%combinationdigit3).

/*
[2,3] Gratings 1 & 2: The target for the combination lock to unlock is grating 1, grating 2 is the entry doorway into the combination hall, it's intention is to only allow one furre in the hallway to unlock the combination. This is bypassable because of the auto-exit system explained below. Again, note that they're placed dynamically by the code below.

Note: I use the grate / nograte floors for lock/unlock, if you want to use objects, you will need to change all the (5:40)'s to (5:41)'s throughout.
*/


// set the floor types

    (5:300) set variable %combolockitem to the value 162.
    (5:300) set variable %combounlockitem to the value 160.

// set the objects used for status, I used the toggle switch

    (5:300) set variable %combolockoff to the value 163.
    (5:300) set variable %combolockon to the value 164.

// position of the combonation unlocked 'door'

    (5:300) set variable %grating1.x to the value 18.
    (5:300) set variable %grating1.y to the value 17.

// [2]

    (5:40) set the floor to type %combolockitem at (%grating1).
    (5:301) copy the value of variable %grating1 into variable %insidelock1.
    (5:354) move the position in variable %insidelock1 southwest (down and left) 1 step(s).

// [5]

    (5:41) place object type %combolockon at (%insidelock1).

// the following two positions are used for auto-lock on exit, see code below

    (5:301) copy the value of variable %grating1 into variable %autolock1.
    (5:301) copy the value of variable %grating1 into variable %autolock2.

// [6]

    (5:355) move the position in variable %autolock1 northwest (up and left) 1 step(s).

// [7]

    (5:353) move the position in variable %autolock2 southeast (down and right) 1 step(s).

// the entry into the hallway

    (5:300) set variable %grating2.x to the value 12.
    (5:300) set variable %grating2.y to the value 20.

// [3]

    (5:40) set the floor to type %combounlockitem at (%grating2).
    (5:301) copy the value of variable %grating2 into variable %insidelock2.

// [4]

    (5:352) move the position in variable %insidelock2 northeast (up and right) 1 step(s).

/*
This ends the variable initialization with the (0:0) startup code.

Now the active part of the code
*/


/*
begin combination locking system

This permits exit of furre from combinational hallway without having to spin the tumblers or do anything special. It also has a flaw, the attempt to exit changes the floor, and by which one can allow another furre in.
*/


(0:7) When somebody moves into position (%grating2),
(1:19) and they (moved from/are standing at) position (%insidelock2),
    (5:40) set the floor to type %combounlockitem at (%grating2).

// Note: code resets the tumblers.

    (5:41) place object type %combozeronumber at (%combinationdigit1).
    (5:41) place object type %combozeronumber at (%combinationdigit2).
    (5:41) place object type %combozeronumber at (%combinationdigit3).

// Note: we don't have to clear the timer, it will self clear when it expires.


/*
Lock furre in combination hallway if main door locked.

Note: this only changes the floor type if the combolock floor is locked.
*/


(0:7) When somebody moves into position (%insidelock2),
(1:19) and they (moved from/are standing at) position (%grating2),
(1:1011) and position (%grating1) is floor type %combolockitem,
    (5:40) set the floor to type %combolockitem at (%grating2).

// Note: code resets the tumblers.

    (5:41) place object type %combozeronumber at (%combinationdigit1).
    (5:41) place object type %combozeronumber at (%combinationdigit2).
    (5:41) place object type %combozeronumber at (%combinationdigit3).
    (5:50) set countdown timer %combinationtimer to go off in %combinationcheck seconds.

/*
Spin tumblers

We catch which tumbler and it's current value by
A: ensuring that the furre is on our dialing position

B: which tumbler to spin by the direction the furre is facing.
NW = tumbler A
NE = tumbler B
SE = tumbler C
SW = combination check
Your tastes and uses may vary, change accordingly.
*/


(0:19) When somebody uses object type 0,
(1:19) and they (moved from/are standing at) position (%combinationdial),
(1:16) and the triggering furre is facing northwest (up and left),
    (5:381) set variable %combinationobject to the object type at (%combinationdigit1).
    (5:301) copy the value of variable %combinationdigit1 into variable %combinationwhich.

(0:19) When somebody uses object type 0,
(1:19) and they (moved from/are standing at) position (%combinationdial),
(1:13) and the triggering furre is facing northeast (up and right),
    (5:381) set variable %combinationobject to the object type at (%combinationdigit2).
    (5:301) copy the value of variable %combinationdigit2 into variable %combinationwhich.

(0:19) When somebody uses object type 0,
(1:19) and they (moved from/are standing at) position (%combinationdial),
(1:14) and the triggering furre is facing southeast (down and right),
    (5:381) set variable %combinationobject to the object type at (%combinationdigit3).
    (5:301) copy the value of variable %combinationdigit3 into variable %combinationwhich.

// Now we have the tumbler position, and the currect dial 'number' available

(0:19) When somebody uses object type 0,
(1:19) and they (moved from/are standing at) position (%combinationdial),
(1:201) and variable %combinationobject is greater than 0.
    (5:302) take variable %combinationobject and add 1 to it.

// Sorry, there's no easy means to roll down, keep this in mind when you build your lock.

(0:19) When somebody uses object type 0,
(1:19) and they (moved from/are standing at) position (%combinationdial),
(1:201) and variable %combinationobject is greater than %comborollover.
    (5:300) set variable %combinationobject to the value %combozeronumber.

// Oops, rolled over, reset to Zero.

// Now we have bumped the tumbler up, place it back at it's position.

(0:19) When somebody uses object type 0,
(1:19) and they (moved from/are standing at) position (%combinationdial),
(1:201) and variable %combinationobject is greater than 0.
    (5:41) place object type %combinationobject at (%combinationwhich.).
    (5:300) set variable %combinationobject to the value 0.

// Combination successfull chunk

(0:19) When somebody uses object type 0,
(1:19) and they (moved from/are standing at) position (%combinationdial),
(1:15) and the triggering furre is facing southwest (down and left),

/*
Note:
there's many means to use this chunk of the code, if you want you could encode the digits as variables, and give the means to change the combination dynamically during run time. You could hard code the code into the map itself, and use the (1:31) Additional Condition to compare with. Your choice.
*/


(1:1013) and position (%combinationdigit1) is object type 467,
(1:1013) and position (%combinationdigit2) is object type 469,
(1:1013) and position (%combinationdigit3) is object type 472,

/*
Yea! the right code was entered.

Unlock the combination door.
*/


    (5:40) set the floor to type %combounlockitem at (%grating1).

// Unlock the combination hall

    (5:40) set the floor to type %combounlockitem at (%grating2).

// Throw the switch

    (5:41) place object type %combolockoff at (%insidelock1).

// Clear the tumblers.

    (5:41) place object type %combozeronumber at (%combinationdigit1).
    (5:41) place object type %combozeronumber at (%combinationdigit2).
    (5:41) place object type %combozeronumber at (%combinationdigit3).

// Inside lock, this hard unlocks the door, permitting free passage.

(0:7) When somebody moves into position (%insidelock1),
(1:3) and they move into object type %combolockon,
    (5:40) set the floor to type %combounlockitem at (%grating1).
    (5:41) place object type %combolockoff at (%insidelock1).

// Inside lock, this locks the door.

(0:7) When somebody moves into position (%insidelock1),
(1:3) and they move into object type %combolockoff,
    (5:40) set the floor to type %combolockitem at (%grating1).
    (5:41) place object type %combolockon at (%insidelock1).

/*
Auto-Lock Exit Sequence

This permits a furre to exit the locked area with the door locked. It does this by various move checks and setting the floor accordingly.
Note:
this can also be used to allow one furre into the locked area without throwing the lock switch.

make exit grate
*/


(0:7) When somebody moves into position (%grating1),
(1:19) and they (moved from/are standing at) position (%autolock2),
(1:1011) and position (%grating1) is floor type 162,
    (5:40) set the floor to type %combounlockitem at (%grating1).

// Exited room, swap back in the locked floor

(0:7) When somebody moves into position (%autolock1),
(1:19) and they (moved from/are standing at) position (%grating1),
(1:1013) and position (%insidelock1) is object type 164,
    (5:40) set the floor to type %combolockitem at (%grating1).

// Changed mind, or allowed friend in, swap floor.

(0:7) When somebody moves into position (%autolock2),
(1:19) and they (moved from/are standing at) position (%grating1),
(1:1013) and position (%insidelock1) is object type 164,
    (5:40) set the floor to type %combolockitem at (%grating1).

/*
Sorry if I offend anyone, but this is the 'twink' test.

Twink exit check needs to be adjusted for different scans it looks for a furre in the hallway, if it finds one, it sets it's timeout again and re-executes. If it finds none, it clears the hall-lock.
Uses find furre in area routine. Not that the entire chunk is what's called a linear scanner, it runs from %insidelock2 [4] to the dialer square [1]
*/


(0:50) When countdown timer %combinationtimer goes off,
    (5:301) copy the value of variable %insidelock2 into variable %scanlockarea.

// Start off with the no-furre condition.

    (5:300) set variable %combinationfurre to the value 0.

/*
Needs adjusting for length of hallway if you lengthen the hallway. It is possible to expand to more than a hallway, but boy you get a lot of code. See my Bubbles DS for an area scanner.

Note: that the it's the exact same code for each square, because it uses variables the whole way, there's no need to check the numbers.

// square 1

(0:50) When countdown timer %combinationtimer goes off,
(1:1100) and there's a furre at (%scanlockarea),
    (5:300) set variable %combinationfurre to the value 1.

(0:50) When countdown timer %combinationtimer goes off,
    (5:352) move the position in variable %scanlockarea northeast (up and right) 1 step(s).

// square 2

(0:50) When countdown timer %combinationtimer goes off,
(1:1100) and there's a furre at (%scanlockarea),
    (5:300) set variable %combinationfurre to the value 1.

(0:50) When countdown timer %combinationtimer goes off,
    (5:352) move the position in variable %scanlockarea northeast (up and right) 1 step(s).

// square 3

(0:50) When countdown timer %combinationtimer goes off,
(1:1100) and there's a furre at (%scanlockarea),
    (5:300) set variable %combinationfurre to the value 1.

(0:50) When countdown timer %combinationtimer goes off,
    (5:352) move the position in variable %scanlockarea northeast (up and right) 1 step(s).

// square 4

(0:50) When countdown timer %combinationtimer goes off,
(1:1100) and there's a furre at (%scanlockarea),
    (5:300) set variable %combinationfurre to the value 1.

(0:50) When countdown timer %combinationtimer goes off,
    (5:352) move the position in variable %scanlockarea northeast (up and right) 1 step(s).

// square 5

(0:50) When countdown timer %combinationtimer goes off,
(1:1100) and there's a furre at (%scanlockarea),
    (5:300) set variable %combinationfurre to the value 1.

(0:50) When countdown timer %combinationtimer goes off,
    (5:352) move the position in variable %scanlockarea northeast (up and right) 1 step(s).

// square 6

(0:50) When countdown timer %combinationtimer goes off,
(1:1100) and there's a furre at (%scanlockarea),
    (5:300) set variable %combinationfurre to the value 1.

(0:50) When countdown timer %combinationtimer goes off,
    (5:352) move the position in variable %scanlockarea northeast (up and right) 1 step(s).

// square 7

(0:50) When countdown timer %combinationtimer goes off,
(1:1100) and there's a furre at (%scanlockarea),
    (5:300) set variable %combinationfurre to the value 1.

/*
You WILL have to adjust the number of squares involved in the scan, there's a means to execute this dynamically, but that's not only a different topic, it also a larger chunk of code. This is the easyest to do, just count the squares from %insidelock2 to %combinationdial you will also note that you don't need to add the (5:352) after the last check.


I've also determined that seven is the optimal distance between lock-grate floor and where the combination dials / squares are. Your tastes may vary.

Note: this is the assumed condition, this resets the combinationtimer for the next pass
*/


(0:50) When countdown timer %combinationtimer goes off,
(1:200) and variable %combinationfurre is equal to 1.
    (5:50) set countdown timer %combinationtimer to go off in %combinationcheck seconds.

// no furre present in the hallway, clear the hall lock, clear the tumblers.

(0:50) When countdown timer %combinationtimer goes off,
(1:200) and variable %combinationfurre is equal to 0.
    (5:40) set the floor to type %combounlockitem at (%grating2).
    (5:41) place object type %combozeronumber at (%combinationdigit1).
    (5:41) place object type %combozeronumber at (%combinationdigit2).
    (5:41) place object type %combozeronumber at (%combinationdigit3).

/*
End combination locking system this is a complex chunk of code which makes serious use of variables, if you have any questions about it or the complex use of variables, I'm mostly in the Dream Makers Guild's dream.


P.S. It's possible to expand the code to handle more than one locked area, either along the same hall, or elsewhere in the map, so that different combinations open different areas.

P.P.S. leaving this debugging code section in here
*/


(0:31) When a furre says {see positions},
    (5:200) emit message {combinationdial %combinationdial.x %combinationdial.y } to whoever set off the trigger.
    (5:200) emit message {combinationdigit1 %combinationdigit1.x %combinationdigit1.y } to whoever set off the trigger.
    (5:200) emit message {combinationdigit2 %combinationdigit2.x %combinationdigit2.y } to whoever set off the trigger.
    (5:200) emit message {combinationdigit3 %combinationdigit3.x %combinationdigit3.y } to whoever set off the trigger.
    (5:200) emit message {grating1 %grating1.x %grating1.y } to whoever set off the trigger.
    (5:200) emit message {insidelock1 %insidelock1.x %insidelock1.y } to whoever set off the trigger.
    (5:200) emit message {autolock1 %autolock1.x %autolock1.y } to whoever set off the trigger.
    (5:200) emit message {autolock2 %autolock2.x %autolock2.y } to whoever set off the trigger.
    (5:200) emit message {grating2 %grating2.x %grating2.y } to whoever set off the trigger.
    (5:200) emit message {insidelock2 %insidelock2.x %insidelock2.y } to whoever set off the trigger.

*Endtriggers* 8888 *Endtriggers*

Generated by DragonSpeak Editor, . 27 2003, 10:04