Results 1 to 19 of 19

Thread: A garrison script that incorporates the ‘destroy_units’ command

  1. #1

    Icon1 A garrison script that incorporates the ‘destroy_units’ command

    Making a garrison script that incorporates the ‘destroy_units’ command is not a new idea. So this is not a step-by-step tutorial, it is rather an illustration of the method of writing a garrison script that uses the ‘destroy_units’ command.

    The garrison script:
    Spoiler Alert, click show to read: 
    Code:
    ;###### Isengard Garrison Script: By TNZ and Withwnar #######
    ;###### For TA 3.1 #######
    
    declare_counter france_garrison
    
    ;###### Isengard Garrison Script: Local vs AI #######
    
    	monitor_event GeneralAssaultsResidence FactionIsLocal
    		and TargetFactionType france
    		and I_IsFactionAIControlled france
    		and IsTargetRegionOneOf Nan-Curunir_Province
        		and I_SettlementUnderSiege Nan-Curunir
    		create_unit Nan-Curunir, Garrison Orthanc Guard, num 4, exp 2, arm 0, wep 0
    		create_unit Nan-Curunir, Garrison Uruk-Hai Raiders, num 4, exp 2, arm 0, wep 0
    		create_unit Nan-Curunir, Garrison Uruk-Hai Archers, num 2, exp 0, arm 0, wep 0
    		set_counter france_garrison 1
    	end_monitor
    
    	monitor_event GeneralAssaultsResidence FactionIsLocal 
    		and TargetFactionType france
    		and I_IsFactionAIControlled france
    		and IsTargetRegionOneOf Dunland_Province
        		and I_SettlementUnderSiege Dunland
    		create_unit Dunland, Garrison Dunlendings, num 4, exp 0, arm 0, wep 0
    		create_unit Dunland, Garrison Dunlending Axemen, num 2, exp 0, arm 0, wep 0
    		set_counter france_garrison 1
    	end_monitor
    
    	monitor_event GeneralAssaultsResidence FactionIsLocal
    		and TargetFactionType france
    		and I_IsFactionAIControlled france
    		and IsTargetRegionOneOf Dunland-Hills_Province
        		and I_SettlementUnderSiege Dunland-Hills
    		create_unit Dunland-Hills, Garrison Dunlendings, num 4, exp 0, arm 0, wep 0
    		create_unit Dunland-Hills, Garrison Dunlending Axemen, num 2, exp 0, arm 0, wep 0
    		set_counter france_garrison 1
    	end_monitor
    
    ;###### Isengard Garrison Script: AI vs AI #######
    
    	monitor_event GeneralAssaultsResidence not FactionIsLocal
    		and TargetFactionType france
    		and I_IsFactionAIControlled france
    		and IsTargetRegionOneOf Nan-Curunir_Province
        		and I_SettlementUnderSiege Nan-Curunir
    		create_unit Nan-Curunir, Garrison Orthanc Guard, num 6, exp 2, arm 0, wep 0
    		create_unit Nan-Curunir, Garrison Uruk-Hai Raiders, num 6, exp 2, arm 0, wep 0
    		create_unit Nan-Curunir, Garrison Uruk-Hai Archers, num 4, exp 0, arm 0, wep 0
    		set_counter france_garrison 1
    	end_monitor
    
    	monitor_event GeneralAssaultsResidence not FactionIsLocal 
    		and TargetFactionType france
    		and I_IsFactionAIControlled france
    		and IsTargetRegionOneOf Dunland_Province
        		and I_SettlementUnderSiege Dunland
    		create_unit Dunland, Garrison Dunlendings, num 6, exp 0, arm 0, wep 0
    		create_unit Dunland, Garrison Dunlending Axemen, num 4, exp 0, arm 0, wep 0
    		set_counter france_garrison 1
    	end_monitor
    
    	monitor_event GeneralAssaultsResidence not FactionIsLocal
    		and TargetFactionType france
    		and I_IsFactionAIControlled france
    		and IsTargetRegionOneOf Dunland-Hills_Province
        		and I_SettlementUnderSiege Dunland-Hills
    		create_unit Dunland-Hills, Garrison Dunlendings, num 6, exp 0, arm 0, wep 0
    		create_unit Dunland-Hills, Garrison Dunlending Axemen, num 4, exp 0, arm 0, wep 0
    		set_counter france_garrison 1
    	end_monitor
    
    ;###### Isengard Garrison Script: Destroy France Garrison #######
    
    	monitor_event PostBattle IsRegionOneOf Nan-Curunir_Province, Dunland_Province, Dunland-Hills_Province
    		and I_CompareCounter france_garrison = 1
    		destroy_units france garrison_unit
    		set_counter france_garrison 0
    	end_monitor
    
    	monitor_event PreBattleWithdrawal IsRegionOneOf Nan-Curunir_Province, Dunland_Province, Dunland-Hills_Province
    		and I_CompareCounter france_garrison = 1
    		destroy_units france garrison_unit
    		set_counter france_garrison 0
    	end_monitor

    Because the script uses ‘GeneralAssaultsResidence’ as the ‘monitor_event’ ,there can only ever be one scripted Garrison on the map at any one time, removing the need to write an elaborate script that puts the scripted Garrison's back in settlements which are still under siege after you have use the ‘destroy_units’ command.

    There are two ‘monitor_event’ that handle destroying the units. The first one uses ‘PostBattle’: that one is pretty self-explanatory, that is, the units are destroyed after the battle. The second one uses ‘PreBattleWithdrawal’. If the player hits the assault button, but then decides to withdraw from the battle, the scripted Garrison is destroyed.

    You can find a working example and more information on the script here:
    http://www.twcenter.net/forums/showthread.php?t=513944

    I'd like to thank, Withwnar for helping with the units for the garrison script demonstration, and Gigantus for the idea of using ‘GeneralAssaultsResidence’ as the monitor event for a garrison script.

  2. #2
    Emperor of Hell's Avatar SPA-NED 1-5
    Join Date
    Jul 2011
    Location
    Netherlands
    Posts
    5,747

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    It looks very good. The only disadvantage of this garrison script is that it takes, if you create it for every faction, many unit slots. What happens when there are multiple garrison script settlements under siege at the same time? Are there side effects?

  3. #3
    Aikanár's Avatar no vaseline
    Join Date
    Mar 2009
    Location
    Sanctuary
    Posts
    12,516
    Blog Entries
    3

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    If I understand the script right, it fires for GeneralAssaultsResidence thus the garrison will only be created when one attack the settlement, not when it's just besieged. That's why TNZ wrote about the singularity of the garrison.

    Nice script TNZ


    Son of Louis Lux, brother of MaxMazi, father of Squeaks, Makrell, Kaiser Leonidas, Iskar, Neadal, Sheridan, Bercor and HigoChumbo, house of Siblesz

    Not everything that counts can be counted, and not everything that can be counted counts.

  4. #4

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    Indeed a clever script, in many better than the Settlement besieged alternative.

  5. #5
    EP!anastasi's Avatar Biarchus
    Join Date
    Jul 2008
    Location
    Athens, Greece
    Posts
    652

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    What happens in the case that with the addition of the garisson units to the existing units the total units are more than the max? Do the extra ones appear as reinforcements in the battle? And would the extra ones be those that were created last?
    Quote Originally Posted by 1988matej View Post
    <snip> i won't preorder to get the dacian's, wont pay for the elephant dlc nor will i settle for a dumbed down game <snip>
    "My garden may be smaller than your Rome, but my pilum is harder than your sternum!"

    a great song ... and one more ... ok, one last






    (\__/)
    ( O.o)
    (> < ) This is Bunny. Please help Bunny reach global domination by copying this message and pasting it to your own signature. Thank you!










    Fred Putz
    Quote Originally Posted by Fred Putz View Post
    Hmm - in my political spectrum Nazism is always on the extreme stupid wing.
    jimkatalanos

    Quote Originally Posted by jimkatalanos View Post
    Can someone delete this one temporarily?
    It's way too active and I am worried.
    Spoiler Alert, click show to read: 
    Taiji
    Quote Originally Posted by Taiji View Post
    Honestly there is no ceremony while I sacrifice stuff
    Garbarsardar
    Quote Originally Posted by Garbarsardar View Post
    <snip> the behaviour of moderators is a clear example of the corruption that absolute power brings to these hitherto innocent kids. Jom, Hesus, Ishan, Giga, were a merry bunch of fellows until the DeletePostDemon went into them and made them do the unthinkable. Praise the lord. And pass the bucket.
    ~Gort~
    Quote Originally Posted by ~Gort~ View Post
    Irony is one of the few saving graces of humanity.
    irelandeb
    Quote Originally Posted by irelandeb View Post
    What we understand is neglible compared to what we know we don't understand, never mind what we don't know we don't understand.
    Squid
    Quote Originally Posted by Squid View Post
    It won't help, people will believe what they want to believe even when presented with incontrovertible proof to the contrary.
    Magicman2051
    Quote Originally Posted by Magicman2051 View Post
    Clarifying, I don't disagree with what I quoted, I don't agree with it either.
    Aradan
    Quote Originally Posted by Aradan View Post
    You do make sense.

  6. #6
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    This script obviously requires additional units in the EDU. The best way to do this would be to restrict it to 3 units (one each sword\pike\missile). If you have drastically different cultures (European, middle-east) then you might need additional sets of 3 units each.










  7. #7

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    Quote Originally Posted by Gigantus View Post
    This script obviously requires additional units in the EDU. The best way to do this would be to restrict it to 3 units (one each sword\pike\missile). If you have drastically different cultures (European, middle-east) then you might need additional sets of 3 units each.
    If you're really pressed for unit entries you could use the armor_ug's to represent the different cultures.
    Since you are always creating them trough script it's easy to set and they use different battle models.

    Obviously this will mean that some have a higher quality than others.

  8. #8

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    How do you use destroy_units to destroy all units in a specific settlement?

  9. #9
    EP!anastasi's Avatar Biarchus
    Join Date
    Jul 2008
    Location
    Athens, Greece
    Posts
    652

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    Quote Originally Posted by The Uruk View Post
    How do you use destroy_units to destroy all units in a specific settlement?
    That's not exactly what this script does. As Gigantus said:
    Quote Originally Posted by Gigantus View Post
    This script obviously requires additional units in the EDU.
    So you create and destroy only those additional units, only in the attacked settlement.

    Quote Originally Posted by EP!anastasi View Post
    What happens in the case that with the addition of the garisson units to the existing units the total units are more than the max? Do the extra ones appear as reinforcements in the battle? And would the extra ones be those that were created last?
    The answer is you can't create more than the max units that can fit in a settlement, right?
    Quote Originally Posted by 1988matej View Post
    <snip> i won't preorder to get the dacian's, wont pay for the elephant dlc nor will i settle for a dumbed down game <snip>
    "My garden may be smaller than your Rome, but my pilum is harder than your sternum!"

    a great song ... and one more ... ok, one last






    (\__/)
    ( O.o)
    (> < ) This is Bunny. Please help Bunny reach global domination by copying this message and pasting it to your own signature. Thank you!










    Fred Putz
    Quote Originally Posted by Fred Putz View Post
    Hmm - in my political spectrum Nazism is always on the extreme stupid wing.
    jimkatalanos

    Quote Originally Posted by jimkatalanos View Post
    Can someone delete this one temporarily?
    It's way too active and I am worried.
    Spoiler Alert, click show to read: 
    Taiji
    Quote Originally Posted by Taiji View Post
    Honestly there is no ceremony while I sacrifice stuff
    Garbarsardar
    Quote Originally Posted by Garbarsardar View Post
    <snip> the behaviour of moderators is a clear example of the corruption that absolute power brings to these hitherto innocent kids. Jom, Hesus, Ishan, Giga, were a merry bunch of fellows until the DeletePostDemon went into them and made them do the unthinkable. Praise the lord. And pass the bucket.
    ~Gort~
    Quote Originally Posted by ~Gort~ View Post
    Irony is one of the few saving graces of humanity.
    irelandeb
    Quote Originally Posted by irelandeb View Post
    What we understand is neglible compared to what we know we don't understand, never mind what we don't know we don't understand.
    Squid
    Quote Originally Posted by Squid View Post
    It won't help, people will believe what they want to believe even when presented with incontrovertible proof to the contrary.
    Magicman2051
    Quote Originally Posted by Magicman2051 View Post
    Clarifying, I don't disagree with what I quoted, I don't agree with it either.
    Aradan
    Quote Originally Posted by Aradan View Post
    You do make sense.

  10. #10

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    Quote Originally Posted by EP!anastasi View Post
    That's not exactly what this script does. As Gigantus said:

    So you create and destroy only those additional units, only in the attacked settlement.


    The answer is you can't create more than the max units that can fit in a settlement, right?
    I understand that but I thought that people here would know as destroy_units is used in the script.

  11. #11
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    destroy_units needs an attribute from the EDU's attribute line (in this example) as definition, meaning that all units that have that attribute will be removed from the defined faction in the game. There is no "destroy_all_units in_this_ city"










  12. #12

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    Thanks,
    Is there a way to destroy all units in a city?

  13. #13
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    Quote Originally Posted by Gigantus View Post
    There is no "destroy_all_units in_this_ city"
    If you destroy units you destroy them faction wide, you cannot restrict it to settlements.










  14. #14
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    It's actually game-wide, so it will affect every faction.

  15. #15
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    Identifier: destroy_units
    Parameters: faction, attribute_or_type
    Description: Disbands all units in the faction's armies with the specified name or attribute.
    Sample use: destroy_units England free_upkeep_unit










  16. #16
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    Ah, my bad, thanks for correcting me

  17. #17
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    No problem, you will get your chance to return the favor...










  18. #18
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    Quote Originally Posted by EP!anastasi View Post
    What happens in the case that with the addition of the garisson units to the existing units the total units are more than the max? Do the extra ones appear as reinforcements in the battle? And would the extra ones be those that were created last?
    create_unit will only add as many units as the settlement can hold. If there are 2 slots free and create_unit is adding 3 then only 2 will be added. No spill-over onto an adjacent tile so no creation of a "reinforcement" army.

    However, attempting to create_unit more units than the settlement can hold seems to corrupt the free-slots logic of the settlement. It works the first time but the next time it fails with an error message along the lines of "there is no room for this unit", even if there is room. It can also affect normal recruitment (same error). I don't know if it always happens.

    Fortunately [console_command create_unit] does not suffer from this. So I'd recommend using...

    Code:
    console_command create_unit Nan-Curunir "Garrison Orthanc Guard" 4 2 0 0
    ...instead of...

    Code:
    create_unit Nan-Curunir, Garrison Orthanc Guard, num 4, exp 2, arm 0, wep 0
    EDIT: the error still appears in the log but it does not affect the settlement in the way that create_unit does. The error is: "err: cannot add unit(s) because the garrison already contains the maximum number of units".

    ~~~

    While attacking one of these garrisoned settlements I noticed something odd. The garrison units are not counted in the enemy's soldier count. (See attached.)

    The number is correct after viewing the enemy army details - which isn't always done by the player - but that seems to be the only place that does use the right number.

    The major concern, I think, is the percentage killed value. During battle it hit 100% when I had killed 75 soldiers and by the time I had killed 375 it was showing 500%. This would also pose a problem for anything else using "percent killed" in the game:
    - trait/anc triggers: awards for killing >x% of the enemy would be handed out more often than they should
    - battle AI: Germanicu5's uses I_PercentageOfArmyKilled as a trigger to do something
    - the game itself: I'm guessing that things such as the "only half of the enemy remains" voiceover are tied to the displayed %

    I wonder if it affects auto-resolve as well. i.e. Is the garrison ignored in battle outcome calculations, including AI-AI battles?

    Click image for larger version. 

Name:	DGS.jpg 
Views:	34 
Size:	107.5 KB 
ID:	294353
    Last edited by Withwnar; September 21, 2013 at 05:16 AM.

  19. #19
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: A garrison script that incorporates the ‘destroy_units’ command

    I wonder if it affects auto-resolve as well. i.e. Is the garrison ignored in battle outcome calculations, including AI-AI battles?
    Yes and no. It seems that the garrison is taken into account for player-vs-AI auto-resolve battles but ignored for AI-vs-AI ones.

    This was tested by creating massive auto-garrisons that attackers should not have won against, then sitting back and letting the AI try to capture settements as normal over a few turns. Settlements were captured all over the place. I know for a fact that some of the attacking armies were very small (I was watching them) so while it is possible that some attackers were actually stronger than the garrison, it is certain that not all of them were. Suggesting that the auto-garrisons were not counted in the AI-AI battles.

    The way I did not test it was by using script [siege_settlement...attack] because that does not trigger a GeneralAssaultsResidence event. Never knew that. Good to know.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •