By Zizazat
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:
Code:
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:
Code:
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.
Code:
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.
Code:
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:
Code:
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.
If this was helpful please
vote
or leave a
review
for TBA.