Modme Forums

[Tutorial] Add Timed Doors

Game Modding | Call of Duty: Black Ops 3 | Scripting


ModmeBot:

Thread By: CT8918

This script allows you to implement doors into your map that will open, then close after a period of time. Can be bought several times.


The script has been generalized and can be expanded upon. Some of the methods within the script may be good for other things as well.


Script requested by: DaNk Heater



Test Footage:



Guide:




Instructions:


1. Create a door of any model (for rotating make sure it hinges/ has an origin). Give targetname "door_1" or whatever.


2. Create a brushmodel clip surrounding the door model. Give targetname "door_1_clip" or whatever


3. Create a use trigger surrounding the door model on both sides. Give targetname "door_1_trig" or whatever



Add the following code into your maps .gsc file. C:\Program Files (x86)\Steam\steamapps\common\Call of Duty Black Ops III\usermaps\your_map\scripts\zm\your_map.gsc



Call the function in main or wherever you need it. Replace the variables accordingly.


level thread timed_door("door_name", "door_trig", "door_clip", "rotate_or_slide", amount, rotate_or_slide_time, delay_time, door_cost);





Examples:



level thread timed_door("door_1", "door_1_trig", "door_1_clip", "yaw", -160, 1, 10, 1000); //rotate as if opening. rotate z
	level thread timed_door("door_2", "door_2_trig", "door_2_clip", "roll", 90, 1, 10, 2000); //rotate x.
	level thread timed_door("door_3", "door_3_trig", "door_3_clip", "pitch", 90, 1, 10, 3000); //rotate y.
	
	level thread timed_door("door_4", "door_4_trig", "door_4_clip", "x", -55.25, 2, 10, 4000); //slide door on x axis only.
	level thread timed_door("door_5", "door_5_trig", "door_5_clip", "y", -55.25, 2, 10, 5000); //slide door on y axis only.
	level thread timed_door("door_6", "door_6_trig", "door_6_clip", "z", 100, 2, 10, 6000); //slide door on z axis only.



Add the function in yourmap's .gsc:


/*
FUNCTION: timed_door 
Author: CT8918
Date: 3/10/2017
Current Project: Mortuus_Arena
Function to open a door for a set amount of time, then close the door. Door can be reused.
door_name - a string containing the name of the door being targeted.
door_trig - a string containing the name of the trigger associated with the door.
door_clip - a string containing the name of the trigger associated with the door.
rotate_or_slide - a string designating which method to use.
		"yaw" = rotate around y ; "roll" = rotate around x ; "pitch" = rotate around y ; "x" = move along x ; "y" = move along y; "z" = move along z;
amount - a double (number) telling the door how much to rotate (-360 to 360) or move (in units).
rotate_or_slide_time - a double for the time it takes for the door to move.
delay_time - a double for the time between the opening of the door, and the closing of the door.
door_cost - an integer value (make number%10 - ex: 1010) for how many points will be deducted from player.
*/ 
function timed_door(door_name, door_trig, door_clip, rotate_or_slide, amount, rotate_or_slide_time, delay_time, door_cost)
{
	door = GetEnt(door_name, "targetname"); // Gets the entity with the targetname.
	door_clip = GetEnt(door_clip, "targetname"); // Gets the entity with the targetname.
	door_trig = GetEnt(door_trig, "targetname"); // Gets the entity with the targetname.
	door_trig SetHintString("Press ^3[{+activate}] ^7to open door. [Cost: " + door_cost + "]");
	door_trig SetCursorHint("HINT_NOICON"); // Changes the icon that shows when looking at the trigger.
	
	open_delay = rotate_or_slide_time*(0.25); //Prevents player from running through door model.
	close_delay = rotate_or_slide_time*(0.75); //Prevents player from running through door model.
	accelerate = rotate_or_slide_time*(0.20); //The acceleration and decceleration of door. Makes it door-like.
	
	//delay_time = (delay_time - open_delay - close_delay);//If you want the whole process to be exactly 10 seconds. 
	
	while(1){
		while(1)
        {
            door_trig waittill("trigger", player);

			//Makes sure player has enough points.
            if(player.score >= door_cost)
            {
                player.score -= (door_cost); 
				
				door_trig hide();

				//z rotate (door-like)
				if (rotate_or_slide == "yaw")
				{
					door rotateYaw(amount, rotate_or_slide_time);
					wait(open_delay); //Prevents run through door model.
					door_clip hide();
				}
				//x rotate
				if (rotate_or_slide == "roll")
				{
					door rotateRoll(amount, rotate_or_slide_time);
					wait(open_delay); //Prevents run through door model.
					door_clip hide();
				}
				//y rotate
				if (rotate_or_slide == "pitch")
				{
					door rotatePitch(amount, rotate_or_slide_time);
					wait(open_delay); //Prevents run through door model.
					door_clip hide();
				}
				if (rotate_or_slide == "x")
				{
					door movex(amount, rotate_or_slide_time, accelerate, accelerate);
					door_clip movex(amount, rotate_or_slide_time, accelerate, accelerate);
				}
				if (rotate_or_slide == "y")
				{
					door movey(amount, rotate_or_slide_time, accelerate, accelerate);
					door_clip movey(amount, rotate_or_slide_time, accelerate, accelerate);
				}
				if (rotate_or_slide == "z")
				{
					door movez(amount, rotate_or_slide_time, accelerate, accelerate);
					door_clip movez(amount, rotate_or_slide_time, accelerate, accelerate);
				}
				
				wait(delay_time);
				 
				//Moves the door back to initial position.
				//y rotate
				if (rotate_or_slide == "yaw")
				{
					door rotateYaw(amount*(-1), rotate_or_slide_time);
					wait(close_delay); //Prevents run through door model.
					door_clip show();
				}
				//x rotate
				if (rotate_or_slide == "roll")
				{
					door rotateRoll(amount*(-1), rotate_or_slide_time);
					wait(close_delay); //Prevents run through door model.
					door_clip show();
				}
				//y rotate
				if (rotate_or_slide == "pitch")
				{
					door rotatePitch(amount*(-1), rotate_or_slide_time);
					wait(close_delay); //Prevents run through door model.
					door_clip show();
				}
				if (rotate_or_slide == "x")
				{
					door movex(amount*(-1), rotate_or_slide_time, accelerate, accelerate);
					door_clip movex(amount*(-1), rotate_or_slide_time, accelerate, accelerate);
				}
				if (rotate_or_slide == "y")
				{
					door movey(amount*(-1), rotate_or_slide_time, accelerate, accelerate);
					door_clip movey(amount*(-1), rotate_or_slide_time, accelerate, accelerate);
				}
				if (rotate_or_slide == "z")
				{
					door movez(amount*(-1), rotate_or_slide_time, accelerate, accelerate);
					door_clip movez(amount*(-1), rotate_or_slide_time, accelerate, accelerate);
				}
				
				door_trig show();
				
				break;
            }
		}
	}
}




