Experienced Scripting

48.  How do I add units to the map in-game?      

There are quite a number of ways to add units in-game to the map, all found in the "Operations on Units" action section:

      - Carry out unit building and add to dynamic group.

      - Carry out fast unit building and add to dynamic group.

      - Create unit and add to dynamic group.

      - Create units in formation and add to dynamic group.

Each of these will create a unit, either by building it in a structure (first two) or simply making them appear in a zone (second two).  The units created will be added to the Dynamic Group specified.  These actions share one critical point in common:  at the start of the game, at least ONE unit of the same nation as the type to be built MUST be present on the map!  This includes the groups available in the Map Editor as "Originals" and "Mercenaries."

Why?  Apparently, when the game loads a scenario it will load graphics *only* for nations present on the map at start.  Thus, if you want to create a group of Winged Hussars during your scenario, you must have placed at least one Polish unit (building, land or sea) on your map somewhere when you made it -- or else the game will not "know" what graphic to use, and thus no Polish units can be created.

Note that this does *not* mean that units of that nation must be present when the trigger is called for -- they only need to have been present at the very start of a game.  Thus, if you want that group of Winged Hussars to appear seemingly out of the blue (with no obvious Polish settlement apparent to the player), just place a couple Polish units (be they peasants, Hussars, pikes, whatever) on the map in the Map Editor, place them in a Mission Group and remove that mission group in your startup routine.

"So how do I use these unit-making functions," you ask?  OK, here we go!

A. Carry out unit building and add to dynamic group.

This function will produce a unit as normally carried out in a selected building... e.g. an English 18th c. barracks for a Highlander unit.  Be sure the unit to be built is of the right type and nationality for the building!

Example:

ACTION

      Carry out [English] Highlander building in structure of group <EnglishBarracks> and add to dynamic group <HighlandRegiment_Dyn>.

NOTE:  With this and the next action, units can be queued in the same trigger.  E.g. if you want 5 Highlanders to be built, repeat the action 5 times.  (But remember - do NOT use "duplicate"!)

NOTE:  Resources and supporting buildings are required and used for the creation of units via structures.  E.g. barracks will not produce units without a Blacksmith; 17th c. pikemen cannot be created without sufficient iron; etc.

B. Carry out fast unit building and add to dynamic group.

This is just like the first, only the unit production is sped up significantly.  Almost ANY unit will produce as if it were an 18th c. pikeman!

 

Example:

ACTION:

      Carry out fast [French] Musketeer, 17 c. building in structure of group <FrenchBarracks>.

C. Create unit and add to dynamic group.

This action creates a unique unit in a particular zone, and associates it with a particular Dynamic Group.  Fairly straightforward.

NOTE: This action and the next do NOT subtract resources or require supporting structures.  Essentially, the units come as "freebies."

D. Create units in formation and assign to dynamic group.

This is perhaps the most useful of the unit creation available to the mission script writer.  It's the easiest way to place units on the map in mass quantities.  Its only drawback is that it does not create true formations: it merely places units on the map in a tidy arrangement.  Thus the units benefit from no formation bonuses and will behave no more cohesively than a collection of loose units controlled as a group.

You'll notice, when selecting the "formation" in which to assign your units, you have quite a wide range of choices -- from single units to ship lines and batteries of cannon and mortars.  Each is illustrated by an ASCII (text) chart in the selection menu, allowing you to peruse your options.  The formation selected does not have to be a "valid" formation for the units created; e.g. you can create 20 Tatars in a neat line using LINEMORB20.

Example:

ACTION

      Create units in formation <LINEMORB20> for player <orange>, place it in zone <TatarZone> in direction 95 and assign to dynamic group <Tatars_Dyn>.
 

49.  How do I order buildings to be created?    

In addition to creating individual military units, "Create unit and assign to dynamic group" action can also be used to create buildings.  It's a good idea to create only one building per zone, as all buildings appear in the zone's center; if a unit or structure is already present there, it could interfere with or prevent entirely the building's creation.

Note that for most buildings, only the foundations will be laid via the "create unit" trigger.  Thus, "build up/repair buildings in group" will be required of some peasants to finish the job. 

 

Example:

CONDITION:

      Quantity of <gold> by player <red> is more than 5000.

ACTION

      Create Barracks, 17th century unit for player <Red> in zone <2ndBarracksZone> and assign to group <Barracks_Dyn>.

      Deselect units of player <Red>.

      Select all units of group <RedPeasants> by changing previous selection.

      Repair/build up buildings of group <Barracks_Dyn> with selected peasants of player <Red>.

 

NOTE:  Buildings created with this function DO subtract resources, but do NOT need their prerequisite structures.  E.g. a market can be built without having previously constructed a storehouse.  

50.  Can I order units onto a ferry?      

Yes you can, but the trigger is a bit tricky to use.  In order to be successful, the ferry *must* be moored (i.e. if you click on it, it must show a Rally Point on shore).  One odd feature of Cossacks: The Art of War is that ferries, when moored in the Map Editor, become unmoored when loaded into a game.  This means you need to control and order a ferry to shore with a trigger, otherwise nothing will come of your efforts.

Another tricky factor in dealing with transports is that it's all but impossible to get a zone placed and sized just right so that the very instant the ferry is moored, it registers as being present in the zone.  (It seems that the ferry must be more than halfway into the zone before the game will notice it.)  The condition "Transport from group <name> belonging to player <color> has landed" must be used to properly time the embarkation order, although a looping trigger or a timer can be used as well.   

NOTE:  Both the ferry and the passengers need to be selected when the order is given.

