Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
0 Active | 59 Guests
Online:

LATEST FORUM THREADS

»
CoD: Battle Royale
CoD+UO Map + Mod Releases
Damaged .pk3's
CoD Mapping
heli to attack ai
CoD4 SP Mapping

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 2
Category: CoD2 Scripting
Scripting and coding with Call of Duty 2.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked
Page
Next Page
subscribe
Author Topic: coded keypad door
NotDeadYet
General Member
Since: Jan 5, 2009
Posts: 52
Last: Jul 28, 2009
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Saturday, Jan. 10, 2009 04:38 pm
I posted in the level design forum, but no one seems to have looked at it or written back. So i will post here also, because my door also requires scripts.

Problem: I have a keypad by my door that has 9 numbers on it. I would like for the players to enter a code to go through the door. I know this is possible cause i saw it on another map. (and no i cannot get if from the map). Please help me with script and triggers. :|

- NotDeadYet (P u l s e)

edited on Jan. 10, 2009 11:39 am by NotDeadYet
Share |
TheModDoctor
General Member
Since: Apr 27, 2007
Posts: 174
Last: Jan 10, 2009
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Saturday, Jan. 10, 2009 05:03 pm
Hi there, I have an idea. Sorry some of it may sound wrong because I haven't scripted for COD2 in a long while.

Make 10 trigger_use triggers (one for each button).
Lets say your code is 4839. Thread a subroutine for "4". In that subroutine code that when "4" is pressed (used), then thread a subroutine for "8". In this new one when button "8" is pressed thread one for 3 and so on... when you get to the last one, after the trigger has been activated open the door from there.

The only problem with this method is that players that doesn't know the code could "hack" your door by pressing all the buttons from 0-9 four times. But then again, you just won't tell them this is how to bypass it...[wink]

(I apologize again, I completely forgot the code statements for cod.)
Share |
TheModDoctor
General Member
Since: Apr 27, 2007
Posts: 174
Last: Jan 10, 2009
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Saturday, Jan. 10, 2009 05:21 pm
I quickly went and looked how the code goes again, so basically what I said will add up to something like this:

Code:
thread keypad();  //CODE IS 5349

keypad()
{
thread 5();
}

5()
{
b5 = getent("b5", "targetname"); //b5 is the trigger_use

b5 waittill("trigger");
thread 3();
}

3()
{
b3 = getent("b3", "targetname"); //b3 is the trigger_use

b3 waittill("trigger");
thread 4();
}

4()
{
b4 = getent("b4", "targetname"); //b4 is the trigger_use

b4 waittill("trigger");
thread 9();
}

9()
{
b9 = getent("b9", "targetname"); //b9 is the trigger_use

b9 waittill("trigger");
thread door_open();
}

door_open()
{
// the rest....

}


Dunno if it will work, but give it a try[wave]
Share |
Pedro699
General Member
Since: Jun 19, 2006
Posts: 781
Last: Dec 18, 2010
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Saturday, Jan. 10, 2009 06:47 pm
I can't resist trying to solve programming problems like this, lol ;-)

I came up with this script:

Code:
init()
{ 

   /* Max number can be 25 (set in the for loop below)
      make sure that all sequential triggers are included 
      
      key: targetname
      value: b# 

      
      where # is the number of that button. Can use trigger uses or trigger damage (you shoot the buttons instead)
      
   */
      
   // List the code here - supports any length of code - always start at zero and increase by 1 each time
   // CODE IS 5349
   
   level.doorCode[0] = 5; 
   level.doorCode[1] = 3;
   level.doorCode[2] = 4;
   level.doorCode[3] = 9;
   
   thread keypad(); 
}

keypad()
{
   nextButton = level.doorCode[0];
   
   entryPosition = 0;
   
   level.lastButton = level.doorCode[(level.doorCode.size - 1)];
     
   for(i=1; i <= 25; i++)
   {
      button = getent(("b" + i), "targetname"); // get sequential buttons
      
      if(!isdefined(button)) break; // no more triggers - exit setup
      
      button thread watchTrigger(i);
   }
   
   level.buttonPressed = undefined;
   
   while(1)
   {
      if(isDefined(level.buttonPressed))
      {
         if(level.buttonPressed == nextButton)
         {
            entryPosition++;
            if(entryPosition == (level.doorCode.size - 1)) // Code finished so when it matches reset the code and open the door
            {  
               // Do your door stuff here - not threaded so can wait there for door to close again              
               door_open(); 
               nextButton = level.doorCode[0];
               entryPosition = 0;
            }
            else
            {
               nextButton = level.doorCode[entryPosition];
            }
            level.buttonPressed = undefined;
         }
         else
         {
            nextButton = level.doorCode[0]; // button selected did not match nextButton - reset code
            level.buttonPressed = undefined;
            entryPosition = 0;
            continue;
         }     
      }     
      wait 0.05;   
   }   
}

watchTrigger(number)
{
   while(1)
   {
      self waittill("trigger");
      level.buttonPressed = number;
      wait 0.05;
   }
}

door_open()
{
// the rest....

}


This script uses the same triggers as for ModDoctor's script.

If you are thinking of the map I am then that one uses damage triggers and you shoot the buttons to enter the code. The issue with use triggers is that presumably the buttons will all be close to each other and the use radii will overlap making it hard to pick the number you want.

You can create a trigger by drawing your trigger brush out of the trigger texture (grey with 'trig' written on it - usage -> tools subset) then right clicking -> trigger -> damage.

By bringing up the entity box 'n' you can enter a key of targetname and a value of b1 then press enter.

That would create the trigger for button 1. Do the same for the second button but use b2 as the value.

The trigger texture is invisible in game so you will need to create a 'fake' keypad out of regular brushes to show the players where the buttons are.

Just as a quick note - the script above does compile but I haven't tested it with some actual triggers - so don't be surprised if it doesn't work straight away!

You can change the code by editing this section of the script:

Code:
   level.doorCode[0] = 5; 
   level.doorCode[1] = 3;
   level.doorCode[2] = 4;
   level.doorCode[3] = 9;


You could change the code to 2362 by changing that section to:
Code:
   level.doorCode[0] = 2; 
   level.doorCode[1] = 3;
   level.doorCode[2] = 6;
   level.doorCode[3] = 2;


You can create longer codes by adding lines - eg.

Code:
   level.doorCode[0] = 5; 
   level.doorCode[1] = 3;
   level.doorCode[2] = 4;
   level.doorCode[3] = 9;
   level.doorCode[4] = 3;
   level.doorCode[5] = 7;

This would be a 6 digit code - 534947

Let us know how it goes!
Share |
Pedro699
General Member
Since: Jun 19, 2006
Posts: 781
Last: Dec 18, 2010
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Saturday, Jan. 10, 2009 07:53 pm
Hmm, I think there will be a small bug in the script.

Just looking over it again I think it will stop one number early - must have been leftover from what I was trying previously.

change the line: (line 51)

if(entryPosition == (level.doorCode.size - 1))

to

if(entryPosition == level.doorCode.size)

If a moderator could update my previous post to avoid any confusion that would be good ;-)
Share |
_INSANE_
General Member
Since: Nov 7, 2008
Posts: 352
Last: Jul 10, 2011
[view latest posts]
Level 5
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Saturday, Jan. 10, 2009 08:30 pm
Maybe have something in there between the numbers in the script... Just to make sure they have the right order and everything of the right code.


THIS IS JUST AN IDEA, NOT NECESSARILY GOING TO WORK

If you DO try this.. you'll have to edit the script to fit your needs with triggers.. etc.

Example:
Password is (5439)

They push 5 .... then the next number they push needs to be 4. To do this, maybe use something like

Code:
passwordmath()
{
	password_math = 0;

	while(1)
	{
		if(password_math == 0 && *trigger 5 triggered*)
		{
			password_math = 5;
		}

		else 

		{
			player iprintlnbold("incorrect number");
			break;
		}


		if(password_math == 5 && *trigger 4 triggered*)
		{
			password_math = 9;
		}

		else 

		{
			player iprintlnbold("incorrect number");
			break;
		}
		

		if(password_math == 9 && *trigger 3 triggered*)
		{
			password_math = 12;
		}

		else 

		{
			player iprintlnbold("incorrect number");
			break;
		}


		if(password_math == 12 && *trigger 9 triggered*)
		{
			open sesame! (open door here);
                       break;
		}

		else 

		{
			player iprintlnbold("incorrect number");
			player iprintlnbold("almost had it");
			break;
		}

		wait .05;

	}

}



I don't know if it will work. Besides... Somebody always comes up with a better answer than me.. But at least i tried [casanova]

