Setting up Doors

From Off Grid Wiki
Jump to: navigation, search

Adding the door into your scene

Firstly you need to add the door prefab to your level and position it as you'd like it to appear in-game. To do this in your Project Folder you need to navigate to the Doors folder (see below) and choose the prefab which you prefer by dragging it into your Scene. For this tutorial we'll use a Swinging Door with Scanners so that once set up properly, it will require a correct ID Card to open. Once you have placed and positioned the door in a doorway you will be able to see it in-game and it should open if you used a door prefab - you will know if you have used the correct prefab because when in the Inspector view if you click on your door, it should already have an Animator and Door Script component.

The folder that contains the door prefabs

Getting access to a locked door by using hackable objects

If you wanted your door to be locked when you begin playing your level, click on your door and in the Inspector view under Door (Script) tick the box next to IsLocked. Now when you load into your level your player will not be able to open the door unless they have key access to the Zone Default.

Next you will want to set the Zone of the door to something unique, for now we'll call it "admin".

Here you can change the Zone of the door, and whether it is locked or open upon starting your level in-game

Now we will want to create a hackable object (link?) in both our scene and our mission script. Once you have set up and connected the hackable object to a network, as well as connecting the door to the network we can now edit the hackable object's script to give us access to a specific Zone that a door is using.

In this guide, 'adminkey' will be the key that is related to the Zone 'admin' to make sure this has been set up check your mission script has this line of code: Doors.SetZoneKeys("admin", {"adminkey"}). By default the player will not have access the key "adminkey" unless we give it to the player straight away in SetupMission(). However we don't want the key to be given to the player, we want the player to gain access to the key by having to hack into a device.

We will use the same variable and file names as the Mission Scripting tutorial. This will include the following:

66 	devices = {
67 		laptop = {
68 			internalName = "laptop",
69 			script = "Scripts/Devices/laptop.lua",
70 		},
71 	},

Our device will be in the table laptop, and the script for the device will be found in laptop.lua. It will be assumed that the hackable device has been added to SetupMission(), check the Mission Scripting tutorial if you need help on this.

In the laptop.lua file we will have the following code.

 1 	device = {
 2 		canAccess = function()
 3 		 return true
 4 		end,
 5 		gui = {
 6 			type = "ncurses",
 7 			updateEveryFrame = false,
 8 			header = [[Office door system]],
 9 			backgroundColour = {0.0, 0.0196, 0.7765},
10 			highlightColour = {0.8863, 0.0, 0.0627},
11 			buttons = {
12 					{
13 					name = "user",
14 					subButtons = {
15 						{
16 							name = "admin",
17 						},
18 						{
19 							name = "internship at security department.doc",
20 						},
21 					},
22 				},
23 				{
24 					name = "access_data",
25 					subButtons = {
26 			  {
27 							name = "admin_door_access.pgp",
28 						},
29 					},
30 				},
31 			}
32 		}
33 	}

At this point the device will be hackable though the player will not be able to actually trigger anything from hacking into the device. To do this you will want to add this below a sub-button, we'll put it below the "admin_door_access.pgp" sub-button.

12 	{
13 		name = "access_data",
14 		subButtons = {
15 			{
16 				name = "admin_door_access.pgp",
17 				onClick = function()
18 					print("clicked")
19 				end,
20 			},
21 		},
22 	},

Finally we want it so that when the "admin_door_access.pgp" is clicked, the player gets access to the key "adminkey", which has been set up to open doors of the Zone "admin" - essentially meaning that the player will be then be able to open and close the door we have created. To do this we just add a small line of code inside the function as shown below.

12 	{
13 		name = "access_data",
14 		subButtons = {
15 			{
16 				name = "admin_door_access.pgp",
17 				onClick = function()
18 					RunMissionCommand([[Doors.AssignKeyToCharacter("adminkey", mission.characters.joe)]])
19 				end,
20 			},
21 		},
22 	},

This is assigning the key "adminkey" to the character joe which if you remember is the player: you! So now if you try and interact with your door which is of the Zone "admin", it will unlock and open like in the GIF below!

(Click to see) The door opening as seen in-game

Changing the opening animation direction

If for example you are in a narrow corridor and you want to open a door, it would be convenient for the door to open outwards away from you, otherwise the door will push towards and into you, disrupting your movement and potentially your vision ahead.

To change the direction of which the door opens is quite simple, though the procedure slightly differs between doors with and without keycard scanners.

For doors without keycard scanners

Firstly you need to click on the handle of your door - make sure you are selecting the handle which is the one that the player will be interacting with to open the door. Then under the 'Mission Object (Script)' click on the tickbox underneath the 'On Interaction Start' (see below), it may or may not be ticked already, either way reversing its current status will reverse the opening direction. If the player might interact with the door again, you should ideally do the exact same to the handle on the other side of the door.

The red circle shows the tickbox that you should click to reverse the opening direction of the door when interacting with that handle

For doors with keycard scanners

Likewise to doors without keycard scanners, it is just a matter of ticking or unticking a tickbox, however this time we are selecting the actual keycard scanner and not the handle. If the door currently opens inwards towards the player, select the keycard scanner which the player is interacting with and you should see components in the Inspector view similar to the ones seen in the picture below. All you do now is click on the tickbox for 'Is Front' (circled in red below), so if the tickbox was ticked, you just need to untick it, and vice versa for if it was unticked.

The red circle shows the tickbox that you should click to reverse the opening direction of the door when interacting with that keycard scanner