Setting up Doors

From Off Grid Wiki
Revision as of 12:30, 30 June 2017 by Dominic (talk | contribs)
Jump to navigation Jump to search

Template:OffGridDocStart

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 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:

devices = {
		laptop = {
			internalName = "laptop",
			script = "Scripts/Devices/laptop.lua",
		},
	},

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.

device = {
		canAccess = function()
		 return true
		end,
		gui = {
			type = "ncurses",
			updateEveryFrame = false,
			header = [[Office door system]],
			backgroundColour = {0.0, 0.0196, 0.7765},
			highlightColour = {0.8863, 0.0, 0.0627},
			buttons = {
					{
					name = "user",
					subButtons = {
						{
							name = "admin",
						},
						{
							name = "internship at security department.doc",
						},
					},
				},
				{
					name = "access_data",
					subButtons = {
			  {
							name = "admin_door_access.pgp",
						},
					},
				},
			}
		}
	}

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.

{
		name = "access_data",
		subButtons = {
			{
				name = "admin_door_access.pgp",
				onClick = function()
					print("clicked")
				end,
			},
		},
	},

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.

{
		name = "access_data",
		subButtons = {
			{
				name = "admin_door_access.pgp",
				onClick = function()
					RunMissionCommand([[Doors.AssignKeyToCharacter("adminkey", mission.characters.joe)]])
				end,
			},
		},
	},

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.


changing opening face direction