The placement of units, Coded and Scripted - using various commands
A Guide to the placement of units, Coded and Scripted.
Here i am going to explain how to use two features in M2TW which I have not seen any mods use, and indeed neither are used in any Vanilla version of TW so far! I searched TWC and found no link to either of them anywhere, nothing! very odd.. But here they are after much trial and error!
One is;
Code:
garrisoned_army
unit "unit" exp 0 armour 0 weapon_lvl 0
unit "unit" exp 0 armour 0 weapon_lvl 0
unit "unit" exp 0 armour 0 weapon_lvl 0
Afterward, I will give an example on how to script a spawn of a navy, which many members have had questions about.
Using garrisoned_army in the descr_strat.txt ... ... ...
This will place specified units in the settlement as a garrison, no characters then are able to be placed within the settlement so make sure the x,y locations of your character do not correspond with the settlements location.
Although placing a garrisoned army and a placed character together will not cause a CTD or error, it will be near impossible to select the character to move him out of the settlement.
The usual limits apply here, only reference units available to the faction from the EDU, and only 20 units will fit. You may add exp and weapon/armour upgrades as well.
sample use;
Using sieging in the descr_strat.txt ... ... ...
First we wll start with a basic understanding of how to use a regular character entry;
The red parts are the key area’s to modify;
NOTE: Character traits and ancillaries are completely optional!
To utilize the sieging ability correctly you must place the army on a tile next to a settlement using the x,y coordinates - and use the, direction (N,E,S,W).
For Example; If the character was placed on the tile on the left side of the settlement, the direction will need to be direction E.
sample use;
Using sieging in the campaign_script.txt ... ... ...
(This took a while longer to discover).
First we will do a quick explanation of spawn_army command;
The red parts are the key area’s to modify;
Character name can be random_name to make things easier.
Character traits are optional again - ancillarie i have never tried, sorry..
family is optional too, it adds the character to the family tree.
, sub_faction faction_name is necessary for a slave faction army to spawn.
end is the part we are looking at to get sieging to work in the campaign_script.txt.
To make sieging work, simply replace end with sieging
NOTE: the x,y coordinates and the use of direction NSEW must be used properly.
NOTE2: the siege_equipment will never work in the campaign_script.txt - but we can get rams, ladders, ect to work (keep reading).
It seems simple at first, but many tests have been done and my conclusion is sound.
The only drawback is the AI will almost certainly every time will move the spawned army away and break the siege on their next turn.
To prevent such defiance we need to script a bit more. Let me introduce you to the siege_settlement command;
This command is used like this;
siege_settlement "Character name or label label_name", settlement name, [maintain|attack]
If our characters name was random_name, we wouldn't know his name - So we use the label. If my target was London, i would label this character 'Invade_London'.
example;
Code:
spawn_army
faction england
character random_name, named character, age 32, x 290, y 134, label Invade_London, direction N
unit unit_name exp 3 armour 1 weapon_lvl 0
unit unit_name exp 3 armour 1 weapon_lvl 0
unit unit_name exp 3 armour 1 weapon_lvl 0
unit unit_name exp 3 armour 1 weapon_lvl 0
sieging
siege_settlement Invade_London, London, maintain
Still this does not allow our spawned army to stay and attack, we need to provide a 'full' code and understand why we are coding in such a way.
The above code will spawn a character to lay siege to London and keep him there for the same turn he is spawned on.
I will now explain how to ensure the AI have seige equipment, stay, and attack.
For the siege equipment, you can add ballista, catapult, ect but it is not necessary.
I know the code above does not specify what siege equipment is to be used, and i am certain that there is no way to specify the equipment like we do in descr_strat, but the AI will build seige equipment if they are capable if the seiging army exists at the begining of their turn and is ordered to maintain the seige (as we did above).
The minimum seige equipment i have seen using this method (4 units) is 1 x ram and 1 x ladder - pretty efficient!
So we will make a code to spawn the seiging army at the beginning of a turn, order it maintain, then at the end of the defender's turn order the attack (granted the seiging army is still there and the defender didn't fend them off already).
Code:
monitor_event FactionTurnStart FactionType england
and I_SettlementOwner London = france
and not I_CharacterExists Invade_London
spawn_army
faction england
character random_name, named character, family, age 32, x 290, y 134, label Invade_London, direction N
unit NE bodyguard exp 0 armour 1 weapon_lvl 0
unit Levy Spearmen exp 0 armour 1 weapon_lvl 0
unit Levy Spearmen exp 0 armour 1 weapon_lvl 0
unit Levy Spearmen exp 0 armour 1 weapon_lvl 0
sieging
siege_settlement Invade_London, London, maintain
end_monitor
monitor_event FactionTurnEnd FactionType france
and I_CharacterExists Invade_London
and I_SettlementOwner London = france
and I_SettlementUnderSiege London
siege_settlement Invade_London, London, attack
end_monitor
Not too difficult - Its just a matter of choosing the correct events.
If the player is england they'll get one opportunity to build seige equipment and attack.
If the player is france they'll get one opportunity to break the seige by attacking or they'll be attacked by the army who has siege equipment ready.
If both are AI it works exactly as intended in the script.
It all happens in one turn also which is great, quick results!
The final step, to make this complex and more like a proper siege.
At the end of this we will be able to make this spawned army wait another 2 turns after being spawned then attack, with the entire stack replenished.
First lets check if the spawned character is still alive, if he is alive we check if he succeeded in the attack, if the settlement is not taken we check if he is still sieging or not, if he is not sieging we move him back and tell him to lay siege again.
Code:
monitor_event FactionTurnStart FactionType england
and not I_SettlementOwner London = england
and I_CharacterExists Invade_London
if I_SettlementUnderSiege London
siege_settlement Invade_London, London, maintain
replenish_units Invade_London
end_if
if not I_SettlementUnderSiege London
reposition_character Invade_London, 290, 134
siege_settlement Invade_London, London, maintain
replenish_units Invade_London
end_if
end_monitor
Finally to ensure the army stays and attacks on the second turn we need to use a counter and increment it each turn.
This is the full code using all the features described above;
Code:
declare_counter delayattack001
monitor_event FactionTurnStart FactionType england
and I_SettlementOwner London = france
and not I_CharacterExists Invade_London
spawn_army
faction england
character random_name, named character, family, age 32, x 290, y 134, label Invade_London, direction N
unit NE bodyguard exp 0 armour 1 weapon_lvl 0
unit Levy Spearmen exp 0 armour 1 weapon_lvl 0
unit Levy Spearmen exp 0 armour 1 weapon_lvl 0
unit Levy Spearmen exp 0 armour 1 weapon_lvl 0
sieging
siege_settlement Invade_London, London, maintain
set_counter delayattack001 1
end_monitor
monitor_event FactionTurnStart FactionType england
if not I_SettlementOwner London = england
and I_CharacterExists Invade_London
if I_SettlementUnderSiege London
and I_CompareCounter delayattack001 = 1
siege_settlement Invade_London, London, maintain
replenish_units Invade_London
inc_counter delayattack001 1
end_if
if not I_SettlementUnderSiege London
and I_CompareCounter delayattack001 = 1
reposition_character Invade_London, 290, 134
siege_settlement Invade_London, London, maintain
replenish_units Invade_London
inc_counter delayattack001 1
end_if
if I_SettlementUnderSiege London
and I_CompareCounter delayattack001 > 1
siege_settlement Invade_London, London, attack
replenish_units Invade_London
inc_counter delayattack001 1
end_if
if not I_SettlementUnderSiege London
and I_CompareCounter delayattack001 > 1
reposition_character Invade_London, 290, 134
siege_settlement Invade_London, London, attack
replenish_units Invade_London
inc_counter delayattack001 1
end_if
end_if
if I_SettlementOwner London = england
and I_CompareCounter delayattack001 > 0
set_counter delayattack001 0
end_if
end_monitor
Spawning a navy through scripts ... ... ...
I would also like to explain how i spawn a navy, a few people didn't think it was possible, i'll explain how;
For a naval spawn we use;
Code:
spawn_army
faction england
character random_name, admiral, age 49, x 199, y 97
unit "vessel name" exp 0 armour 0 weapon_lvl 0
unit "vessel name" exp 0 armour 0 weapon_lvl 0
unit "vessel name" exp 0 armour 0 weapon_lvl 0
end
Just be sure that the chosen tile is a sea tile, and the "vessel name" corresponds with a valid ship in the EDU and this will work fine.
I think the main issue for people was missing the admiral part, but that is strange because we have always been able to spawn in priests, spy's, assassins, ect and this is only different because the admiral has vessels attached to him so we use spawn_army instead of spawn_character..
EDIT:
Spawning an agent through scripts ... ... ...
I also want to share some simple character spawns, as discussed above, we can spawn in agents using the simple version of the code & lets give them some traits;
Code:
spawn_character faction, name, agent, age 18, x 397, y 339
console_command give_trait name trait 1
faction = self explanatory - check descr_sm_factions.txt
name = Could be 'random_name' - check descr_names.txt
agent = priest, assassin, merchant - check descr_character.txt
trait = GoodSpy, GoodAssassin, GoodDiplomat - export_descr_character_traits.txt
1 = the level for the trait, for example good spy lvl4 which is Adept_Spy would look like "GoodSpy 4" and not actually have Adept_Spy shown.
Lets do a few scripts;
Spoiler Alert, click show to read:
Code:
spawn_character england, Dan, spy, age 18, x 198, y 56
console_command give_trait Dan GoodSpy 4
console_command give_trait Dan GoodConspirator 1
Code:
spawn_character england, Brian, assassin, age 27, x 8, y 206
console_command give_trait Brian GoodAssassin 3
console_command give_trait Brian GoodConspirator 1
Code:
spawn_character england, Stu, diplomat, age 21, x 240, y 142
console_command give_trait Stu GoodDiplomat 5
console_command give_trait Stu Secretive 2
Code:
spawn_character england, Arth, merchant, age 35, x 211, y 28
console_command give_trait Arth GoodMerchant 1
console_command give_trait Arth NaturalMerchantSkill 3
Code:
spawn_character england, Vic, priest, age 24, x 76, y 81
console_command give_trait Vic NaturalPriestSkill 3
console_command give_trait Vic TheologiansGuildMember 1
Code:
spawn_character england, Liz, princess, age 17, x 29, y 68
console_command give_trait Liz FaithfulWoman 1
console_command give_trait Liz PrettyWoman 2
I hope you all enjoyed this tutorial
Thank you
~Archaon
Last edited by Archaon; September 15, 2009 at 07:16 AM.
Awesome! A week earlier and it would have saved me a couple of headaches. +rep
Quick question:
This entry "siege_equipment sap_point 1" will not cause an error in a mod? Sapping is no longer available in medieval2.
Hmm: you sure? I must admit i dont recall seeing a sap in battle, but the code exists in descr_sm_factions to allow or dis-allow sap ability.. and the game recognizes the siege_equipment sap_point 1
EDIT: What is really curious to me was to make sieging work, I simply replaced end with sieging.
Can you think of anything else we could try to replace end with?
Last edited by Archaon; September 14, 2009 at 12:24 AM.
Re: The placement of units, Coded and Scripted. ## Using commands 'garrisoned_army / spawn_army' with siege_equipment! ## Also, How to spawn a navy through scripts! ##
Very interesting. I think we need a new sticky in the Text Editing & Scripting area here listing scripting command tutorials, because your signature can only get so long(and linking to that from the main index, but don't throw em all in there)! Chop chop moderator!
I will do a test of this, since I had planned to use a similar function but obviously it wouldn't have been quite as concise when we needed the move commands, and report results here.
Re: The placement of units, Coded and Scripted. ## Using commands 'garrisoned_army / spawn_army' with siege_equipment! ## Also, How to spawn a navy through scripts! ##
Originally Posted by Augustus Lucifer
Very interesting. I think we need a new sticky in the Text Editing & Scripting area here listing scripting command tutorials, because your signature can only get so long(and linking to that from the main index, but don't throw em all in there)! Chop chop moderator!
I will do a test of this, since I had planned to use a similar function but obviously it wouldn't have been quite as concise when we needed the move commands, and report results here.
PM me to discuss idea's on how we are going to make the new sticky and make a good list of threads. BTW I'm >Junior mod< and initiative is not my strong point (yet )
Fell free to post all your findings in this thread that relate to the title or we'll find a better place to report the results. if all else fails, make a new thread and we'll ad it to the sticky
Re: The placement of units, Coded and Scripted. ## Using commands 'garrisoned_army / spawn_army' with siege_equipment! ## Also, How to spawn a navy through scripts! ##
Archaon,
Your scripting discoveries continue to astound. Good work guvnor! I will now do 256 new events pictures before breakfast just to celebrate. :o) Good luck with further script innoviation.
Re: The placement of units, Coded and Scripted. ## Using commands 'garrisoned_army / spawn_army' with siege_equipment! ## Also, How to spawn a navy through scripts! ##
character name, named character, male, leader, age 84, x 239, y 128, portrait portrait_name, label label_name, battle_model battle_model_name
i can't seem to understand what are the label code for
i saw it in Kingdoms campaign_script, but i don't understand what it is for...
Re: The placement of units, Coded and Scripted. ## Using commands 'garrisoned_army / spawn_army' with siege_equipment! ## Also, How to spawn a navy through scripts! ##
Originally Posted by Swagger
i can't seem to understand what are the label code for
i saw it in Kingdoms campaign_script, but i don't understand what it is for...
Here i used a short explanation;
Originally Posted by Archaon
If our characters name was random_name, we wouldn't know his name - So we use the label. If my target was London, i would label this character 'Invade_London'.
I am not the best person to explain all its uses, but is it a great little feature that allows us to script commands for a character if the name is unknown.
For example, we can spawn in random named generals and agents.
If we do not know the name, then how would you script an attack command or give_trait or reposition_character.. ect ect?? We use 'label' to reference a character we do not know the name of.
I labeled my character 'Invade_London' because that is what i want him to do, but the label can be anything, in another mod i used 'Elf1'.. the label can be anything you want. regardless of the label, your character can be given a name, or a random name, and still the label can be used.
Think of the label as the actual characters name, but remember that each label can only be used once, every new label must be unique.
So be careful of duplication when you replicate your scripts.
Last edited by Archaon; September 14, 2009 at 04:48 AM.
Re: The placement of units, Coded and Scripted. ## Using commands 'garrisoned_army / spawn_army' with siege_equipment! ## Also, How to spawn a navy through scripts! ##
that would also work to kill him?
Code:
console_command kill_character label1
basicly when we don't know the character name, the label will work as a replace?
basicly when we don't know the character name, the label will work as a replace?
I am not sure if a 'console command' would recognize a label in place of a Name, However regular commands and conditions definitely recognize labels.
try it and report here
EDIT:
was just playing around more on this, trying to spawn a general with an ancillary.. Not happening.
But i found a work around - Make a new trait that has no trigger, Have the trigger for the ancillary that the character has that new trait - Spawn the character in with the new trait and he'll get that ancillary!
Last edited by Archaon; September 14, 2009 at 05:48 AM.
Re: The placement of units, Coded and Scripted. ## Using commands 'garrisoned_army / spawn_army' with siege_equipment! ## Also, How to spawn a navy through scripts! ##
Originally Posted by Swagger
that would also work to kill him?
Code:
console_command kill_character label1
basicly when we don't know the character name, the label will work as a replace?
Check the following:
Originally Posted by Agis Tournas
(Tested and working)
monitor_event FactionTurnStart FactionIsLocal
and I_TurnNumber = 10
if I_LocalFaction elo
kill_character BAUDOUIN4
end_if
end_monitor
console_command is not needed for the command kill_character. BAUDOUIN4 is the label I use in my games, for BAUDOUIN IV of Jerusalem in the descr_strat.txt
NOTE: labelmeans that in descr_strat.txt (at the imperial_campaign folder of your game installation) your faction leader (Baudouin IV of Jerusalem) should look like this: character BAUDOUIN_IV of Jerusalem, named character, male, leader, age 16, x 189, y 261 , label BAUDOUIN4
Hope to have been useful Agis
A mini-mod is never late! Nor is it ever early. It arrives precisely when I mean it to do! Son of Agisilaos / Grandson of jimkatalanos / Great-grandson of Garbarsardar
Re: The placement of units, Coded and Scripted. ## Using commands 'garrisoned_army / spawn_army' with siege_equipment! ## How to spawn a navy through scripts! ## How to spawn an agent through scripts
Awesome work Archaon, +rep, i was wondering how do i know the label of my character? that is something i never knew how to set up.
Re: The placement of units, Coded and Scripted. ## Using commands 'garrisoned_army / spawn_army' with siege_equipment! ## How to spawn a navy through scripts! ## How to spawn an agent through scripts
You pick your own label, how does 'icedie' sound?
gigantus, named_character, male, leader, age 84, x 239, y 128, portrait portrait_name, label icedie
Re: The placement of units, Coded and Scripted. ## Using commands 'garrisoned_army / spawn_army' with siege_equipment! ## How to spawn a navy through scripts! ## How to spawn an agent through scripts
:hmm so this line in descr_strat does have nothing to do with it?
Code:
faction east_anglia, balanced smith
ai_labeldefault
denari 20000
denari_kings_purse 2000
settlement
and is there another file that need the label to be placed in?
Re: The placement of units, Coded and Scripted. ## Using commands 'garrisoned_army / spawn_army' with siege_equipment! ## How to spawn a navy through scripts! ## How to spawn an agent through scripts
It is just that: a label that is used for the AI. It is referenced in descr_campaign_ai_db.xml.
Re: The placement of units, Coded and Scripted. ## Using commands 'garrisoned_army / spawn_army' with siege_equipment! ## How to spawn a navy through scripts! ## How to spawn an agent through scripts
There are several types of 'labels'.
One that an AI set marries to the entry in the descr_campaign_ai_db.xml.
Another that is used for scripting language.
In this thread we are only talking about the scripting language.
Re: The placement of units, Coded and Scripted. ## Using commands 'garrisoned_army / spawn_army' with siege_equipment! ## How to spawn a navy through scripts! ## How to spawn an agent through scripts
Originally Posted by Archaon
There are several types of 'labels'.
In this thread we are only talking about the scripting language.
Ah, i see thanks for clearing that up mate!! i thought they both were related!!
By this you mean the label can be any name ? in that case what is the point of it then?
what versions of the game (reg/King) and patch did you test these scripts on?
Good summary.
(S)
M2TW-K GOLD (And i have tested for the M2 exe as well)
Thats 1.5 for the M2TW and 1.6 for K right?
Originally Posted by Icedie of South
Ah, i see thanks for clearing that up mate!! i thought they both were related!!
By this you mean the label can be any name ? in that case what is the point of it then?
As I explained, the label is most important for when we do not know the actual name of the character. without a name for the character we want to move or whatever cannot script to that character, and the label is our savior.