If you have any questions or requests, feel free to message me.


ModmeBot:

Reply By: DaNk Heater

YOU ARE TRULY AMAZING THANK YOU SO MUCH!!! I WILL MAKE SURE TO LIST IN THE CREDITS OF MY MAP!! THANK YOU SO MUCH!


ModmeBot:

Reply By: DaNk Heater

Hi, one other request could you maybe do a quick tutorial with this. I'm not really the best with this kind of stuff! Thanks!


ModmeBot:

Reply By: CT8918

I'll create one here soon. Had to catch up on some work.


ModmeBot:

Reply By: CT8918
Sorry, got distracted. Here is a video trying to explain how to implement this:


ModmeBot:

Reply By: iBounce
You made this a lot more complicated than it needs to be, to be honest.

But hey, if it works, it works


ModmeBot:

Reply By: CT8918

iBounce
You made this a lot more complicated than it needs to be, to be honest. But hey, if it works, it works

I know haha. Just made it multi-purpose so people could dissect it if they want.


ModmeBot:

Reply By: idb11987
How would i make this work for timed doors on a map like five has its pap doors. So once you teleport then the doors open after 30 seconds or so and close soon after. thanks in advanced :)


ModmeBot:

Reply By: soul-toktzt

idb11987
How would i make this work for timed doors on a map like five has its pap doors. So once you teleport then the doors open after 30 seconds or so and close soon after. thanks in advanced :)

I think you have to put
wait (30);
Right below
door_trig waittill("trigger", player);


ModmeBot:

Reply By: idb11987
Thanks bro ill give it a blast ;)


ModmeBot:

Reply By: KillJoyYT
does anyone know how to edit Ct's time door script so that the buyable option wont be available on the door until the door has fully reset???

Right now you can buy the door when its on the way back

causing it to go away even further and not coming back to its origin

thanks


ModmeBot:

Reply By: Harry Bo21
after the model rotate

model waittill( "rotatedone" );


ModmeBot:

Reply By: KillJoyYT
OK so I've put the code at the bottom of the timed door script and it worked!

but now the door is only buyable once.


