Game Scripting – Part 5 – The Guide! – Chapter 3
Welcome to another week of scripting help!
I promised last time that I’d give you a pro tip on how to shorten your code… and here it is:
When you’re writing your scripts, we’ve covered how you need to start and close all your tags. An example:
<script>
</script>
For tags that will contain other scripting elements, you need to keep the start and end tags separate like this. So, the script tag, the condition tag, the event tag, the response tag. These are all elements that you need to place additional code in between the start and end tags.
But what about something like:
<player></player>
You’ll never end up placing anything in between the start and end tag there. Those two are a complete thought placed together like that. When you have a situation like that, you can shorten your code. So instead of the code above, you can just use:
<player/>
See what caused that? It’s the “/” at the end. This tells the script engine that you’re closing that tag. It’s an abbreviation for or any other close tag that you can use.
I used something else mysterious in the last few code snippets I’ve given to you.
What does that do? It turns off the player’s ability to interact with the game for a moment. So, if you want to tell some story, you don’t want people able to make moves and continue the game. The Disable Controllers tag is what turns the player’s ability to do this on and off. If you set the value to “true”, you have turned off Controllers. When you want them available again, you want to include another tag setting things to “false”. Let’s show one of those tags using our newfound shortcut from above, too. Note that I used the “/” to avoid needing to write out , but I left in there. Again, this is because the tags need content in between them to function. Important to remember!
My final promise from last week was that I would cover a more complex condition for your scripting. So let’s get to that. What I want to do today is set a special unit on my map, and then trigger some dialog if that unit is destroyed. So here it comes, a fat block o’ code. Note I’ll be using my shorthand method throughout, and I’ll explain the new tags when I’m done.
<script>
<event>
<condition type="startGame" />
<response type="nameUnit">
<x value="5" />
<y value="5" />
<name value="Jimmy" />
</response>
<response type="disableControllers">
<disable value="true" />
</response>
<response type="chat">
<sender value="Captain Tucker" />
<message value="Alright, Nephew Jimmy. Let's start our training mission." />
<avatar value="tucker" />
<color value="red" />
</response>
<response type="disableControllers">
<disable value="false" />
</response>
</event>
<event>
<condition type="killUnit">
<unitName value="Jimmy" />
</condition>
<response type="disableControllers">
<disable value="true" />
</response>
<response type="chat">
<sender value="Captain Tucker" />
<message value="You suck, Jimmy." />
<avatar value="tucker" />
<color value="red" />
</response>
<response type="disableControllers">
<disable value="false" />
</response>
</event>
<event>
<condition type="endGame">
<player value="1" />
<victory value="true" />
</condition>
<response type="disableControllers">
<disable value="true" />
</response>
<response type="chat">
<sender value="Captain Tucker" />
<message value="Success!" />
<avatar value="tucker" />
<color value="red" />
</response>
<response type="disableControllers">
<disable value="false" />
</response>
</event>
<event>
<condition type="endGame">
<player value="1" />
<victory value="false" />
</condition>
<response type="disableControllers">
<disable value="true" />
</response>
<response type="chat">
<sender value="Captain Tucker" />
<message value="It looks like we both had trouble with this one." />
<avatar value="tucker" />
<color value="red" />
</response>
<response type="disableControllers">
<disable value="false" />
</response>
</event>
</script>
Okay… so note that what I’ve done here at the start is I have named a unit on my map Jimmy. This is a special unit. Because I have named it, I can now refer to it when I want things to happen in-game. Note that in order to name units properly, you need to be using a pre-deployed Blitz map (the units already exist) or a Classic map (where units are made from factories). Since the WarMachine can move, and naming units requires knowing the map coordinates of where a unit is, you can name units created in the middle of a level on a Blitz map.
So, I create a map with a unit at 5,5 on the X,Y grid. Then I enter in this scripting. The game will, in the background, name my unit at 5,5 to “Jimmy”. Note that if you do not make a unit at 5,5 on the map, this code will break. Feel free to name another unit, just make sure to change the coordinates as well.
Now, the critical code is: This tells the engine that when a unit is killed, in this case “Jimmy”, that the next scripting event should occur. In this case, it’s me telling Jimmy he sucks. I mean, come on Jimmy. Get it together. I could also use that same condition and specify a unit on a particular tile, instead of a unit with a particular name.
Let’s say you had a barricade setup that is keeping a unit protected. The first enemy unit that is destroyed on the tile before that barricade could trigger an event where your general announces that his barricade is invulnerable. And, similarly (using either the location or name condition), you could have your general despair when the barricade is destroyed.
There’s a lot of potential for fun with these things.
Okay! More next week with conditions! We’re still scratching the surface here people!


Conqueror95
Thank you, this is very helpful. There hasn’t been a game before that allows you to script your own maps. Thanks guys.
August 27th, 2009 at 5:46 amQllGaaRD
Very nice, really good guide. Thanks and please keep it op urbansquall
September 27th, 2009 at 6:03 amConquerer95
Hey, I don’t if you will check this, but I have a question about banning certain units. So far, I have scripted this:
Keep in mind that this map is classic map, and there is a sea control structure. This scripting doesn’t seem to disable the battle cruiser for each player. Any ideas/tips?
October 25th, 2009 at 8:25 amrebelmanone
Best game ever, thanks for so much interaction. Awesome script help Thank You.
January 29th, 2010 at 8:01 pmrebelmanone
I copied the script above but without the endgame responses only. Dont work, the second chat comes up first then first chat second, in beginning. the second chat should not come up until kill unit? the controllers are active during the chat too and kill unit dont work at all. Any ideals? uppercase/lowercase, spaces and symbols all the same.
January 31st, 2010 at 7:06 pmrebelmanone
I got the above script working. It seems I overlooked something, what I over looked im not sure. Because I didnt realize I could just highlight, rightclick, copy, and paste on to my script. I did just that and it works great. So disregard my previous commet Thanks.
February 14th, 2010 at 6:35 pm