A 4-digit keypad-password protected security door

Login to reply  Page: « < 1 of 1 > »
18 Jul 2010 - 19:212892
A 4-digit keypad-password protected security door
I have created a nice script that allows you to have a security door with a 4-digit keycode. The keycode is randomly generated for each player, so one person's keycode won't work for another player. The player must 'find' a piece of paper on which their own keycode is 'printed'.

First, the script to randomly generate a unique keycode for the player. This is a room entry trigger, but could be placed wherever you want the the number to be generated:
Name: 'Generate random keycode for player',  VNum: [39606], RNum: [  774]
Trigger Intended Assignment: Rooms
Trigger Type: Enter , Numeric Arg: 100, Arg list: None
Commands:
* Generate a keycode on entry to this room
if %actor.is_mortal%==1
  if %actor.varexists(keycode_396)%
    * Has keycode been removed from player?
    if %actor.keycode_396%<1000
      eval keycode_396 %random.8999%+1000
      remote keycode_396 %actor.id%
    end
  else
    eval keycode_396 %random.8999%+1000
    remote keycode_396 %actor.id%
  end
end
Secondly, the piece of paper, which has this 'examine' command trig attached to it:
Name: 'Show code on scrap of paper',  VNum: [39610], RNum: [  778]
Trigger Intended Assignment: Objects
Trigger Type: Command , Numeric Arg: 2, Arg list: exa
Commands:
if %arg%/=paper
  if %actor.varexists(keycode_396)%
    %send% %actor% The scrap of paper has a 4-digit number written on it.
    %send% %actor% The number is %actor.keycode_396%    
  else
    %send% %actor% The scrap of paper is blank.
  end
  return 1
else
  return 0
end
Thirdly, we need a trigger which resets the door as 'locked' (not physically, that is done in zedit, this just resets the variable). This should be attached to the room that the keypad/door is in.
Name: 'Reset keypad - room 39609',  VNum: [39611], RNum: [  779]
Trigger Intended Assignment: Rooms
Trigger Type: Global Zone Reset , Numeric Arg: 100, Arg list: None
Commands:
* Reset the keypad door as 'locked' on zone reset
if %dr_ul_39609%==1
  set dr_ul_39609 0
  global dr_ul_39609
end
And finally, this is the (huge) script to handle the keypad itself. Again, it needs to be in the room that the keypad is in.
Name: 'Security Keypad - Room 39609',  VNum: [39607], RNum: [  775]
Trigger Intended Assignment: Rooms
Trigger Type: Command , Numeric Arg: 100, Arg list: type
Commands:
* Unique code is generated for each player in room 39602
* First, Imms are immune
if %actor.is_imm%
  %echoaround% %actor% %actor.name% types a number into the keypad.
  if %dr_ul_39609%==1
    %send% %actor% Nothing happens - the door is already unlocked!
  else
    %send% %actor% You enter your secret over-ride code, and unlock the door.
    %echo% The keypad beeps, and you hear a click from the door.
    %door% 39609 e flags abd
    %door% 39608 w flags abd
  end