function timed_door(door_name, door_trig, door_clip, rotate_or_slide, amount, rotate_or_slide_time, delay_time, door_cost)
{
	door = GetEnt(door_name, "targetname"); // Gets the entity with the targetname.
	door_clip = GetEnt(door_clip, "targetname"); // Gets the entity with the targetname.
	door_trig = GetEnt(door_trig, "targetname"); // Gets the entity with the targetname.
	door_trig SetHintString("Hold &&1 At Your Own Risk");
	door_trig SetCursorHint("HINT_NOICON"); // Changes the icon that shows when looking at the trigger.
	
	open_delay = rotate_or_slide_time*(0.25); //Prevents player from running through door model.
	close_delay = rotate_or_slide_time*(0.75); //Prevents player from running through door model.
	accelerate = rotate_or_slide_time*(0.20); //The acceleration and decceleration of door. Makes it door-like.
	
	//delay_time = (delay_time - open_delay - close_delay);//If you want the whole process to be exactly 10 seconds. 
	
	while(1){
		while(1)
        {
            door_trig waittill("trigger", player);
			//Makes sure player has enough points.
            if(player.score >= door_cost)
            {
                player.score -= (door_cost); 
				
				door_trig hide();

				//z rotate (door-like)
				if (rotate_or_slide == "yaw")
				{
					door rotateYaw(amount, rotate_or_slide_time);

					wait(open_delay); //Prevents run through door model.

					door_clip hide();
				}
				//x rotate
				if (rotate_or_slide == "roll")
				{
					door rotateRoll(amount, rotate_or_slide_time);

					wait(open_delay); //Prevents run through door model.

					door_clip hide();
				}
				//y rotate
				if (rotate_or_slide == "pitch")
				{
					door rotatePitch(amount, rotate_or_slide_time);

					wait(open_delay); //Prevents run through door model.

					door_clip hide();
				}
				if (rotate_or_slide == "x")
				{
					door movex(amount, rotate_or_slide_time, accelerate, accelerate);
					door_clip movex(amount, rotate_or_slide_time, accelerate, accelerate);
				}
				if (rotate_or_slide == "y")
				{
					door movey(amount, rotate_or_slide_time, accelerate, accelerate);
					door_clip movey(amount, rotate_or_slide_time, accelerate, accelerate);
				}
				if (rotate_or_slide == "z")
				{
					door movez(amount, rotate_or_slide_time, accelerate, accelerate);
					door_clip movez(amount, rotate_or_slide_time, accelerate, accelerate);
				}
				
				wait(delay_time);
				 
				//Moves the door back to initial position.
				//y rotate
				if (rotate_or_slide == "yaw")
				{
					door rotateYaw(amount*(-1), rotate_or_slide_time);

					wait(close_delay); //Prevents run through door model.

					door_clip show();
				}
				//x rotate
				if (rotate_or_slide == "roll")
				{
					door rotateRoll(amount*(-1), rotate_or_slide_time);

					wait(close_delay); //Prevents run through door model.

					door_clip show();
				}
				//y rotate
				if (rotate_or_slide == "pitch")
				{
					door rotatePitch(amount*(-1), rotate_or_slide_time);

					wait(close_delay); //Prevents run through door model.

					door_clip show();
				}
				if (rotate_or_slide == "x")
				{
					door movex(amount*(-1), rotate_or_slide_time, accelerate, accelerate);
					door_clip movex(amount*(-1), rotate_or_slide_time, accelerate, accelerate);
				}
				if (rotate_or_slide == "y")
				{
					door movey(amount*(-1), rotate_or_slide_time, accelerate, accelerate);
					door_clip movey(amount*(-1), rotate_or_slide_time, accelerate, accelerate);
				}
				if (rotate_or_slide == "z")
				{
					door movez(amount*(-1), rotate_or_slide_time, accelerate, accelerate);
					door_clip movez(amount*(-1), rotate_or_slide_time, accelerate, accelerate);
				}
				
door_trig waittill( "rotatedone" );

				door_trig show();
				
				break;
            }
		}
	}
}



please help!


ModmeBot:

Reply By: Harry Bo21
coz of this

door_trig waittill( "rotatedone" );


the trigger isnt whats rotating...

comment that out


ModmeBot:

Reply By: KillJoyYT
Wow I'm an idiot

that makes sense.

}
				
door waittill( "rotatedone" );

				door_trig show();
				
				break;
            }
		}
	}
}

I fixed it but the trig is still for only one use.

I tried to add this as well but it didn't work


}
				
door waittill( "rotatedone" );
door_clip waittill( "rotatedone" );


				door_trig show();
				
				break;
            }
		}
	}
}


ModmeBot:

Reply By: Harry Bo21
coz i said comment it out not change it


ModmeBot:

Reply By: KillJoyYT
but you told me to add door waittill rotatedone

so that the doors trig wont be accessible until the door has fully reset.


ModmeBot:

Reply By: Harry Bo21

KillJoyYT
but you told me to add door waittill rotatedone so that the doors trig wont be accessible until the door has fully reset.

no i stated "how to wait" for a rotate to finish

he has his own code - by hardcoding the wait


ModmeBot:

Reply By: KillJoyYT
I FIGURED IT OUT

OK

right before show trig you put


door waittill( "movedone" );



thanks for the guidance man!