| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Advanced scripting of the mission xml

Page history last edited by Donald Smithson 14 years, 3 months ago


 


Placing a unit (prop) using a script command(ie. Adding a Zeus, laptop)

Placing a Prop

Lets say we want to create a "laptop" from the units list, (you could substiture any other prop - for example a mine) and I want it to appear when a player is in a specific location.

In the editor I place a marker where I want the laptop to appear and give the marker a name (for the marker I usually use a shell case from the static's list as these can give quite precise x,y,z co-ordinates) and in the same area I create a trigger location (lets say I call it "loc_laptop").

 

Once the marker is placed I leave the editor and open up the world.xml file, using the search tool I locate the marker, take a note of the x,y,z co-ordinates, then delete the marker from the world.xml file, save and close.

 

In the mission.xml file I would then use the following to acually make the laptop appear.

 <trigger name ="t_loc_laptop" interval="2" preserved="false">

  <condition type="UnitInLocation" location="loc_laptop" player_type="team_a" greater_than="0"/>

  <event name="e_laptop"/>

</trigger>

 

<event name ="e_laptop">

<element type="CreateUnit" unit="laptop" name_id="laptop01"pos="4301.9297 -883.35876 1384.9781" start_time="1"/>

</event>

 

Adding a zeus

Adding a Zeus to your mission is a three step process. 

  1. First, in the editor, create a "Target Marker" in the location where you would like your Zeus.  Name this marker "target_zeus01".
  2. Second, In the world.xml, search for your "target_zeus01" to obtain the positional x,y,z coordinates where you placed your marker.
  3. And lastly, enter this information into your mission.xml:

<element type = "CreateUnit" weapon="predator" pos="5538.6543 -3598.2598 522.5941" spare_clips="1" yaw_pitch_roll="0 0 50" />

 

The position or 'pos="x y z"' comment are the x,y,z coordinates that you pulled from your Target Marker.  If you need to be precise with the placement of your Zeus (IE place the Zeus on top of a box), the Zeus 0,0,0 location is not centered, but on the corner.  So if you would like to center your Zeus, you may need to add or subtract 2-3 from your 'X' and\or 'Y' coordinates to get the desired effect.

 


Adding Objectives

When modding in GRAW 2, adding one or two objectives can turn a simple "shoot-em-up" into a tactical mission.

Adding Objectives is a simple procedure, In this example we want to place a C4 charge on an Adat to destroy it, this

in turn will trigger a second objective which is to find and destroy a communications antenna.

 

So, firstly, in the map editor we need to create and place three items:

1) A location trigger that we will call "loc_trig00"

2) An Adat that we will cal "adat01"

3) A communications antenna that we will call "antenna01"

 

That done, we can save and exit from the editor and open up our "mission.xml" file.

In the mission.xml file we first need to add the following to the "start_mission" event:

  <element type="MakeAttachable" attach="true" detonate_event="e_destroyed_adat01" vehicle_id="adat01"/>

  <element type="MakeAttachable" attach="true" detonate_event="e_destroyed_antenna01" name_id="antenna01"/>

  <element type="StartTrigger" name="t_destroyed_adat01" start_time="2"/>

   <element type="StartTrigger" name="t_destroyed_antenna01" start_time="2"/>

 

This enables us to plant a charge on both the "adat01" and the "antenna01" and starts the triggers that will set the Objectives when certain  conditions are satisfied.

 

So, now to the main body of the mission script, if we add the following:

 

<!-- Add first objective destroy adat01

==========================-->

  <trigger name="t_loc_trig00" interval="2" preserved="false">

  <condition type="UnitInLocation" location="loc_trig00" player_type="team_a" greater_than="0"/>

  <event name="e_add_objective1"/>

</trigger>

  <event name="e_add_objective1">

  <element type="Objective" id="obj1" state="add" headline_id="your text" txt_id="your text" waypoint_id="your text" waypoint="your x-y-z co-ordinates"/>

</event>

<!-- Add second Objective ... break communication link

========================================-->

  <trigger name="t_destroyed_adat01" interval="2" preserved="false">

  <condition type="VehicleDestroyed" vehicle_id="adat01" amount="all"/>

  <event name="add_objective2"/>

</trigger>

  <event name="add_objective2">

  <element type="Objective" id="obj2" state="add" headline_id="your text" text_id="your text" waypoint_id="your text" waypoint="your x-y-z co-ordinates"/>

  <element type="Objective" id="obj1" state="completed"/>

</event>

 

What we have are our two objectives, the first objective is set by the player being in a certain location ("loc_trig00"), the second objective is set by the first objective being  satisfied ("t_destroyed_adat01")

 

A walkthrough would be something like this:

 

When the player enters an area (UnitInLocation)  (loc_trig00) the first objective (obj1) is added and in the game a green arrow will guide you to the target (adat01) which will show as a green box as you approach.

 

Once the target is reached we can plant a C4 charge on the adat01 and destroy it ....... BOOOOM !!

 

Destroying the adat01(t_destroyed_adat01) triggers the addition of our second objective and goes something like this:

 

BOOOOM !! adat01 is destroyed and triggers (t_destroyed_adat01) our condition (VehicleDestroyed) (adat01) to add our second objective (obj2) at the same time the first objective is removed from the objectives list as it is now complete (id="obj1" state="completed"), and in the game a green arrow will now guide you to the next target which in this case will be (antenna01).

 

When selecting your waypoints for targets, I would recommend you look them up in the world.xml  file (ie.. for the loc_trig00 do a search in the world.xml for loc_trig00) and use the FULL co-ordinates including the numbers after the decimal point (ie.... "-3638.04 -2749.988 363.45395"). Otherwise your waypoint "green box" will appear to be in a different location as you approach.

 

Also, the above is only an example, you can use anything as a trigger ... vehicle destroyed, patrol destroyed, sniper killed, hostage found etc...etc.. and if you use the "if_all" if_any" or if_none conditions then several conditions can be set to satisfy an objective.


 

 

Setting up respawn points

To keep your Ghosts from having to run across the map after an area has been cleared, you may wish to consider setting up additional locations to spawn in the unfortunate incident that a player has been killed.  To do this, setup your respawn locations in the editor.  For our example, we'll have three spawn locations:

  • coop_spawn:  This is your initial spawning location
  • loc_respawn01: After a particular area has been entered (say loc_trig01), then your team will respawn to this location
  • loc_respawn02: After your team detonated an ADAT, you want to respawn at the ADAT location.  So you would create the loc_respawn02 at the site of the ADAT

 

Here is the code:

<trigger name ="t_loc_trig01" interval="2" preserved="false">

<condition type ="UnitInLocation" location ="loc_trig01" player_type = "team_a" greater_than="0"/>

<event name ="e_loc_trig01"/>

</trigger>

<event name = "e_loc_trig01">

<element type = "StopTrigger" name = "t_loc_trig01"/>

<element type = "SetSpawnLocation" location = "coop_spawn" side = "1" set = "false"/>

<element type = "SetSpawnLocation" location = "loc_respawn01" side = "1" set = "true"/>

</event>

 

<trigger name="t_adat01_dead" interval="2" preserved="false">

<condition type = "VehicleDestroyed" vehicle_id="adat01" amount = "all"/>

<event name="e_adat01_dead"/>

</trigger>

<event name = "e_adat01_dead">

<element type = "StopTrigger" name = "t_adat01_dead"/>

<element type="Objective" id="adat_destroyed" state="completed"/>

<element type="SetSpawnLocation" location="loc_respawn01" side="1" set="false"/>

<element type="SetSpawnLocation" location="loc_respawn02" side="1" set="true"/>

 

</event>

 

The above code assumes that you must pass through loc_trig01 prior to detonating the ADAT.  If not, you can even add all three locations to the code such as this example with the ADAT detonation:

 

<event name = "e_adat01_dead">

<element type = "StopTrigger" name = "t_adat01_dead"/>

<element type="Objective" id="adat_destroyed" state="completed"/>

<element type = "SetSpawnLocation" location = "coop_spawn" side = "1" set = "false"/>

<element type="SetSpawnLocation" location="loc_respawn01" side="1" set="false"/>

<element type="SetSpawnLocation" location="loc_respawn02" side="1" set="true"/>

 

</event>

Where both "coop_spawn" and "loc_respawn01" are set to not spawn any more players.

 

