door access code

Posted By: DuaneDawson

door access code - 10/27/13 23:04

Code:
//////////////////////////////////////////////////////////////////////////////////
// copy the files from this folder inside your \work folder
// don't forget to include access.wdl
// place dialsmall.pcx in your level and attach it the "dial_small" action
// place a door in your level and attach it the "new_door" action 
//////////////////////////////////////////////////////////////////////////////////

BMAP* dialpad_pcx = "dialpad.pcx";

BMAP* one_pcx = "one.pcx";
BMAP* two_pcx = "two.pcx";
BMAP* three_pcx = "three.pcx";
BMAP* four_pcx = "four.pcx";
BMAP* five_pcx = "five.pcx";
BMAP* six_pcx = "six.pcx";
BMAP* seven_pcx = "seven.pcx";
BMAP* eight_pcx = "eight.pcx";
BMAP* nine_pcx = "nine.pcx";
BMAP* zero_pcx = "zero.pcx";
BMAP* asterisk_pcx = "asterisk.pcx";

///////////////////////////////////////////////////////////////////////////////////

var number_of_digits;

///////////////////////////////////////////////////////////////////////////////////

STRING* password_str = "1234";
STRING* guess_str = "";

///////////////////////////////////////////////////////////////////////////////////

ENTITY* locked_door;

///////////////////////////////////////////////////////////////////////////////////

SOUND* dial_wav = "dial.wav";
SOUND* error_wav = "error.wav";
SOUND* success_wav = "success.wav";

///////////////////////////////////////////////////////////////////////////////////

function check_code(button);
function show_dialpad();
function compare_strings();

///////////////////////////////////////////////////////////////////////////////////

PANEL* dialpad_pan =
{
	bmap = dialpad_pcx;
	pos_x = 0;
	pos_y = 0;
	layer = 10;

	button = 143, 8, one_pcx, one_pcx, one_pcx, check_code, null, null; 
	button = 270, 8, two_pcx, two_pcx, two_pcx, check_code, null, null; 
	button = 398, 8, three_pcx, three_pcx, three_pcx, check_code, null, null; 
	button = 143, 128, four_pcx, four_pcx, four_pcx, check_code, null, null; 
	button = 272, 128, five_pcx, five_pcx, five_pcx, check_code, null, null; 
	button = 397, 129, six_pcx, six_pcx, six_pcx, check_code, null, null; 
	button = 144, 248, seven_pcx, seven_pcx, seven_pcx, check_code, null, null; 
	button = 273, 249, eight_pcx, eight_pcx, eight_pcx, check_code, null, null; 
	button = 397, 250, nine_pcx, nine_pcx, nine_pcx, check_code, null, null; 
	button = 146, 368, zero_pcx, zero_pcx, zero_pcx, check_code, null, null; 
	button = 272, 370, asterisk_pcx, asterisk_pcx, asterisk_pcx, check_code, null, null; 

	flags = OVERLAY;
}

////////////////////////////////////////////////////////////////////////////////////

action dial_small()
{
	my.ambient = -40;

	set(my,PASSABLE); 
   my.emask |= ENABLE_CLICK; // lite-C
  

	my.event = show_dialpad;
}

action cells_access_door()
{
	locked_door = me;
}

function check_code(button)
{
	number_of_digits += 1;
	snd_play (dial_wav, 30, 0);
	if (button == 1) 
	{
		str_cat (guess_str, "1");
	}
	if (button == 2) 
	{
		str_cat (guess_str, "2");
	}
	if (button == 3) 
	{
		str_cat (guess_str, "3");
	}
	if (button == 4) 
	{
		str_cat (guess_str, "4");
	}
	if (button == 5) 
	{
		str_cat (guess_str, "5");
	}
	if (button == 6) 
	{
		str_cat (guess_str, "6");
	}
	if (button == 7) 
	{
		str_cat (guess_str, "7");
	}
	if (button == 8) 
	{
		str_cat (guess_str, "8");
	}
	if (button == 9) 
	{
		str_cat (guess_str, "9");
	}
	if (button == 10) 
	{
		str_cat (guess_str, "0");
	}
	if ((button == 11) | (number_of_digits > 4)) 
	{
		while (mouse_left == 1) {wait (1);
		}
		wait (0.5);
		snd_play (error_wav, 70, 0);
		reset(dialpad_pan,SHOW);
	}


	while (1)
	{
		if (str_cmp (password_str, guess_str) == 1) // pass ok?
		{
			snd_play (success_wav, 20, 0);
			reset(dialpad_pan,SHOW);
			while (locked_door.pan > -0) // unlock the door!
			{	
				c_rotate(locked_door, vector(-4 * time_step, 0, 0), IGNORE_WORLD);
				wait (1);
			}
			c_rotate(locked_door, vector(-4 * time_step, 0, 0), IGNORE_WORLD);
			break; // get out of the while loop
		}
		wait (1);
	}
}

function show_dialpad()
{
	number_of_digits = 0;
	str_cpy (guess_str, ""); // reset the string
   set(dialpad_pan,SHOW);
}

Posted By: 3run

Re: door access code - 10/27/13 23:16

Ehm.. Any words about it man? Resources?
Posted By: NeoNeper

Re: door access code - 10/29/13 16:35

what is the question?
Posted By: Feindbild

Re: door access code - 10/30/13 07:48

No question, since this was posted in "contributions".
Posted By: CanadianDavid

Re: door access code - 10/30/13 08:40

What 3run is really asking is for a description for this script. Also, it's almost useless since we don't have the extra assets. Though from a quick glance the code seems simple enough.
© 2024 lite-C Forums