Take On Mars

Take On Mars

Not enough ratings
Scenario creating III: Displaying messages to the player
By dariusz1983
Scenario Creating Part 3

Let's talk. I don't mean you and me, I mean you and your player. Talking to the player is quite important and can be a linchpin between a great scenario and an annoying one. As with everything, there is a good to fair chance of overdoing it, but I won't judge. It is up to you to figure out how much and when to talk to your player. In any case, this guide shows you how.

This modding guide is the third in a series of guides trying to show you guys and gals how to make cool scenarios. I have spent some quality time going through the code and the config files, experimenting etc. and have found some really fun stuff for everyone to try out.

The guide series:
  1. Starting in a landing vehicle
  2. Triggers and Events
  3. Displaying messages to the player (this guide)
  4. Data Pad guide (how to create your own data pad)
  5. Supply Drop with custom goodies.
  6. Mission Objectives

If there's anything you guys would like to see, let me know in the comments. I am going to create a scenario that actually uses all of the mentioned "features" and upload it as a reference.
   
Award
Favorite
Favorited
Unfavorite
Introduction
Now as a fair warning, this guide will be heavy on the scripting. All we do here will be accomplished with a script event and well, a script. But it should be easy enough to incorporate in your own designs even without coding knowledge.

All together we have four different ways of communicating with the player. There might be more, hidden somewhere in the code, but I am sure the four I'll mention will be more then enough.

Before we jump right into it, I'd like to tell you a little bit about paths (as in file paths) in the game. All the example in this guide will be executed with one single test scenario including the mars island and a fridge (yes, a fridge, you'll see). the scenario is a custom scenario, not an add-on. Basically I just opened up the editor, hit new, made the scene and saved. That's all. Those scenarios get saved here:
%PROGRAM_FILES%\steam\userdata\123456789\244030\local\addons\scenarios\

In my example scenario, I use the following script path:

$profile:addons/scripts/myscript.h

which means, it lies in the "external" file location (where the scenarios are saved). The folder structure I used is arbitrary, it might as well have been something different, allthough it is strongly recommended to use the same structure the main game is using.

Alright, enough talk, let's get to it.
The classic message box
The first of the "four" I'd like to show you is the classic message or popup box. It is also something I recommend not to use. Mainly because it requires the user to enable his mouse cursor and click it away with the OK button (the ENTER key is also a way to dismiss the message). That said, you should use it if there is something very important to be relayed to the player that he has to acknowledge:



The reason I personally don't like this one is that it reminds me to much of a normal desktop application and not a game, but that's my opinion, you might see it differently of course.

Almost forgot, in order to use that in your event script, code this please:
void ExecuteScript (Event_Script eventScript) { g_Game.ShowMessage ("Caption", "Your message", ID); }

The ID is rather obscure to me, I assume it is ment as a way for the game to distinguish the different message box objects or something like that. In all fairness, in what I have tried, it didn't matter, I used 1, and it worked.

Of course you can use string IDs you have defined in the language *.xml files, which is the way to go to enable yourself (or others) to translate those strings.
The cool in game popup message
Now this type of message box is, just like the rest following, something that appears on the screen and disappears after a preset amount of time.

All of those are summened by a single method call:
g_Campaign.AddPopupMessage( secondsToShow, layout, caption, message, message2 );

And the meaning is:
Parameter
Type
Description
secondsToShow
float
For how many seconds should the message be visible.
layout
string
Which message GUI layout should be used.
caption
string
The title string to display.
message
string
The primary message to show to the user.
message2
string
The secondary message to show to the user.

Depending on which layout is beeing used, not every parameter gets used. We can call this method several times in a row, each message gets displayed in succession.

The caption only

This type requires the usage of the layout:
gui/layouts/tkom_popupmsg_1.layout

And this is how it looks:



In order to code it, the following line is neccassary:
g_Campaign.AddPopupMessage(10, "gui/layouts/tkom_popupmsg_1.layout", "The fridge!!!", "", "" );

Caution, this layout has no use for the messages, only the caption is being displayed.

A caption and a (short) message

This version uses the caption aswell as a mesage, allthough it shouldn't be long. Test it to be sure. The layout to be used is:
[layout]gui/layouts/tkom_popupmsg_2.layout[/code]

And this is how it looks:



In order to code it, the following line is neccassary:
g_Campaign.AddPopupMessage(10, "gui/layouts/tkom_popupmsg_2.layout", "The fridge!!!", "Seriously, a fridge!", "" );