Setting up variables

There may be times when you need to store numeric values when manipulating your missions.  In this example, we'll have 10 objectives in order to complete your mission.  So our objective in this code is to add '1' each time a mission is completed.  When our variable equals 10, then we can end the game.

 

First, we'll need to setup our variable string using the "Calculate" element under our starting conditions:

<event name="start_mission">

<element type="StartTrigger" name="t_end_game" start_time="1"/>

<element type="Calculate" start_time="1">

<store target="missions_completed" source="0"/>

</element>

</event>

In the above code, we use the target "missions_completed" to store our values.  Since we are starting the game, we want our initial value to be zero noted by the 'source="0"'. 

 

After we've triggered one of our objectives as complete (detonated a vehicle, entered a location, etc.), we'll want to add the following code into the event

<event name="e_our_triggered_mission_objective_completed">

<element type="Objective" id="obj1" state="completed"/>

<element type="Calculate" start_time="1">

<add target="missions_completed" source="1"/>

</element>

</event>

Note that we've called the "Calculate" element type again.  This time, we use the "add" sub element to add one to our "missions_completed".  You can use other sub-elements such as "sub" to subtract a value, "rand" for a random variable, etc.

 

So each time we complete an objective, we add "1" to our "missions_completed" target.  We now need to setup the trigger to end the game once our "missions_completed" variable equals "10"

 

<trigger name="t_end_game" interval="2" preserved="false">

<condition type="EvaluateVar" var="missions_completed" equal="10"/>

<event name="e_end_game"/>

</trigger>

<event name="e_end_game">

<!-- Enter the code you want to end the game -->

</event>

 

As you can see, under the trigger "t_end_game" we created the condition to evaluate the variable in the "missions_completed" target.  If "missions_completed" then equals 10, call up the event to end the game.

 

You can use variables in many different ways in your GRAW2 Missions: creating random numbers for spawning AI in different locations, using in conjunction with strings to trigger diverse messages, etc.

 

Scripting triggered smoke effects

During gameplay, there may be times when you want to call up smoke effects triggered by an explosion, marking an enemy, etc.  In this example, we are going to pop smoke to identify the extraction zone once all objectives have been completed.

 

<trigger name="t_objectives_complete" interval="2" preserved="false">

<condition type="EvaluateVar" var="missions_completed" equal="10"/>

<event name="e_objectives_complete"/>

</trigger>

<event name="e_objectives_complete">

<element type="StopTrigger" name="t_objectives_complete"/>

<element type="ShowMessage" msg="Mission Complete, Ghosts." kind="splash"/>

<element type="Objective" id="obj_end" state="add" headline_id="Extract" txt_id="Extract" waypoint_id="Extract" waypoint="15465 -2052 50"/>

<element type="StartTrigger" name="t_extract" start_time="3"/>

<!-- Code for the Smoke -->

<element type="CreateUnit" unit="efx_hh_zone_smoke" location="loc_extraction" center="true" name_id="smoke_extract" start_time="3"/>

<element type="ColorSmoke" side="1" name_id="smoke_extract" start_time="3.5"/>

</event>

In this example, we setup a trigger to end the game and an objective to reach the extraction point.  After 3 second, we use the "CreateUnit" element to create the "efx_hh_zone_smoke" in the center of the extraction location and gave it the name "smoke_extract".  The nice thing about the "efx_hh_zone_smoke" is that it has three colors to choose from:

  • 0 = Neutral or Black Smoke
  • 1 = Blue Smoke
  • 2 = Red Smoke

We can change the color using the "ColorSmoke" element and identify the smoke to change via the "name_id".  Just make certain that the "ColorSmoke" element is called after the "CreateUnit" or your smoke will use the default "0" or "Black" smoke.

 

Note that if you do not use the 'center="true"' variable, the creation of the unit (in this case smoke) will appear at random in the location.  As with the example with the creation of the Zeus, you can also use x,y,z coordinates instead of a location you created in the editor.


Putting writing on walls / surfaces.

This is a slow process, with a "difficult to place" object, so if you intend to put several writings in your mission, save after each one. Basically the text object can be found in the editor under "static" and by pressing control+2 then masking for building. This will bring up the two text objects (a standard and a military text object). Clicking with the left mouse button on a wall / surface will place the axis point for the text from here using the arrow buttons on your keyboard you can manipulate the text into position (remember the axis are 3D).

 

When the building text object is used, a "Text Edit" box will be placed on your screen from here you can - a)put in your own text - b)edit the colour by moving RGB sliders and - c) edit the size of the text. In the standard text object you can only use uppercase letters, you cannot include numbers, or periods / full stops or any punctuation. In the military text object you can use numbers.

 

If after you have placed some text you want to edit it again, you can do this by clicking your left mouse button where you "think" the bottom left corner of the  text boundary box is.

<create a video of this>

 


 

How to script player selectable re-spawn points

Introduction/Description

 

Player selectable re-spawn points allow the players to select where they will re-spawn into they game when the die.

Player selectable -re-spawn points allow the player to determine which one of a defined set of spawn points is active at any one time.  The player does this by standing for "x" seconds at a pre-defined location on the map (usually indicated by a static prop - like a transformer). The game script will then set the player spawn location to that location.  When players die, they will spawn back into the game at that point.

 

This provides for some interesting game dynamics as players fight to stay alive as they set forward spawn points.

 

In the Editor

We'll start by defining the spawn locations in the map editor. We'll call the locations "loc_coop_spawn01" and "loc_coop_spawn02".  You'll also want to put a prop. there so that the players can recognise the place they need to go to to set the spawn.  You could also use writing on a wall or an objective marker.

These locations are in addition to the "default" starting spawn location "coop_spawn" - this is where the players will spawn when the game starts.

 

The Script

The code uses a simple player trigger that will call an event if a player stays in the defined location for more than "x" seconds. This code can be used to trigger a variety of events, in this case, it is being use to trigger the re-setting of the spawn point.

 

Let's start with an example where we have just 2 player selectable respawn points/locations. It's easy to expand the script out from there once you understand how it works.

 

There are two xdefines (think of them as routines) that are used here to make the code more compact and readable.  They 1) reset the spawn point and 2) detect when a player has moved into one of the defined locations.

 

You put these two xdefines into your mission.xml.  I usually put it up toward the top of the code just before the start_misison tag (<event name = "start_mission">).

 

Script to Reset the Spawn Point

<!--======== Clear all spawn points and then set spawn point for player activated location =======-->
    <xdefine name = "set_coop_spawn( loc_spawn )">
        <event name="e_$loc_spawn">
            <element type = "SetSpawnLocation" location = "coop_spawn" side = "1" set = "false"/>
            <element type = "SetSpawnLocation" location = "loc_coop_spawn01" side = "1" set = "false"/>
            <element type = "SetSpawnLocation" location = "loc_coop_spawn02" side = "1" set = "false"/>
            <element type = "SetSpawnLocation" location = "$loc_spawn" side = "1" set = "true"/>
        </event>
    </xdefine>

Script to Trigger an Event When a Player Moves Into an Area

<!--==============  LOCATION BASED EVENT  =========================-->

    <xdefine name = "location_based_event( loc_lbe, e_lbe, wait_time, wait_message, done_message )">

        <player_trigger name = "t_lbe_$loc_lbe" player_type="team_a" >

               <condition name="InLocation" location="$loc_lbe" />

               <on_enter name="TriggerEvent" event="e_start_lbe_timer_$loc_lbe"/>

                <on_exit name="TriggerEvent" event="e_break_lbe_timer_$loc_lbe"/>

       </player_trigger>

            <event name ="e_start_lbe_timer_$loc_lbe">

               <element type = "ShowMessage" msg = "$wait_message"/>

                <element type = "TriggerEvent" event = "$e_lbe" start_time = "$wait_time"/>

                <element type = "TriggerEvent" event = "e_times_up_$loc_lbe" start_time = "$wait_time"/>

        </event>

         <event name="e_times_up_$loc_lbe">

               <element type = "ShowMessage" msg = "$done_message"/>

        </event>

         <event name="e_break_lbe_timer_$loc_lbe">

                   @debugmessage(  e_break_lbe_timer )

                  <element type = "BreakEvent" event = "e_start_lbe_timer_$loc_lbe" />

  </event>

</xdefine>

 

Now it's just a matter of "calling" the above scripts and then triggering them from your mission script. You do this by using the "@" command to "call" the xdefine, passing the required parameters to it. Then using "StartPlayerTrigger" to activate the spawn location test. For example...

 

@location_based_event( loc_coop_spawn01, e_loc_coop_spawn01, 5, Wait here for 5 seconds to set this as the new spawn location,  New spawn location set)
@location_based_event( loc_coop_spawn02, e_loc_coop_spawn02, 5, Wait here for 5 seconds to set this as the new spawn location,  New spawn location set)
@set_coop_spawn( loc_coop_spawn01 )
@set_coop_spawn( loc_coop_spawn02 )

 

<event name = "start_mission">
        <!--Set the spawn location triggers for the first set of spawn points-->

        <element type = "StartPlayerTrigger" name= "t_lbe_loc_coop_spawn01" start_time = "0"/>
        <element type = "StartPlayerTrigger" name= "t_lbe_loc_coop_spawn02" start_time = "0"/>

 

 

So the start of your mission.xml would look like this...

<?xml version="1.0" encoding="ISO-8859-1"?>

 

<mission_script>
    <xi:include href = "/data/levels/common/common.xml#xpointer(/common/*)"/>
    <xi:include href = "/data/levels/common/coop_ranks_ogr_quarry.xml"/>
    <xi:include href = "/data/levels/common/coop_rules.xml"/>

 

<!--======== Clear all spawn points and then set spawn point for player activated location =======-->
    <xdefine name = "set_coop_spawn( loc_spawn )">
        <event name="e_$loc_spawn">
            <element type = "SetSpawnLocation" location = "coop_spawn" side = "1" set = "false"/>
            <element type = "SetSpawnLocation" location = "loc_coop_spawn01" side = "1" set = "false"/>
            <element type = "SetSpawnLocation" location = "loc_coop_spawn02" side = "1" set = "false"/>
            <element type = "SetSpawnLocation" location = "$loc_spawn" side = "1" set = "true"/>
        </event>
    </xdefine>

<!--==============  LOCATION BASED EVENT  =========================-->

    <xdefine name = "location_based_event( loc_lbe, e_lbe, wait_time, wait_message, done_message )">

        <player_trigger name = "t_lbe_$loc_lbe" player_type="team_a" >

               <condition name="InLocation" location="$loc_lbe" />

               <on_enter name="TriggerEvent" event="e_start_lbe_timer_$loc_lbe"/>

                <on_exit name="TriggerEvent" event="e_break_lbe_timer_$loc_lbe"/>

       </player_trigger>

            <event name ="e_start_lbe_timer_$loc_lbe">

               <element type = "ShowMessage" msg = "$wait_message"/>

                <element type = "TriggerEvent" event = "$e_lbe" start_time = "$wait_time"/>

                <element type = "TriggerEvent" event = "e_times_up_$loc_lbe" start_time = "$wait_time"/>

        </event>

         <event name="e_times_up_$loc_lbe">

               <element type = "ShowMessage" msg = "$done_message"/>

        </event>

         <event name="e_break_lbe_timer_$loc_lbe">

                   @debugmessage(  e_break_lbe_timer )

                  <element type = "BreakEvent" event = "e_start_lbe_timer_$loc_lbe" />

  </event>

</xdefine>

 

@location_based_event( loc_coop_spawn01, e_loc_coop_spawn01, 5, Wait here for 5 seconds to set this as the new spawn location,  New spawn location set)
@location_based_event( loc_coop_spawn02, e_loc_coop_spawn02, 5, Wait here for 5 seconds to set this as the new spawn location,  New spawn location set)
@set_coop_spawn( loc_coop_spawn01 )
@set_coop_spawn( loc_coop_spawn02 )

 

<event name = "start_mission">
        <!--Set the spawn location triggers for the first set of spawn points-->

        <element type = "StartPlayerTrigger" name= "t_lbe_loc_coop_spawn01" start_time = "0"/>
        <element type = "StartPlayerTrigger" name= "t_lbe_loc_coop_spawn02" start_time = "0"/>

 

 

 

 

Comments (0)

You don't have permission to comment on this page.