As per the request, please find below a tutorial to set up a neutral creep faction in your DoW maps which can patrol, guard or escort.
Have fun and good luck!
Part 1 - First Things First
Spoiler
Okay, so before we get cracking there are somethings we need to get out the way:
1) This is my first tutorial, so it's likely that it might not be the greatest ever, although I'll try my best and update based on feedback. In this tutorial we will deal with patrol routes, simple back and forth patrols, and the guarding of both areas and units.
2) The methods used in this tutorial are mine and other SCAR coders will have their own ways which might even be better(!) but we can always cross that bridge when we come to it
3) I'm not great with the GIMP paint tool
4) Download the tutorial map from:
http://www.mediafire.com/?sharekey=7...333de3aa77c0d6
and put the files in
C:\Program Files\THQ\Dawn of War - Dark Crusade\DXP2\Data\scenarios\mp
or the Soulstorm equivalent - It's a 3 player map called creep tutorial.
Now, if you have it, open up the map in the map editor, also if you can open up the .SCAR in notepad or Scite then that might be useful.
Setting Up the Map
First up is an overview:
Here you can see a smattering of some things which look a bit like fried eggs, with labels such as 'point1' - these are markers and they're very important.
Also I have circled the player start locations as follows:
Player 1 - red
Player 2 - yellow
Player 3 - Purple
Player 3 will be the owner of the creeps.
The problem with creeps
In Dawn of War, you cannot have sentient 'world' owned units. For creeps to be 'neutral' and present they have to be assigned to a player, which should always be the highest player slot- So for example in an 8 player map, the creeps should be owned by player 8.
One of the problems posed by creeps is that the creep player must have a HQ present or else Dawn of War has a bad habit of considering them annihilated.
Therefore when designing a creep map, it's best to have a small hideaway for the creep HQ surrounded by impassible terrain so that players cannot easily get line of sight or shots on the HQ. Note that this means for creeps to work the player must select fixed start positions.
Now, the slight snag to this plan is brought about by teleporters (in particular the bone singers ENORMOUS range) and in Soulstorm, fliers, which can pop across impassible terrain. So...something must be done.
First off...
A few words about markers
Markers, generally basic markers, are an integral part of SCAR mapping. They allow you to set up points of reference on the map, and so fundamentally, if you want to create a patrol route, it will need to be made of markers.
Also you can add radii to these points of reference, which is massively handy for detecting say, if someone is near a marker, like maybe to see how far along the route our patrol has patrolled (genius Fuggles, genius).
The menu for these is summoned by clicking on the little red flag on the tool bar:
You can see from the overview that I have set up 8 markers, which break down as:
Point 1,2,3,4 - A circular patrol route
Point A,B - A linear patrol route
Relic - A marker to check proximity to our relic which is being guarded
and finally...
Deadzone - Dealing with the creep overlord
My way of handling the creep base breaks down as follows;
1) No one shall go anywhere near it
2) The base will be invulnerable so that a crafty player cannot remove all the map's creeps by destroying the HQ
This will all be covered in the code, but before that, we need to look at squad groups (Sgroups).
LFG!
SCAR handles two types of groups, entities (Egroups) and squads (Sgroups). In rough terms, an entity is a building and a squad is a unit (although technically a squad is made out of x number of entities, this will not be important to the SCAR used in this tutorial).
Although these groups can be setup up dynamically in game, for the sake of scripting its nice and sometimes essential to do it before hand where possible.
I shall presume that you know how to put units on the map using the editor, so having done that you can select them using the drag tool or the selection tool which looks like a man and a tree. So say, you want a traitor librarian to be follow a patrol route, you pop him on the map, select him and then go to the Groups menu and then go into Create Squad Group.
From here you can give your squad group a name.
In my tutorial I will deal with 4 groups:
sister1 - a small girl who will follow the circular patrol route
daddy1 - a chaos obliterator who will follow the small girl and keep her safe from harm with his life
guard - Inqusitor Toth on guard duties of the Relic
patrol1 - A traitor librarian who will follow a back-and-forth patrol
So with groups and markers in mind, let's look at the coding - I'll try to keep my breakdown linear, but somethings will begat other things.
Part 2 - SCAR Ahoy!
Spoiler
Firstly, a SCAR file needs some standard things which make up the basic opening:
These lines call in the various SCAR libraries that Dawn of War provides. Now we'll look at the OnInit function, which is what will be loaded as soon as the map loads up by use of the Scar_AddInit function:Originally Posted by SCAR
As indicated by the curly brackets {} you can see that we are creating a table called t_Players, which will be important as you need tables for FOR operators and it's where we will store the player information that the SCAR needs so as to know which player is which.Originally Posted by SCAR
This will all be set up in the 'players' function, which is why we run it immediately (Rule_AddOneShot means run once, the 0 is time before it is run) and why all the other functions are on an interval delay. When interval delay functions are called, the first number is how often in seconds the function will be run, the second number is the delay in seconds before this kicks off (which in this case is well after the players have been setup).
At this stage we have basically called in the function libraries and set a lot of wheels in motion. The few things which are a = b are variables which I'll use to keep track on what stage something or other is at - However these will be examined as and when we get there.
Love the game, love the players
So let's look at the players function:
This function has three real aspects. The first is a FOR loop which cycles through each start location and assigns a place to each player on the t_Players table. This will allows us to handle them in other code, for example in the second bit of coding which deals with the creep player.Originally Posted by SCAR
I mentioned SCAR groups earlier and here you can see an Entity Group in action. The 2 lines which kick off with EGroup_ basically get all of player 3's buildings and make them indestructable.
You can see that I am calling player 3 by the handle "t_Players[3]" and this is something I will do all the way through - If you make a creep map with more players than simply change the [3] to [whatever].
I am grabbing all of player 3's entities (which we know is just a HQ at this stage) and putting them in a group called "creepHQ" which I'm then making invulnerable before calling in the deadzone function which I shall look at shortly.
Finally on this section I'm locking out the patrolling units from the CPU player so that they will obey my SCAR commands and not their CPU whims.
Now let's have a look at the deadzone function (I'm trying to be linear - honest!)
The purpose of this function is two-fold;Originally Posted by SCAR
1) If anyone comes near the creepHQ then they die, including the creep player so that they can't build
2) Kill off the creep HQ when only 1 player is alive so that the level will end (the creep HQ is invulnerable remember)
Each time it is runs this function first sets a variable called g_alive to 0 and then counts through all the player slots, adding 1 to the total for each player alive. If the final total is 2 then there is only the winner and the creeps, so the creep player is shown out of the back door to allow the victory celebrations to commence.
In addition the funcion also checks the marker "deadzone" to see if any players have squads near it. If they do, then they are bundled into an Sgroup and then suicided. If you really felt inclined you could add some additional functionality which stopped the creep player building anything, but I find that continually genociding their builders works pretty well.
Part 3 - A simple 2 point patrol
Spoiler
Linearity be damned, let's start with something easy.
You may recall that on the map I have made an Sgroup called "patrol1" consisting of one traitor librarian (you may not of course, which is why I have taken this opportunity to remind you).Originally Posted by SCAR
SCAR, as with most programming languages, is logical and as such if you tell it to make nothing do something, it will look at you disapprovingly and crash.
For this reason all my patrol functions kick off with something which counts the number of units alive and if there are none, then it skips out the function.
In the opening part of the SCAR I defined patrol_loop_B as 1. This code checks this variable every time it's run and depending on the status of the patrol_loop_B variable gives an attack move order to my Sgroup "patrol1" to go to either the marker pointA or pointB.
When using this code please appreciate that it's really simple, and as such it hinges on the fact that the interval time that it is called on is great enough for the patrol to get from one point to the next. I've given it 90 seconds in the opening section:
So basically every 90 seconds this code is run, the patrol_loop_B variable is toggled and the patrol unit sent to wherever it's not. Now, if I set this interval to 10 seconds the poor creep would run 10 seconds each way and then 10 seconds later come back, ultimately achieving nothing.Originally Posted by SCAR
Part 4 - Guarding a location
Spoiler
With linearity abandoned in favour of a logical progression of complexity, I'll move onto guarding a location. Now to be clear, when I say location I really mean 'marker radius', in this case the area on the map within the boundaries of the marker called 'relic' (What could be within this marker? Well, if you can't guess that then you probably aren't doing so well with this tutorial).
For veterans of part 3, you'll see that again I check to see that any of my patrol group "guard" are alive. In this case it's only Toth, but it could well be a squad of ogryns and a badger.Originally Posted by SCAR
Next, and again something which is recurring, I'll take note of the number of players and then do a bit of cyclical logic to check whether any players besides from the creep overlord are there, as shown by for i=1, count -1 do. This works by saying, 'right, there are 3 players and I know that player 3 is the owner of the creeps, so I only need to check up to player 2 to see who is within the marker'.
If any players are in the marker area "relic" then they are bundled into an Sgroup called "trespassers" and Toth is sent to sick 'em on melee stance as he hurts the most that way.
Furthermore, I have put some code in for Toth to get stuck in if someone starts sniping at him, hence the check to see if the Sgroup is under attack. If so, I've put him on ranged attack so that he doesn't run about too much and get kited to God knows where. I've put in some final logic so that if no players are near the relic and Toth isn't being shot at then he'll run back to his marker.
Part 5 - Multi-point Patrols
Spoiler
Okay, I admit that I've muddied the water in this code by covering 2 things at once. Primarily this is because it's convenient, but secondarily it's because I worked this code out for my mod based on Bioshock, which never got finished owing to spare time and damned if I'm wasting good code.
This section is a beast so let's try and take it one step at a time. Firstly the rules of this are that my Sgroup "sister1" is going to patrol between the points 1 - 4. I'll be using MoveToMarker rather than AttackMoveMarker as she has no guns, so swap as needed for your units. The 'little sister' will pretty much be following a circular patrol route, with some slight embellishments for her guardian.
First things first, I kick off the patrol route:
This is in someways a wasteful bit of code, but I feel it illustrates a point as these 2 lines both do exactly the same thing. The command 'Cmd_MoveToMarker' unsurprisingly tells a unit to move to a marker. This is typically done as per the second line, with the Sgroup in quotes ("sister1") and the marker in quotes ("point2").Originally Posted by SCAR
However, instead of using a direct marker name it's sometimes nice to use a stand-in, or variable - In this case patrol_loop_A which I defined as "point2" in the opening SCAR. I have found that it can be handy to use a variable which can be changed dynamically, so I can send the exact same command on interval but with different results. If in the opening I changed the value of patrol_loop_A to "point3" then this code would still be valid. You can imagine then that if I had a function which cycled the value of patrol_loop_A then I have the basics of a patrol route when combined with repeated usage of the above code.
Next up, the bulk of the patrol code:
The first line is my embellishment for the 'big daddy' - it checks to see if the obliterator escort is alive and if so, whether it's within 5 units of the girl. If the escort is alive but not near enough, then the girl will wait before setting off on the next leg of her loop. If the escort is dead then she carries on her loop regardless.Originally Posted by SCAR
For now, let's imagine there was no daddy, in which case it would look like:
Notice that there is one fewer 'end'. You need to have an 'end' for each IF, OR and FUNCTION.Originally Posted by SCAR
As you can probably see this is a series of arguments. Firstly it checks to see if the Sgroup "sister1" is at the marker "point1" and if so it tells her to move (remember not attack move in this example) to the next marker and saves the value of the variable patrol_loop_A as "point2".
For those not familiar, an IF loop works down its list of arguments until it reaches the bottom or finds something which works along the way. So in this code it checks whether the patrol is at the first point and if not, checks to see if the patrol is at the second point and so on. This keep the patrol mooching along its route.
Now, we need to put in some additional logic to cater for attack:
The first function checks to see if the patrol group is under attack and if so it unlocks the unit, thereby putting it in control of the creep overlord. An alternative would be to do what I did with Toth and explicitly say 'when attacked use guns' or whatnot. You will see when an attack comes it fires off the secondary function sisterresumepatrol which checks to see if the combat stops, and if so tells the sister to start heading to whatever marker patrol_loop_A currently is.Originally Posted by SCAR
Part 6 - Hiding behind your bigger mate
Spoiler
As mentioned I've put some code in here which I originally created to emulate the logic used by Big Daddies in the game Bioshock. For those not familiar, the little girls in that game contain a parasite which you can extract to give yourself psychic powers, but at the cost of the girl's life. To prevent this, the powers that be send the little girls out with large soldiers who protect the little girls from harm, and the way to quickly get a shoeing is to:
a) Get too near the little sister
b) Attack the little sister
c) Attack the big daddy
There are 2 parts to the protector logic, the first is to keep the big lug plodding after his little charge. This runs every 2 seconds or so:
Originally Posted by SCAR
This first checks to see if the Sgroup "daddy1" is alive and if so checks that it is not in combat (attackstatus = 0). If not then it gets the position of the Sgroup "sister1" and then tells the daddy to attack move to the location defined by the variable sisterlocation. With the slight interval delay this creates quite a nice effect.
So, that's patrolling, now for protecting:
Once more a tripartite sort of a function. In the first block I'm checking whether the patrol or escort is under attack, and if so toggle the attackstatus flag (so that the following logic is temporarily put on hold) and then taking the locks of so that the attacker gets a faceful or rage.Originally Posted by SCAR
After this, as shown by another FOR loop, I'm checking to see if any players are too close to the patrol group, if so, again with the rage.
Finally, if no-one is nearby and no-one is under attack, then lock up the escort from the CPU and set the attackstatus toggle back to enable following.
On the test map please be aware that not having fog of war makes the protector more powerful than normal.
Part 7 - Parting is such sweet sorrow
Spoiler
So there we have my first tutorial - huzzah!
Hopefully it all makes sense and you have at least a vague grasp of what's going down. It really is all to do with markers and Sgroups, so as long as you understand what is making things tick then you'll realise that my arbitrary naming and patrol creation makes no difference. I could easily have put 6 squads of firewarriors in the group "sister1" and it would still continue as now, just with 6 firewarrior squads being tracked by an obliterator.
If you've made it through and your head hurts, I'm not surprised! SCAR is pretty straightforward, but at first it just looks oblique! If any of it makes sense through either my garbled code or my garbled commentary then congratulations! Just stare at it until it becomes clear (or is that magic eye pictures?).
I've tried my best to explain it all, but it's not easy when you have to dart about the shop. Any questions then post in the thread and someone will sort you out. This has taken me several hours and so I apologise for any madness and I appreciate all feedback.
TTFN











Anyways, the AI ignores the Creep HQ.

