From Off Grid Wiki
Jump to: navigation, search

How to write up a crypto chat conversation

The in game conversations through cryptochat are an important way to deliver narrative context, tutorialisation of tools and mechanics, or telegraphing the goals and objectives you might need to, to a player playing your level.

To start building your own conversations you only need to know the locations of two lua scripts,

our old friend the 'Mission Script' which as a reminder sits in Assets\StreamingAssets\Levels\*YourLevelName*\Scripts

and then a new script, or actually scripts, you see each conversation is its own lua script found in Assets\StreamingAssets\Levels\NewsPaperOffice\Conversations

Create a new file for your new conversation and give it a name, it can be anything, it is only used a reference for starting the conversation, tieing the name to an objective or event can make it easier to keep in your head when and where the conversation will be called while editing them. The example we are using here is **testConversation.lua**

The file path for the conversations lua files

Conversations can be triggered in many different ways but the most basic example is by a trigger volume such as a mission object.

Set up a trigger volume

Create a game object and give it a name, in this example "MissionObject_1_1"

Give it a mission object component, set the drop down to trigger

Make sure the game object has a box collider, and tick the isTrigger box.

In the mission script, create the trigger

1 -- [[ Mission triggers & interactions]] --
3 MissionObjects["MissionObject_1_1"].OnTriggerEnter = function(name)
4 	if name == Player.GetName() then
5 		Mission.StartObjective(mission.objectives.enterbuilding)
6 	end
7 end

This will fire off the objective on player entry.

Create the objective

Here we create the 'enterbuilding' (or objective name of your choosing) objective.

 1 -- Mission objectives:
 2 	objectives = {
 3 	--[[ Find way into the building ]]--
 4 		enterbuilding = {
 5 			name = "theapostle_obj_enterbuilding_name",
 6 			description = "theapostle_obj_enterbuilding_desc",
 7 			hints = {
 8 				"theapostle_obj_enterbuilding_hint_1",
 9 				"theapostle_obj_enterbuilding_hint_2",
10 			},
11 			messages = {
12 				"theapostle_obj_enterbuilding_msg_1",
13 			},
14 			onStart = function()
15 				print("Started objective 'enterbuilding'")
16 				**Conversation.StartScript("testConversation")**
17 			end,
18 			onCompleted = function()
19 				print("Completed objective 'enterbuilding'")
20 			end,
21 		},

The operative part of the objective here is obviously the moment where we call **Conversation.StartScript("testConversation")** and so now we have all the constituent parts.

Creating the actual conversation

You have already created your conversation script (the example being 'testConversation.lua' that you created at the start of this example) open up this file and then we are ready to get down to the creative bit.

Our example conversation looks like this:

 1 anger = 0
 2 sendData = true
 3 encrypted = true
 4 singleMessage = false
 6 characters = {
 7 	"Joe",
 8 	"Smedley",
 9 	"Terrence",
10 	-- "HW",
11 }
13 begin = function()
14 	Send( {"Smedley", "Joe..."} )
15 	Send( {"Smedley", "you there yet?"} )
16 	SendResponse( {"yes"} )
17 	Send( {"Smedley", "Ok this is Terrence, the newspaper editor I told you about"})
18 	Send( {"Terrence", --[["theapostle_obj_enterbuilding_msg_1"]] 
19 	"Thanks for turning up, I know this was a strange request. Firstly you're going to need to find a way into the buildings server room in the basement"})
20 	Send( {"Smedley", 
21 		function() 
22 			return "Yeah, follow my cues and we'll work that out, something like " .. tostring(math.random(1, 40)) .. " young people have been vanished without a trace in the last " .. tostring(math.random(1,4)) .." months."
23 			end } )
24 	-- Send( {"HW", "Oh, it's you."} )
25 	SendResponse( { "Yes but what the hell am I doing here?!", rude }, { "But why a newspaper office?", ignore } )
26 end
28 rude = function ()
29 	anger = anger+1
30 	Send( {"Smedley", "Keep calm, we have alot to get through"} )
31 	continue()
32 end
34 ignore = function ()
35 	anger = anger-1
36 	Send( {"Terrence", "Apologies for being cryptic, I promise all will be revealed"} )
37 	continue()
38 end
40 continue = function()
41 	End()
42 end

There is quite a lot of power behind the conversations system, it's open to being made in the sprawling, branching mess you have always dreamed of creating, or purely an interactive way of tailoring the humour of the player, with a few witty conversational choises and apt trite responses.

Not only this but you can run functions within conversations to either draw from variables or use mathematical operators, to create complex reactions that draw on 'memory' of previous events in the game.

The conversations themselves can run generate or add to variables, giving the ability to track elements of the conversation and use it to influence events later in the game for instance unlocking a mission by selecting a particular conversation path could be done by having certain choices add increment a variable with each correct selection. That variable reaching the correct value would then unlock the level.

More subtly perhaps this functionality could be used to track the players temperament by choices and give varied reactions from different characters dependent on how the player chooses to talk to them.

Call back functions

It's also possible to get interesitng things to happen once a conversation has ended

1     Conversation.StartScript("path/to/conversation", callbackFunc)
3     function callbackFunc() { makeModal() }

an example would be:


Single messages

If you need want to just send a single message from a character to player, without pausing the game for a full-on conversation, you can do that by setting the singleMessage variable in the conversation to true.

1 sendData = true
2 encrypted = true
3 singleMessage = true
5 ...

Other than that, the script works exactly like normal conversations. However keep in mind that the UI is built for reasonably short single messages only, any buttons for player responses etc will not be displayed at all, and the single message window closes automatically after a while. But most importantly, because the game doesn't pause for the message and there's no guarantee the player pays any attention to it, or notices it soon enough to read it fully, single messages should never be used for any important things. If there's something you need the player to be aware of, use normal conversation instead (or a modal popup).

If the singleMessage option is not included in the script, the game defaults to normal conversation.