Hi!
I've found a number combination lock script
which opens a door at a correct digit combination typed in.
The typing is done through a "lock prim" with a digit texture.
A light is turned on simultaneously as a signal.
(Here's the video:
https://www.youtube.com/watch?v=ZH8TVzMzr08 )
(You can get the digit number texture here:
https://plus.google.com/104510377241048360983/posts/TFb5m9ncj3E )
Unfortunately, the given script only allows for
two digits.
I would like to have more digits, let's say five all in all.According to the author, it is relatively easy.
(He didn't tell me how to do it, though.)
Could you maybe help me out?
Thanks in advance!
The script consists of 3 parts:
1. The actual lock script
2. The script that goes into the opening door prim
3. The script that goes into the signal light prim1. The script that goes into the lock prim:---------------------------------------------------------------------------------------------------------------
// Script starts here
//User Configuration Start.......//
list secret_number =[1,2];// write your secret digits here using comma
float unlocked_time = 5;// how long it will be unlocked in case anyone breaks the code
integer communication_channel = -5468752;// in case you want to use it as a remote lock.
Use a random negative channel here
string lock_phrase = "This is locked now!";// write whatever you like
string unlock_phrase = "You have unlocked this!";// write whatever you like
// User Configuration End.......//
list digits;
integer d1;
integer d2;
integer secret_digit_one;
integer secret_digit_two;
float start = -0.45;
integer ut;
set_digit(integer face, float offset) {
llSetLinkPrimitiveParamsFast( LINK_THIS,[PRIM_TEXTURE, face,
llGetInventoryName(INVENTORY_TEXTURE,0),<0.125,1.0,0>,<offset,0,0>,0 ]);
}
lock_setup() {
llSetText(lock_phrase,<1,1,0>,1.0);
llSetObjectDesc(lock_phrase);
llRegionSay(communication_channel,lock_phrase);// for remote listen event
llMessageLinked(LINK_SET, 1, lock_phrase,"");// for linked object
llSetPrimitiveParams([PRIM_TYPE,PRIM_TYPE_BOX,PRIM_HOLE_DEFAULT,<0.125, .625, 0.0>,0.0,<0.0, 0.0, 0.0>,<1.0, 1.0, 0.0>,<0.0, 0.0, 0.0>,
PRIM_SIZE,<0.15, 1.0, 0.5>, PRIM_COLOR,-1,<0,0,0>,1.0, PRIM_GLOW,-1,0.1
]);
llSetLinkPrimitiveParamsFast( LINK_THIS,[PRIM_TEXTURE, 5,
llGetInventoryName(INVENTORY_TEXTURE,0),<0.125,1.0,0>,<start,0,0>,
0, PRIM_COLOR, 5, <1,1,1>, 1.0 ]);
llSetLinkPrimitiveParamsFast( LINK_THIS,[PRIM_TEXTURE, 6,
llGetInventoryName(INVENTORY_TEXTURE,0),<0.125,1.0,0>,<start,0,0>,
0, PRIM_COLOR, 6, <1,1,1>, 1.0 ]);
}
default
{
state_entry()
{
integer column = 10;
float tileX = 1.0/column;
digits = [
0, start,
1, start+tileX,
2, start+tileX * 2,
3, start+tileX * 3,
4, start+tileX * 4,
5, start+tileX * 5,
6, start+tileX * 6,
7, start+tileX * 7,
8, start+tileX * 8,
9, start+tileX * 9
] ;
lock_setup();
state locked;
}
}
state locked
{
touch_end(integer t)
{
if( llDetectedTouchFace(0) == 6)
{
d1++;
float offset = llList2Float(digits,d1++ );
secret_digit_one = (d1/2-1);
if( d1 >= llGetListLength(digits)) d1 = 0;
set_digit(6, offset);
}
else if( llDetectedTouchFace(0) == 5)
{
d2++;
float offset = llList2Float(digits,d2++ );
secret_digit_two = (d2/2-1);
if( d2 >= llGetListLength(digits)) d2 = 0;
set_digit(5, offset);
}
if( secret_digit_one == llList2Integer(secret_number,0) && secret_digit_two == llList2Integer(secret_number,1) )
{
d1 = 0; d2 = 0; secret_digit_one = 0; secret_digit_two = 0;
llSay(0,unlock_phrase);
llSetObjectDesc(unlock_phrase);
llSetText(unlock_phrase,<1,0,0>,1.0);
llRegionSay(communication_channel,unlock_phrase);// for remote listen event
llMessageLinked(LINK_SET, 0, unlock_phrase,"");// for linked object
llSetColor(<0,0,0>,-1);
state unlocked;
}
else return;
}
}
state unlocked
{
state_entry()
{
llSetTimerEvent( 1.0);
}
timer()
{
ut++;
if( ut> unlocked_time)
{
ut=0;
llSetTimerEvent(0);// just a double check for opensim only, not needed in SL
state default;
}
}
}
// Script ends here
---------------------------------------------------------------------------------------------------------------
2. The script that goes into the door prim:---------------------------------------------------------------------------------------------------------------
// Door Script starts here
integer t;
default
{ link_message( integer sender, integer num , string m, key k)
{ if( "You have unlocked this!" == m)
{ for(t=15; t != -1; t--)
{ rotation rot = llAxisAngle2Rot(<0,0,1>,(TWO_PI/60)*t);
llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROT_LOCAL,rot]);
llSleep(0.05); }
}
else if ("This is locked now!" == m)
{ for(t=0;t<=15;++t)
{ rotation rot = llAxisAngle2Rot(<0,0,1>,(TWO_PI/60)*t);
llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROT_LOCAL,rot]);
llSleep(0.05); }
}
}
}
// Door Script ends here
---------------------------------------------------------------------------------------------------------------
3. The script that goes into the light prim:---------------------------------------------------------------------------------------------------------------
// Light Script starts here
float glow;
default {
state_entry() {
llListen( -5468752,"","",""); }
listen(integer c, string n, key k, string m)
{ if( "You have unlocked this!" == m)
{ glow = 2.0; }
else if ("This is locked now!" == m)
{ glow = 0.0; }
llSetLinkPrimitiveParamsFast( LINK_THIS,[PRIM_GLOW,-1, glow]);
}
}
// Light Script ends here