else
  * Not an Imm, so we need to check their keycode
  if %actor.varexists(keycode_396)%
    if %actor.keycode_396%>=1000
      if %arg%==%actor.keycode_396%
        if %dr_ul_39609%==1
          * Door is already unlocked!
          %send% %actor% You type %actor.keycode_396% into the keypad.
          %echoaround% %actor% %actor.name% types a number into the keypad.
          %echo% The keypad beeps, but nothing else happens.
        else
          * Door was locked, but correct number entered
          %send% %actor% You type %actor.keycode_396% into the keypad.
          %echoaround% %actor% %actor.name% types a number into the keypad.
          %echo% The keypad beeps, and you hear a click from the door.
          %at% 39608 %echo% You hear a click from the west.
          %door% 39609 e flags abd
          %door% 39608 w flags abd
          set dr_ul_39609 1
          global dr_ul_39609
        end
        * Reset wrong guesses counter
        if %actor.varexists(wrong_39609)%
          rdelete wrong_39609 %actor.id%
        end
      else
        %send% %actor% You type %arg% into the keypad.
        %echoaround% %actor% %actor.name% types a number into the keypad.
        if %actor.varexists(wrong_39609)%
          eval wrong_39609 %actor.wrong_39609%+1
          remote wrong_39609 %actor.id%
          if %actor.wrong_39609%>3
            * Too many wrong guesses - zap 'em!
            %send% %actor% A powerful jolt of electrical power envelopes you.
            %echoaround% %actor% A powerful jolt of electrical power envelopes %actor.name%.
            set hp %actor.hitp%
            if %hp%>1000
              set hp 1000
            end
            eval dam (%hp%/5)+%random.10%
            %damage% %actor% %dam%
          end
        else
          set wrong_39609 1
          remote wrong_39609 %actor.id%
          %echo% Nothing happens.
        end
      end
    else
      * Has completed the zone, and not yet received a new number
      %send% %actor% You type random numbers into the keypad.
      %echoaround% %actor% %actor.name% types a number into the keypad.
      %echo% Nothing happens.
      if %actor.varexists(wrong_39609)%
        eval wrong_39609 %actor.wrong_39609%+1
        remote wrong_39609 %actor.id%
        if %actor.wrong_39609%>3
          * Too many wrong guesses - zap 'em!
          %send% %actor% A powerful jolt of electrical power envelopes you.
          %echoaround% %actor% A powerful jolt of electrical power envelopes %actor.name%.
          set hp %actor.hitp%
          if %hp%>1000
            set hp 1000
          end
          eval dam (%hp%/5)+%random.10%
          %damage% %actor% %dam%
        end
      else
        set wrong_39609 1
        remote wrong_39609 %actor.id%
        %echo% Nothing happens.
      end
    end
  else
    * Has no keycode, so can't know a valid unlocking number
    %send% %actor% You type random numbers into the keypad.
    %echoaround% %actor% %actor.name% types a number into the keypad.
    %echo% Nothing happens.
    if %actor.varexists(wrong_39609)%
      eval wrong_39609 %actor.wrong_39609%+1
      remote wrong_39609 %actor.id%
      if %actor.wrong_39609%>3
        * Too many wrong guesses - zap 'em!
        %send% %actor% A powerful jolt of electrical power envelopes you.
        %echoaround% %actor% A powerful jolt of electrical power envelopes %actor.name%.
        set hp %actor.hitp%
        if %hp%>1000
          set hp 1000
        end
        eval dam (%hp%/5)+%random.10%
        %damage% %actor% %dam%
      end
    else
      set wrong_39609 1
      remote wrong_39609 %actor.id%
      %echo% Nothing happens.
    end
  end
end
That's it - you don't even need to make a keypad object - I just added this as an extra description in the room:
1) Keywords: keypad numeric numbers
2) Description:
 ___  ___  ___
| 1 || 2 || 3 |
 ===  ===  ===
| 4 || 5 || 6 |
 ===  ===  ===
| 7 || 8 || 9 |
 ===  ===  ===
|Can|| 0 ||Ent|
 ---  ---  ---
The keypad is a basic numerical type, with the numbers 0-9 and a Cancel and
Enter button.  The buttons are faded through use, but no buttons are more faded
than others, suggesting that the combination is changed regularly.


__________________
18 Jul 2010 - 20:252893
Very nice Jam, very very nice.


__________________
Owner/Coder/Head Admin
Caer Dubrin
18 Jul 2010 - 23:512894
:)
Quote ralgith:
Very nice Jam, very very nice.

Glad you like it!
It took several attempts to get the big keypad trig right, and every time I got it working, I thought of another improvement (like imm-override or three guesses before you get zapped), but I think this version should be virtually bug-free, and has been tested several times.
I did consider writing this as a spec-proc, but decided it would be a challenge to script it, and it's become probably the most complex script I've created. I thought other MUDs would find it useful, so shared it here and on CWG forums.


__________________
19 Jul 2010 - 00:042895
Definitely a complex and time consuming creation. I'm in the process of creating an even more complex script.. but only because this mob will have 10 different special actions it might do to players from picking them up and throwing them across the MUD, to using a tree like a giant broom to smack the whole room.


__________________
Owner/Coder/Head Admin
Caer Dubrin
Login to reply  Page: « < 1 of 1 > »