Chapter 4: Objective UIOk. Now you should know a little more about how the syntax works, so I won’t describe everything at the same level as in the previous chapter but will of course explain anything new and the function of the script itself.
Our goal in this chapter is to create an objective with headline, descriptive text and a waypoint marker in the HUD. We want to update the objective during the mission and finally declare the objective completed. Important to understand is that nothing that we create in this chapter will have anything to do with what the actual objective is, in other words, what activates it, what is required to update it, or what is required to complete it? Nor will the script in this chapter work by itself. All we’re going to do is create the parts that the player can see during the mission, the HUD and map elements. For the objective to actually do anything and drive the mission forward, you’ll need to use triggers and other events based on your mission design. All available trigger conditions will be covered in detail in chapter 5.
We really wouldn’t need to enclose each of the elements covered in this chapter inside their own events, but we’ll do that anyhow to show that they are used in different parts of the script. In your mission you can, and probably will, use them inside any event you want, combined with other elements.
Here is the script that we’ll need to reach the goal of this chapter:
headline_id=”mx_obj1_head” txt_id=”mx_obj1_txt”
waypoint_id=”mx_obj1_wp” waypoint=”10171 -9296 106”/>
headline_id=”mx_obj1_head” txt_id=”mx_obj1_txt2”
waypoint_id=”mx_obj1_wp” waypoint=”10171 -9296 106”/>
To do this we need nothing from the world.xml, but we need to have the coordinates to where we want the waypoint marker to appear. One way of getting this is to use the panel inside the map editor, activated by pressing “/” or your numeric keypad, and moving your camera to around the area where you want it to be placed and then writing down the coordinates seen in the lower right corner. Another way is to place a prop where you want it to be, name it something like “objective_marker_pos”, save your file and them open the world.xml in you XML editor and do a search for “objective_marker_pos”. Then you’ll find its coordinates listed next to it’s entry in there, copy them to somewhere safe and then back in the map editor, delete the prop.
Add Objective EventThe first thing we need is an event that adds the objective for the player to see.
That part of the script looks like this:
headline_id=”mx_obj1_head” txt_id=”mx_obj1_txt”
waypoint_id=”mx_obj1_wp” waypoint=”10171 -9296 106”/>
For this we create a simple event and give it a name that is descriptive so we later can easily find it in our script. This you know by now so let’s concentrate on the content element.
We only need one element to initiate an objective for the player and it’s of the type “objective”. This element type has many attributes that are optional to use depending on what you want to do with the objective itself.
First we’ll set the attributes that “objective” always requires, which is “id” and “state”. “id” is the name that we’ll use inside the script to add, update and remove the objective, lets call this “obj1”. In “state” we determine what’s going to happen to the objective GUI, and as we now want to add it as a new objective, set it to “add”.
Then we want to tell the game which strings to use as objective headline and objective description. This is done by setting the attributes “headline_id” and “txt_id”, which require you to enter the name of string variables created in the strings.xml connected with your mission, which you don’t have to use. There is another option to enter headline and description to an objective, that doesn’t require a strings.xml file. Instead of using “headline_id” you simply use the attribute “headline” and enter the text you want inside the quotation marks. The same thing can be done for the description, when “txt” is used instead of “txt_id”. The strings.xml files are used to allow for multi language support.
That was it for the objective part. Now we need to set the attributes for the waypoint marker. The first of those is “waypoint_id”, which works the same as the other string attributes, but holds the string that will be visible under the waypoint in the HUD. This attribute also accepts text written directly between the quotation marks, if that text isn’t matching the name of a string variable in the strings.xml. The second attribute needed is “waypoint”, which requires the coordinates of where the waypoint should appear in the game world that we got earlier somehow. These are entered as three floats in the order “x”, “y” and “z”. Now all that is left is closing all tags.
Update Objective EventNow the player can see the objective in the list, read the description and see the waypoint on the map and in the HUD. But during this objective the description will change when a given trigger condition is set. This could also be used to move the waypoint marker by simply adding new coordinates for it, but we’ll leave it this time.
That part of the script looks like this:
headline_id=”mx_obj1_head” txt_id=”mx_obj1_txt2”
waypoint_id=”mx_obj1_wp” waypoint=”10171 -9296 106”/>
Create a new event and give it a good name. We’ll only need one element as contents again, and once again we’ll set the “type” to “objective”. As we want to update the objective we added earlier, we’ll have to set “id” the same as we did before. Then we’ll set “state” to “update”. Next we’ll use the “headline_id” and “txt_id” again. As we don’t want to change the objective headline, we’ll set the same string for that as before, but we want to change the description, and so we simply set another value to the “txt_id”.
As we don’t want to change the objective waypoint, we’ll set all those value the same again, and finish by checking that all tags are closed.
Completing Objective EventFinally we want to create the event that declares the objective completed in the list and removes the waypoint.
That part of the script looks like this:
Create yet another new event and give it a good name. Once again we’ll only need one element as content with the “type” set to “objective”. Then again tell the game which objective you want to manipulate by setting “id” to the name we gave it when first adding it. Finally to remove the objective and the waypoint, we’ll set “state” to “completed”. The reason both the objective was set as complete and the waypoint was removed is that they have the same “id”. I’ll show next how to do this with separate waypoint controls. But first, close all tags, and we’re done with the goal for this chapter.
Separate Waypoint ControlFor some objectives you’ll probably want more then one waypoint marker and/or have separate control over it in the script. To get the later you’ll need to have a separate id for just the waypoint marker. This is done by defining the objective and the waypoint in separate elements.
Objective and waypoint with a single id:
headline_id=”mx_obj1_head” txt_id=”mx_obj1_txt”
waypoint_id=”mx_obj1_wp” waypoint=”10171 -9296 106”/>
Objective and waypoint with separate ids:
headline_id=”mx_obj1_head” txt_id=”mx_obj1_txt” />
waypoint_id=”mx_obj1_wp” waypoint=”10171 -9296 106”/>
If you want to add multiple waypoints for an objective, you simply do it by adding an additional element for each additional waypoint.
Objective with two waypoints:
headline_id=”mx_obj1_head” txt_id=”mx_obj1_txt” />
waypoint_id=”mx_obj1_wp” waypoint=”10171 -9296 106”/>
waypoint_id=”mx_obj1_wp” waypoint=”10500 -8256 -90”/>
When you define everything with separate ids, you also have to remember to remove them all at the end with separate elements.
Strings.xmlThe strings.xml file is something that all original missions use to define strings containing the text to be shown during the mission, including the briefing text seen in single player. These files are found in the data/strings catalogue.
Note: The tutorial "GRAW2: The Editor" will cover how to setup a custom strings.xml file in the level folder instead.Inside it uses very simple XML, with one base element containing all string variable elements.
Example of string.xml contents: