Scripting GRAW for OGR Coop Maps
By: Evilducky
Published :16 October 2006


This scripting tutorial will provide basic scripts to get some things to work for your custom OGR-Coop maps. These will be what you need to get things to work. The areas will be basic and simple and I will explain where to put them.

Here you go guys. I have decided to give you guys some basic scripts to get some things to work for your custom OGR-Coop maps. These will be what you need to get things to work. The areas will be basic and simple and I will explain where to put them. These won’t be the full script, from start to finish, so don’t say that I need to end the script data.

To test these, make a very small map and make sure you throw the AI graphs and vehicle graphs. To get the vehicle nodes, go to the AI graph layer, then hit ‘n’ and the AI graph will clear, but not disappear, and now you can set the vehicle graph.

After you make the map, set up the scripts what each of these are for. Ex: if you want to make guys work, use your small test map, place a guy, set him to patrol/guard/sniper or whatever you want. Then use the first script I wrote and set up the area like I explain and it should work.

Now there’s 2 ways to trigger an event. The first way is to just have them all spawn at the start of the game, and the other to have them spawn with a trigger point. You will have to change the areas, and group id's for your script to fit your map, but this should help out a lot of people. I use my small test map to test out these scripts before I post them, so they will work for how I explain them so the rest is up to you to make sure you change the info to what you need.

Guy set up
We will start off with a spawning 1 guy.

<script_data>
        
<xi:include xhref="/data/levels/common/common.xml#xpointer(/common/*)"/>
        
<!--<area_group name="area1" area_name="area1" group="mp_players" interval="0.3" condition="1"/>-->
<area_group name="group01" area_name="group01" group="mp_players" interval="0.3" condition="1"/>

<!--<user name="user" type="once">
<trigger type="UnitInArea" area="area1"/>
<event name="event"/>
</user>-->

<user name="enemy01" type="once">
<trigger type="UnitInArea" area="group01"/>
<event name="group01"/>
</user>
    
<event name="start_game">
<element type="ActivateGroup" group_id="enemy01" start_time="5"/>
</event>

<event name="group01">
<element type="TriggerEvent" event="activate_enemy01" start_time="0.1"/>
</event>

<event name="activate_enemy01">
<element type="ActivateGroup" group_id="enemy01" start_time="0.0"/>
<element type="UnitInArea" area="group01" state="deactivate"/>
</event>

Now to set up the area. You would put an area box around the guy that you placed and name it whatever you like. Mine is group01. The "user name="" " part you can put whatever you want as a user name, but to help keep confusion down keep it to the enemy that your spawning name.
Next is the "<trigger type="UnitInArea" area=""/> " part. You will need to put whatever the name of the area you set around the guys, between the ("") part. That’s telling the game to to look at the area.
Next is the <event name=""/>. This part is important because you will need to make sure that you don’t screw up names here. You can name the event whatever you want it to be. I usually just name it whatever I named my area to help with confusion. What this will do, is tell the game to look at the scipt down at the event second of it. Now that that is done, we will move on to the next part.
The next part is setting up the <event name="start_game"> part. This will set up how your map will start. Underneath this line you will put 1 of 2 things. 1st: if you want to have the guys just spawn you set it up like I have it <element type="ActivateGroup" group_id="" start_time="5"/>. This will tell the game, that 5 seconds after you start it will spawn the guy with the group_id of whatever you named the guys under group. In my 1 guy set up, the group_id I gave him was enemy01 and you set that up when you place the guy, there is a little text box that will ask you what group_id you want to give him, and what transport_id you want to give him, along with some other things. The transport_id isn’t important to spawning guys unless you want them to spawn inside a vehicle.
Like I said that line will be for having the guys just spawn at the begging after 5 seconds. If you want to the spawn with a trigger line, you have to set things up a little different. That is the 2nd way to spawn guys. What you need to do after the <start game> have it say<element type="UnitInArea" group_id="" state=”activate” start_time="5"/> instead of <element type="ActivateGroup" group_id="" start_time="5"/>. What that does is, tells the game that after 5 seconds of crossing the trigger line, the guys will spawn where you put them.
Next, under </event> you will set up the trigger for the group. Starting off with <event name="group01"> and you get that even name from what you put back in the <user name> area of the script. Next fill in the <element type="TriggerEvent" event="activate_enemy01" start_time="0.1"/> with the proper info. The element type has to have the capitals where they are, or it wont work right. The event=”” is a little different this time, because your going to have it go to another line of text in the script. In this case, I put the event name as “activate_enemy01” which will have the game go to the final part of the script to activate the guys. And the start time is jus how fast you want it to do it. Keep it at 0.1 for time sakes.
Now to set up the last lines of script. To start off you need to have the event name again, which will be whatever you put in the last part we just did. <event name="activate_enemy01"> is what mine looks like. See how the 2 are the same. This will tell the game to come to this part of the script next. Under that you will have 2 lines 1: <element type="ActivateGroup" group_id="enemy01" start_time="0.0"/> which will tell the game to spawn the guys, with a start time of 0.0 because it will spawn at the guys at the time you put back in the start time under <start game> lines. You put the group_id in this part as you can see, which again you got from when you made the guy. And the second line is <element type="UnitInArea" area="group01" state="deactivate"/> which will deactivate the area from being triggered a second time. Then just end the event like shown, and you’re done. Go test it out.

Machine gun set up.

Next we’ll set up a guy on the machine gun. To do this, set up the script just like the first one, but with a few changes and lets pretend that there is no area, and guy just yet. It’s just a fresh new map. I won’t go on explaining it to great detail like I did before because you can just follow what I did before.
To do this, you can again do it one of the 2 ways. By having them spawn at the beginning or to have a trigger line for them. The way to set this up is by first going to your map, and setting up the MG. It’s located in the props section and is called “m2hb_tripod” and place it somewhere. Next you will set up a guy; it can be any enemy but make sure that there is just 1 guy that will spawn there and just keep him in guard and make sure he is close to the gun.
Now you’re going start naming things. When you place the machine gun name it something like mg01, this is for just for the tutorial purposes and in your map, you can name it whatever you like. Next make sure you name the guy that you put near it the same thing, mg01. This will have him spawn using the machine gun. Next set up an area around it and name it mg01 also, to keep things easy to start with. Later on you can experiment with areas, and group names and stuff and see if you can get them to work. Now just tide up your script to look like this and it will work:
<script_data>
        
<xi:include xhref="/data/levels/common/common.xml#xpointer(/common/*)"/>
        
<!--<area_group name="area1" area_name="area1" group="mp_players" interval="0.3" condition="1"/>-->
<area_group name="mg01" area_name="mg01" group="mp_players" interval="0.3" condition="1"/>

<!--<user name="user" type="once">
<trigger type="UnitInArea" area="area1"/>
<event name="event"/>
</user>-->

<user name="mg01" type="once">
<trigger type="UnitInArea" area="mg01"/>
<event name="mg01"/>
</user>
    
<event name="start_game">
<element type="ActivateGroup" group_id="mg01" start_time="5"/>
</event>

<event name="mg01">
<element type="TriggerEvent" event="activate_mg01" start_time="0.1"/>
</event>

<event name="activate_mg01">
<element type="ActivateGroup" group_id="mg01" start_time="0.0"/>
<element type="UnitInArea" area="mg01" state="deactivate"/>
</event>



Like always, use your small test map to make sure you can do things and have them work. And make sure you export after you make changes and save your script.

Vehicle set up
This is where it gets hard and tricky. You can have the vehicle do a few things. Again, when it spawns it can come in, in the 2 ways mentioned before. Then you can have it patrol an area, or have it move to an area, and guard it. Since you know how to make them spawn, Ill just keep it to the way it moves.

Tanks
For the tanks, there are 2 types. There is the Abrams and the US_Abrams. The Abrams are AI driven, which means that it doesn’t need a tank crew. This is the one you set as hostile and you will most likely put into your game. The US_Abrams I just use for decoration, like if you build a friendly base, you throw those in there so they don’t constantly shoot at you. Now, when you place a tank down, there is 3 things to do. 1: give it a Vehicle_id, which will be important. For the tutorial, let us just give our pretend tank the name of tank01. Next, you want to check the box “sequenced spawn” , which will give it a sequenced spawn, and lastly change the dropdown menu to “hostile” which will make it the enemies tank. Now that we set up the tank and placed it on the map where you want it, you need to set up the area and when you set it, name it patrol_tank.

Now it’s time for the script. Ill put both the patrol script, and move script, which are very similar, with only 1 part changed.


<?xml version="1.0" encoding="ISO-8859-1"?>
<World>
<!-- World -->
<load_scene file="/data/levels/custom_levels/Blackhawk_down/Blackhawk_down.diesel" use_lightset="true" materials="/data/levels/custom_levels/Blackhawk_down/materials.xml">
        
<object name="world_bb" hidden="true"/>
        
<object name="room01" hidden="true"/>
<object name="Plane01" hidden="true"/>
<global_ambient color="60 60 40"/>
        
</load_scene>

<load_scene file="/data/objects/lens/normal_lens.diesel">
<object name="normal_lens" hidden="true"/>
</load_scene>
<load_scene file="/data/objects/lens/zoom_lens.diesel">
<object name="zoom_lens" hidden="true"/>
</load_scene>
    
<script_data>
        
<xi:include xhref="/data/levels/common/common.xml#xpointer(/common/*)"/>
        
<!--<area_group name="area1" area_name="area1" group="mp_players" interval="0.3" condition="1"/>-->
<area_group name="patrol_tank" area_name="patrol_tank" group="mp_players" interval="0.3" condition="1"/>
        
<!--AREA TRIGGERS-->
<user name="patrol_tank01" type="once">
<trigger type="UnitInArea" area="patrol_tank01"/>
<event name="patrol_tank01"/>
</user>

<event name="start_game">
<element type="UnitInArea" area="patrol_tank01" state="activate" start_time="5"/>
</event>
                
<event name="activate_tanks">
<element type="ActivateVehicle" vehicle_id="tank01" start_time="1.0"/>

<element type="OrderTank" vehicle_id="tank01" ai="true" order="patrol" <!--world_x="-8266.8818" world_y="3262.9829"--> start_time="5.0">
<waypoint position="-7687 2987 0"/>
<waypoint position="-2012 2957 0"/>
</element>
</event>

<event name="patrol_tank">
<element type="TriggerEvent" event="activate_tanks" start_time="0.1"/>
</event>

<player name="player1" mod_name="OnFoot">
<spawn unit_name="ghost_player" object="spawn_player1"/>
</player>
<player name="player2" mod_name="OnFoot">
<spawn unit_name="ghost_player" object="spawn_player2"/>
</player>
<player name="player3" mod_name="OnFoot">
<spawn unit_name="ghost_player" object="spawn_player3"/>
</player>
<player name="player4" mod_name="OnFoot">
<spawn unit_name="ghost_player" object="spawn_player4"/>
</player>
        
<gametype_info name="enemies_to_kill" value="60"/>
        
<spawn_manager>
<!--<xi:include xhref="/data/levels/merge_xml/common_spawn.xml#xpointer(/to_include/spawn/*)"/> -->
</spawn_manager>
        
</script_data>
</World>

Now if you want friendly tanks in there, you would need to put the US_Abrams in there, and then throw the tank crew guys in, and make a few changes to the script there. I haven’t experimented with that yet, so Ill hold off on that part. But as you can see, there is some new lines in there.

<event name="activate_tanks">
<element type="ActivateVehicle" vehicle_id="tank01" start_time="1.0"/>

<element type="OrderTank" vehicle_id="tank01" ai="true" order="patrol" <!--world_x="-8266.8818" world_y="3262.9829"--> start_time="5.0">
<waypoint position="-7687 2987 0"/>
<waypoint position="-2012 2957 0"/>
</element>


This right here is important.

This will activate the tank, and then will assign it to what you want it to do. Because it’s the abram, you need to have the (ai=”true”) part in there. Without it, the tank wont move. Next you have to give it an “order” which we did, patrol. N

ow is the fun part. You get the waypoint positions from the saved “world#” XML files in your graw/custom-levels/work/your_map folder. Getting the 2 right points is fun.. (sarcasm). To get it, here is what I do.

You lay down 3 vehicle AI nodes at the point where you want the tank to start. Save it, and go into that XML file, and copy the 3 points to notepad. Then go back into the editor and take out the one you want to start. Then save it, and go back into the XML and compare the remaining 2 ai nodes, to the orginal 3 and see what one is mission.

Now go back into the editor, and place the 1 last vehicle node that you took out, pretty close to where you had the original one, and save it. Now go get the one that was close to it, and there is your start point. <!- -IF there is an easier way to do this, please post up in the forums and let us all know- -> That will give you the first set of waypoints “which is the -7687 2987 0” on mine there. Yours will change on your map, so don’t keep my positions there as they are just to show you how they look

Now you will do the same thing with the end position, and past it in the second part of that, and your tanks will Now patrol. Now just go into your little test map that you should of made, and fiddle around with that script, and get areas, and tank names that work for your map to work in the little test one. Also see if you can add more if you want.

Now to get it to just move to a point, you take that small part of the script and change it some.

<event name="activate_tanks">
<element type="ActivateVehicle" vehicle_id="tank01" start_time="5.0"/>
<element type="OrderTank" vehicle_id="patrol_tank01" ai="true" order="move" world_x="-287" world_y="-902" start_time="5.0">
</element>
</event>



You can see where the changes are. They are small and simple changes, but what you need to do is change the “order” from patrol, to move and then instead of a start waypoint, you just put in the end waypoint as shown. And what it does is, it will get the tank to move to that point and just stay there and defend that point.

Ill add more for you guys later, like the blackhawk, panhards and apaches. Hope this helps out alot of people.

 


© GhostRecon.net