Complicating matters further, the ferry needs to remain moored and stationary long enough for the units to embark.  Otherwise, fatal accidents and stranded passengers result (which, of course, you can always exploit as a plot feature if you wish).  Fortunately a condition exists to count the number of units on a ferry, which can serve as a signal to cast off.

Example:

- Ship to Shore

CONDITION:

      ALWAYS

ACTION:

      Deselect units of player <blue>.

      Select all units of group <FrenchFerry> by changing previous selection.

      Order selected units of player <blue> to go to zone <Mooring> saving waypoints, place them in direction 10.

 

- Embark

CONDITION:

      Number of units of group <FrenchFerry> in zone <Mooring> is more than 0.

      Transport from group <FrenchFerry> and belonging to player <blue> has landed.

ACTION:

      Deselect units of player <blue>.

      Select all units of group <FrenchMuskets> by changing previous selection.

      Select all units of group <FrenchFerry> by adding to previous selection.

      Embark selected units of player <blue> on selected transport.

 

- Departure

CONDITION:

      Number of units of group <FrenchFerry> in zone <Mooring> is more than 0.

      Number of passengers in transport of group <FrenchFerry> by player <blue> is more than 79.

ACTION:

      Select all units of group <FrenchFerry> by changing previous selection.

      Order selected units of player <blue> to go to zone <Destination> saving waypoints, place them in direction 95.

 

Finally, there's the small matter of landing the ferry again and disembarking units. 

 

- Arrival

CONDITION:

      Number of units of group <FrenchFerry> in zone <Destination> is more than 0.

      Transport from group <FrenchFerry> and belonging to player <blue> has landed.

ACTION:

      Select all units of group <FrenchFerry> by changing previous selection.

      Disembark all units from selected transport by player <blue>.
 

51.  What's a "response chain?"      

A response chain is a method of creating complex responses to simple conditions.  Several triggers can be used to create a coherent whole in ways not possible using one single trigger.  For example, how do you create an intelligent (programmed) response to a player whose forces can cross any combination of three bridges?  Attempting to do this with only one trigger produces unsatisfactory results, as it's too easy to "set" a reaction before all possible conditions are considered.  E.g. if the condition is "50 units in zone EastBridge," and the player sends 50 units to that zone -- and THEN 1000 to "WestBridge," your programmed player will be easily tricked into committing its forces to repel the ruse.  You need something that will "analyze" the situation (through a number of triggers) and then respond appropriately.

52.  How do I use a response chain?    

Response chains can rely heavily on the use of flags, and sometimes timers.  Say there are three conditions to be "considered" by the AI.  Each of these conditions can be used to set a flag.  Then, additional triggers can be used to define reactions based on which flags are set.  A timer is useful in regulating these responses, since it's pretty rare that all conditions will be met *exactly* at the same moment.  Another flag can be used to tell the game, "OK, I've made up my mind -- this is what we're going to do."  Otherwise, a response chain can behave unpredictably, based on new conditions being met after a response has been initiated.

NOTE:  Order of response triggers is very important with response chains.  The most complex set of conditions MUST be placed first!  Otherwise, a simpler condition will be selected by the game engine before it "realizes" that additional conditions apply.  E.g. a condition such as

CONDITION

      Flag <Zone1Flag> is on.

      Flag <Zone2Flag> is on.

      Flag <Zone3Flag> is on.

ACTION

      ...

 

must be placed before

CONDITION

      Flag <Zone1Flag> is on

ACTION

      ...

...otherwise, the game will respond to Zone1Flag being on *first* and skip all other possible responses!
 

53.  How do I disable upgrades?   

Unfortunately, the "Disable Upgrade" action does not work.  Also, while PeaceTime can be used in creating maps, other Start Options seem to have no effect on missions.  This makes it all but impossible to restrict upgrades for players.  The only means of doing this is by carefully controlling the resources a player has, so that the player simply can never afford the upgrade.   

Obviously this creates other problems, because the player might not be able to carry out upgrades you want him to!  The solution to this, of course, is to make upgrades available via other triggers... e.g. a Commander being present in a Zone centered at a faction's Academy.  Given how cumbersome this process can be, you should consider carefully how important "disabling" any particular upgrade is to your scenario.

To restrict a player's resources, you need to set up a loop which will reduce a resource below a certain threshold once that threshold is achieved.  For example, most countries' 18th century requires about 50,000 food.  To prevent a player from ever accruing that much food (and thus preventing the "Progress to 18th Century" upgrade ever being available in the Town Hall), try the following:

CONDITION

      Quantity of food by player <Red> is more than 49900

ACTION

      Set player <Red> 49800 of food.

      Activate Current Trigger.

 

NOTE:  As there will be a split second where the amount of food is higher than the threshold, it's a good idea to set that threshold a bit below the requisite for moving to the 18th century.  Otherwise, a quick player might be able to hit the button at just the right time... thus defeating the purpose of the trigger.

NOTE:  The threshold CANNOT be the same number as what the resource will be set to, as this will cause the game to crash.

54.  How do I prevent the AI from producing certain units?      

An action for this is available in "Operations on Units:" Disable production of units/buildings.  It actually works!

Note that the counterpart of this action, "Enable production of units/buildings," does NOT work for units not normally available to the player.  E.g. enabling production of Saxon Riders will do a player with only Algerian units no good whatsoever.

Example:

CONDITION

      Number of units of group <Shipwright> in zone <Shipyard> is less than 1.

ACTION

      Disable production of Ferry units for player <Red>.

      Disable production of Galley units for player <Red>.

      (etc.)