You have two more layouts available, yes, you guessed it, "*_popupmsg_3.layout" and "*_popupmsg_4.layout", both are similar to the first two, only a different font size. Try them out to see which one you like best.
The Error Message
Now this one is pretty. In terms of coding it works just as the previous ones, only the layout used is different:
g_Campaign.AddPopupMessage(5, "gui/layouts/tkom_popupmsg_error.layout", "The fridge!!!", "Seriously, a fridge!", "" );

Use it to relay that something is wrong...or that you REALLY like red crosses :)

And that is how it looks:


The Success Message
Similar to the error message this one displays a success message:
g_Campaign.AddPopupMessage(5, "gui/layouts/tkom_popupmsg_ok.layout", "The fridge!!!", "Seriously, a fridge!", "" );

And this is how it looks:



There are more, check out the available layouts in the workbench and experiment a bit, or go nuts and create your own layout, why not?!
The Hint
There is another way to display messages to the player, or rather his thoughts. Playing the scenario made by Rudy.cz (The Lyot Crater SP prototype scenario) I've realized, just as he did, the hints are awesome to display the players characters thoughts. They aren't as intrusive as the other popup messages, but work in a similar way.

Calling such a hint works like this:
g_Game.ShowHint ( message, secondsToShow, highlight );

The meaning of the parameters is:
Parameter
Type
Description
message
string
The message to be displayed.
secondsToShow
float
How long should the hint be displayed.
highlight
bool
Display a highlight frame around the hint?

This is the example I have used in the video below:
g_Game.ShowHint( String("I'm too old for this ♥♥♥♥!!!"), 10, true );

The Log
Yes, you heard right. It's the captains log. Sort of. Your character has an internal log of sorts, to which you can add text lines. Those are being displayed on the datapad.

This is a great way to store information that might not be that important at a certain time but are handy to have stored away.

The invocation is a little bit tricky, but we'll manage, won't we :)

The method call itself is easy:
obj.AddLogEntry( entry );

where entry is the string entry you'd like to add. The hard part is the obj. If we're dealing with a player, it is an object of the type CharacterObject. That in turn is derived from VehicleObject, which defines the AddLogEntry() method. This means, that every vehicle can have a log, but only the players log is being displayed on the datapad.

Now how to get the CharacterObject reference. That is the tricky part. This is one of several ways to do it:
TKOM_Entity playerEntity = GetTKOMEntityByID( 10000001 ); if( playerEntity ) { Vehicle_Handler vehHandler = (Vehicle_Handler)playerEntity; VehicleObject vehObject = vehHandler.storage; if( vehObject ) vehObject.AddLogEntry( "Found the fridge." ); }

Here 10000001 is my characters id as shown in the scenario editor.

Here's how it looks in the game:

Conclusion
That was it, you made it.

I hope you are prepared now to talk to your players. As a look ahead and to wet your apetite, here's a video of a scenario (under construction) I'm making. It shows messages and a scripted supply drop.





Have fund and gool luck on Mars!
10 Comments
dariusz1983  [author] 23 Jan, 2024 @ 11:04am 
@Egon_Freeman: That's Youtube for you ;). For some reason all those old videos got turned private. I try to reactivate them.
Egon_Freeman 3 Jan, 2024 @ 5:49pm 
Is there a reason that every video shown here shows up as "This video is private"? :D
Blade 7 Jan, 2019 @ 1:33pm 
anyone know how to delete save files?
dariusz1983  [author] 11 Mar, 2017 @ 6:58am 
@dbfletch: You're right. My mistake. Thanks, I'll fix it as soon as I get to it.
dbfletch 8 Mar, 2017 @ 7:04pm 
@dariusz1983,
I believe "g_Game.ShowMessage" should read "g_Game.ShowMessageBox" for the classic message box script code
Vas 13 Jan, 2017 @ 4:39am 
I don't quite understand "The Log" part, and have a further question about it. Lemme know when you're online and I can tell you what I'm attempting to do.
dariusz1983  [author] 21 Sep, 2015 @ 4:03am 
Oh, THAT rocket. The huge one! I see. The rocket is controlled by the RocketController_OnSim class. If you could set it's StartLaunch variable to true it would launch I guess. I haven't tried it out though. Plus you need to get the RocketController_OnSim instance, but since you want it as an effect for your scenario, I guess this should be fairly easy. I might have something for you. I'll look it up once I'm home this evening.
Washington 20 Sep, 2015 @ 11:16pm 
What i mean is, how do you make the prototype rocket launch upon entry to the game. The rocket is located under vehicles in the editor and can be launched by going up to it by pressing F in camera mode but i need it to launch automatically withou me having to go into camera mode and pressing F.
dariusz1983  [author] 20 Sep, 2015 @ 2:02pm 
What do you mean by rocket launch?
Washington 19 Sep, 2015 @ 3:58pm 
please, can you quicly tell me how to make a rocket launch at the start of the game, I beg u