edited on Jan. 10, 2009 03:34 pm by INSANE{H|S}
Share |
NotDeadYet
General Member
Since: Jan 5, 2009
Posts: 52
Last: Jul 28, 2009
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Sunday, Jan. 11, 2009 02:16 am
Thank you all, i really like insane's idea because its written like i write C++. I can understand that, unfortunetly i have no clue how to make the trigger worthy. I am new to this. I will try the other ones though, but my ultimate goal is to have them to this to open a door. How would i finish off the scripts by saying if the code is right execute door swing or something?

heres what i have... i made the keypad, i would like to do the damage thing because i believe having them click on the buttons would be extremly difficult. The keypad has the numbers 1-9 and the enter button. I would like a random 4 digit code, (not picking, plus i think i have enough brain power to edit codes, just cant make em) that can open a door if entered correctly.

buttons are number b1,b2---b9, and b10 (for enter)

edited on Jan. 10, 2009 09:19 pm by NotDeadYet

edited on Jan. 10, 2009 09:22 pm by NotDeadYet
Share |
coywhite
General Member
Since: Jul 27, 2008
Posts: 24
Last: Mar 11, 2010
[view latest posts]
Level 1
Category: CoD2 Scripting
Posted: Sunday, Jan. 11, 2009 05:00 am
hi, use this code.. i had it in a old map i made yrs ago.. =D

Code:
key1() 
{ 
object_1 = getent("1","targetname"); 
    
something = 0; 

while (something < 10) 
{ 
object_1 waittill ("damage", iDamage); 
   { 
   something = something + iDamage; 
   } 
}   
thread key2(); 
}       

key2() 
{ 
object_3 = getent("4","targetname"); 
    
something = 0; 

while (something < 10) 
{ 
object_3 waittill ("damage", iDamage); 
   { 
   something = something + iDamage; 
   } 
} 
thread key3(); 
}       

key3() 
{ 
object_3 = getent("2","targetname"); 
    
something = 0; 

while (something < 10) 
{ 
object_3 waittill ("damage", iDamage); 
   { 
   something = something + iDamage; 
   } 
} 
thread key4(); 
}       

key4() 
{ 
object_3 = getent("3","targetname"); 
object_4 = getent ("door","targetname"); 
    
something = 0; 

while (something < 10) 
{ 
object_3 waittill ("damage", iDamage); 
   { 
   something = something + iDamage; 
   } 
} 
///******************Here is door movement, edit to suite your needs.
object_4 rotateto ((0, 90,0), 1);
wait 3;
object_4 rotateto ((0, 0,0), 1.7);
wait 1;
thread key1(); 
}    


Reply with any questions.
Share |
Pedro699
General Member
Since: Jun 19, 2006
Posts: 781
Last: Dec 18, 2010
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Sunday, Jan. 11, 2009 02:04 pm
Knocked up a quick sample map with a working keypad:

www.codbrothers.co.uk/misc/mp_keypad.zip

The code resets with this script if you hit the wrong button.

All required source files included.

================

The issue with Insane's script is that it will not keep looping. The chances of the trigger being fired right at the start are virtually zero so the script sees else -> break. This exits the loop and ends the script. Changing break to continue would cause the loop to skip rest of contents and restart, which is perhaps better.

However, having changed the breaks to continues would now cause the code to get stuck at the first number.

password_math starts at 0. when trig 5 is activated it will set password_math to 5. Trigger 4 will not be active so the script enters the else part and restarts the loop. As password_math is now 5 the first if statement is always going to be false so it will just keep skipping the rest of the loops contents.

Scripting in CoD is effectively c++, but is pretty much all based on loops of one kind or another. Unlike most programs you might write yourself, CoD scripts are usually designed to run multiple times, if not forever - so it can take a while to get used to techniques that work in the game along with the multitude of game limitations!

Good luck!





edited on Jan. 11, 2009 09:36 am by Pedro699
Share |
NotDeadYet
General Member
Since: Jan 5, 2009
Posts: 52
Last: Jul 28, 2009
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Sunday, Jan. 11, 2009 06:42 pm
thanks i will try coywhite's first, because at the moment your link does not work pedro. thanks for the help, i will post back on what worked.

P.S. would i make my door a brushmodel???

edited on Jan. 11, 2009 01:50 pm by NotDeadYet

UPDATE:

Script compile error when i used coywhite's. all i did was save it as mp_treehouse3_keypad.gsc. then in the mp_treehouse.gsc i called it like this maps\mp\mp_treehouse3_keypad::main();

edited on Jan. 11, 2009 02:00 pm by NotDeadYet
Share |
Restricted Access Topic is Locked
Page
Next Page
subscribe
MODSonline.com Forums : Call of Duty 2 : CoD2 Scripting

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»