Page 1 of 4 1234 LastLast
Results 1 to 20 of 79

Thread: Is this script right?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Is this script right?

    I found this in the campaign_script of my Third Age 1.4.1 install:

    Spoiler Alert, click show to read: 

    ;########################## AI morale bonus ############################
    monitor_event FactionTurnStart FactionIsLocal
    and I_TurnNumber = 0
    and BattleDifficulty = hard
    set_event_counter difficulty_hard 1
    terminate_monitor
    end_monitor

    monitor_event FactionTurnStart FactionIsLocal
    and I_TurnNumber = 0
    and BattleDifficulty = very_hard
    set_event_counter difficulty_very_hard 1
    terminate_monitor
    end_monitor

    set_event_counter is_the_ai 0

    monitor_event PreFactionTurnStart FactionIsLocal
    set_event_counter is_the_ai 0
    end_monitor

    monitor_event PreFactionTurnStart not FactionIsLocal
    set_event_counter is_the_ai 1
    end_monitor



    Is the first "set_event_counter is_the_ai 0" extraneous? It's after the "end_monitor" part, so what does it do? As far as I can tell, this is the original file of the mod.

  2. #2

    Default Re: Is this script right?

    If I had to guess what the logic was there, I'd say that he was just setting the default value to 0. Not sure whether or not it's necessary.

  3. #3

    Icon1 Re: Is this script right?

    The game reads it as a one-off command, to set that event counter to zero. It's worth mentioning that the default value of an event counter (or non-event counter) is in fact zero. So that line is pretty pointless.

  4. #4
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Is this script right?

    That line on it's own would appear an oversight as it's setting is completely covered by the two following monitors. Maybe a leftover from coding...










  5. #5

    Default Re: Is this script right?

    Ok, thanks, guys! In other campaign_script files that had the subsequent two monitors, that line didn't appear, so I was wondering.

  6. #6

    Default Re: Is this script right?

    In this thread http://www.twcenter.net/forums/showthread.php?t=344341, TNZ posted this script:

    Spoiler Alert, click show to read: 

    declare_counter has_garrison_unit monitor_event FactionTurnStart FactionType milan and IsFactionAIControlled if I_UnitExists scotland Garrison Sword set_counter has_garrison_unit 1 end_if if I_UnitExists scotland Garrison Spear set_counter has_garrison_unit 1 end_if if I_UnitExists scotland Garrison Bow set_counter has_garrison_unit 1 end_if I_CompareCounter has_garrison_unit = 1 destroy_units scotland garrison_unit set_counter has_garrison_unit 0 end_monitor




    I want to modify the garrison script included in TATW 1.4.1 as follows:

    1) Clone some of the units in the EDU and give the clones the garrison_unit attribute
    2) Add a script in the campaign_script that destroys the units with garrison_unit after a siege so the faction that was attacked cannot use those units to counterattack

    Here's how the script creates units:

    Spoiler Alert, click show to read: 

    monitor_event ButtonPressed ButtonPressed siege_maintain_button

    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege < 1
    and I_CompareCounter Anorien_Local = 0
    while I_CompareCounter PT < 1
    if I_CompareCounter Anorien_Defense = 11
    create_unit Anorien, Gondor Spearmen, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Militia Archers, num 1, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 10
    end_if
    if I_CompareCounter Anorien_Defense = 12
    create_unit Anorien, Gondor Spearmen, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Militia Archers, num 1, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 10
    end_if
    if I_CompareCounter Anorien_Defense = 21
    create_unit Anorien, Gondor Spearmen, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Militia Archers, num 1, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 10
    end_if
    if I_CompareCounter Anorien_Defense = 22
    create_unit Anorien, Gondor Spearmen, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Militia Archers, num 1, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 10
    end_if
    end_while
    end_if


    How should the script that destroys the units be written?

    Spoiler Alert, click show to read: 

    monitor_event FactionTurnStart FactionType sicily
    if not I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege > 0
    and I_CompareCounter Anorien_Local = 0
    destroy_units Anorien garrison_unit

    end_monitor


    I'm not sure about that > 0 part. Is it still necessary? I'm also not sure if you can target a specific settlement like that, but I don't want all the units with the garrison_unit attribute to be destroyed in all settlements owned by Gondor at the same time in case some of them are still under siege.

    What's the difference between "I_CompareCounter Anorien_Local = 0" and "IsFactionAIControlled"?

    I will attach the whole garrison script in case it helps.

    Hmm, I see TNZ's script came out garbled, but you can see it in post #7 in the link.
    Last edited by k/t; December 02, 2012 at 08:51 PM.

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

    Default Re: Is this script right?

    destroy_units takes a faction as its first parameter, not a settlement. It destroys all units of that type/attribute within the faction; not possible to destroy only some of them, e.g. in one settlement.

  8. #8

    Default Re: Is this script right?

    Crap. So I'd have to do this

    Spoiler Alert, click show to read: 


    monitor_event FactionTurnStart FactionType sicily
    if not I_SettlementUnderSiege Anorien
    and not I_SettlementUnderSiege Belfalas
    and not I_SettlementUnderSiege Cair-Andros
    and not I_SettlementUnderSiege Lebennin
    and not I_SettlementUnderSiege West_Lebennin
    and not I_SettlementUnderSiege Osgiliath-West
    and not I_SettlementUnderSiege Lossarnach
    and I_SettlementOwner Anorien = sicily
    and I_SettlementOwner Belfalas = sicily
    and I_SettlementOwner Cair-Andros = sicily
    and I_SettlementOwner Lebennin = sicily
    and I_SettlementOwner West_Lebennin = sicily
    and I_SettlementOwner Osgiliath-West = sicily
    and I_SettlementOwner Lossarnach = sicily
    and I_CompareCounter Anorien_Siege > 0
    and I_CompareCounter Anorien_Local = 0
    and I_CompareCounter Belfalas_Siege > 0
    and I_CompareCounter Belfalas_Local = 0
    and I_CompareCounter Cair-Andros_Siege > 0
    and I_CompareCounter Cair-Andros_Local = 0
    and I_CompareCounter Lebennin_Siege > 0
    and I_CompareCounter Lebennin_Local = 0
    and I_CompareCounter West_Lebennin_Siege > 0
    and I_CompareCounter West_Lebennin_Local = 0
    and I_CompareCounter Osgiliath_West_Siege > 0
    and I_CompareCounter Osgiliath_West_Local = 0
    and I_CompareCounter Lossarnach_Siege > 0
    and I_CompareCounter Lossarnach_Local = 0
    destroy_units sicily garrison_unit

    end_monitor


    But that would mean that if Gondor loses one of its garrison script settlements, the garrison units will no longer be destroyed, since the destroy script will check to see if Gondor has them all. How can I make the game destroy the garrison units only if none of the garrison script settlements still belonging to Gondor are under siege, regardless of whether some have been captured or not?

    Any ideas about this -> What's the difference between "I_CompareCounter Anorien_Local = 0" and "IsFactionAIControlled"?

    And this -> and I_CompareCounter Anorien_Siege > 0? What does that do? I think there was another part of the script that was related to it.

  9. #9

    Icon1 Re: Is this script right?

    k/t: That method I suggested in the thread you are linking I found on further examination to be flawed for a couple of reasons, one of which you have discovered.

    Therefore, I would suggest this method instead:
    Spoiler Alert, click show to read: 
    Code:
    ;###### Isengard Garrison Script #######
    ;###### 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

    What makes this method so much more useful is that it treats every siege as a separate event, removing the need to check whether a city is still under siege. Furthermore, because each siege is now a separate event you can use the ‘destroy units’ command without worrying if you’re destroying another city’s garrison.

    If memory serves, that original garrison script used in Third Age mod was written by Tsarsies, and it was originally designed to do the exact thing you want to do with it. However, it was never fully implemented. That’s why it looks a little overly complicated.

    I should mention, with this different method, that the garrison units are not spawned when the city is initially siege but when it’s assaulted. This isn’t a problem because a human player can still withdraw from the battle and the Garrison units will still be destroyed. Also, I don’t think that this method affects the AI in the slightest.

  10. #10

    Default Re: Is this script right?

    Ah, ok, thanks. Would you mind posting your entire garrison script?

    The problem with your way is that the garrison_units won't lose men during the siege, but I can try it.

    One way I thought of is making a set of clone units for each city and then the destroy_units script would only remove the garrison_units of the cities that are no longer besieged.

    If there are already 15 units in the settlement and the script calls for the creation of 6 Guards of the Orthanc, 6 Uruk-Hai Raiders and 2 Uruk-Hai archers, the script will only make 5 Guards of the Orthanc, right?

    What about the extra stuff in the script I uploaded? There are some parts to ensure there are no multiple garrison spawns during the same siege and various other things I don't understand. I will ask Tsarsies if it's indeed his script and if he remembers what it does.
    Last edited by k/t; December 05, 2012 at 02:23 AM.

  11. #11

    Default Re: Is this script right?

    I just had a look at the campaign_script of TATW 3.2 and it doesn't look like that. They must have changed it.

    If it says "GeneralAssaultsSettlement", will it work for captains too?

    At what point does "PreBattleWithdrawal" kick in? When the attacker abandons the siege?

    Would it be possible to make the script check every settlement with a garrison script and add 1 to a counter for every such settlement that is besieged and then destroy the garrison units only if the counter is 0? This is what I cobbled together:

    Spoiler Alert, click show to read: 

    declare_counter ongoing_siege_gondor
    declare_counter ongoing_siege_rohan
    declare_counter ongoing_siege_dwarves
    [etc]

    monitor_event PreFactionTurnStart IsFactionAIControlled
    set_counter ongoing_siege_gondor 0

    monitor_event FactionTurnStart IsRegionOneOf Anorien <- how can I make it check only for AI factions here?
    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege > 1
    and I_CompareCounter Anorien_Local = 0

    inc_counter ongoing_siege_gondor 1
    end_if

    monitor_event FactionTurnStart IsRegionOneOf Cair_Andros
    if I_SettlementUnderSiege Cair_Andros
    and I_SettlementOwner Cair_Andros = sicily
    and I_CompareCounter Cair_Andros_Siege > 1
    and I_CompareCounter Cair_Andros_Local = 0

    inc_counter ongoing_siege_gondor 1
    end_if

    monitor_event FactionTurnStart IsRegionOneOf Belfalas
    if I_SettlementUnderSiege Belfalas
    and I_SettlementOwner Belfalas = sicily
    and I_CompareCounter Belfalas_Siege > 1
    and I_CompareCounter Belfalas_Local = 0

    inc_counter ongoing_siege_gondor 1
    end_if

    end_monitor

    monitor_event FactionTurnEnd IsFactionAIControlled
    and I_CompareCounter ongoing_siege_gondor = 0
    destroy_units sicily garrison_unit

    end_monitor


    Then I could make a script like that for every faction.

    Hmm, could I just do this (relating to my question in bold in the script above):

    Spoiler Alert, click show to read: 

    monitor_event FactionTurnStart IsFactionAIControlled
    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege > 1
    and I_CompareCounter Anorien_Local = 0

    inc_counter ongoing_siege_gondor 1
    end_if


    This part "if I_SettlementUnderSiege Anorien" will make the script check to see if Anorien is under siege anyway, no? This way I can make the script run only for the AI and decrease turn time. What do you think? Will it work?
    Last edited by k/t; December 10, 2012 at 02:35 AM.

  12. #12
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Is this script right?

    monitor_event FactionTurnStart IsRegionOneOf Anorien <- how can I make it check only for AI factions here?
    if I_SettlementUnderSiege Anorien

    The above checks if it is the Anorien region and if Anorien is under siege - kinda double checking...
    Use 'monitor_event FactionTurnStart not FactionIsLocal'










  13. #13

    Default Re: Is this script right?

    The garrison script in the campaign_script of TA 1.4 uses "not FactionIsLocal". The script of TA 3.2 uses "IsFactionAIControlled". What's the difference?

    I have this in the campaign_script:

    Spoiler Alert, click show to read: 
    ;############################ BARRACK REFORM EVENT 6 SCRIPT ###############################

    monitor_event FactionTurnStart FactionIsLocal
    and I_TurnNumber = 0
    add_events
    event counter gamenotes_accepted
    event counter gamenotes_declined
    date 0
    end_add_events
    historic_event gamenotes true
    terminate_monitor
    end_monitor

    monitor_conditions I_EventCounter gamenotes_accepted = 1
    set_event_counter large_city_barracks 0
    set_event_counter huge_city_barracks 0
    terminate_monitor
    end_monitor

    monitor_conditions I_EventCounter gamenotes_declined = 1
    set_event_counter large_city_barracks 1
    set_event_counter huge_city_barracks 1
    terminate_monitor
    end_monitor

    monitor_event PreFactionTurnStart FactionIsLocal
    and I_TurnNumber = 32
    and I_EventCounter large_city_barracks = 0
    set_event_counter large_city_barracks 1
    historic_event large_city_barracks
    terminate_monitor
    end_monitor

    monitor_event PreFactionTurnStart FactionIsLocal
    and I_TurnNumber = 55
    and I_EventCounter huge_city_barracks = 0
    set_event_counter huge_city_barracks 1
    historic_event huge_city_barracks
    terminate_monitor
    end_monitor


    If I want to make the units spawned by the garrison script depend on which units have been unlocked so far by the barracks events, could I do this:

    Spoiler Alert, click show to read: 
    monitor_event ButtonPressed ButtonPressed siege_maintain_button

    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege < 1
    and I_CompareCounter Anorien_Local = 0
    and event_counter large_city_barracks = 0
    and event_counter huge_city_barracks = 0

    while I_CompareCounter PT < 1
    create_unit Anorien, Gondor Spearmen Mercs, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers Mercs, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Trebuchet, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm Mercs, num 2, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 5
    end_while
    end_if

    monitor_event ButtonPressed ButtonPressed siege_maintain_button

    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege < 1
    and I_CompareCounter Anorien_Local = 0
    and event_counter large_city_barracks = 1
    and event_counter huge_city_barracks = 0

    while I_CompareCounter PT < 1
    create_unit Anorien, Gondor Spearmen Mercs, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers Mercs, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Infantry Mercs, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Trebuchet, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm Mercs, num 2, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 5
    end_while
    end_if

    monitor_event ButtonPressed ButtonPressed siege_maintain_button

    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege < 1
    and I_CompareCounter Anorien_Local = 0
    and event_counter large_city_barracks = 1
    and event_counter huge_city_barracks = 1

    while I_CompareCounter PT < 1
    create_unit Anorien, Gondor Spearmen Mercs, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers Mercs, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Infantry Mercs, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Kingsguard, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Fountain Guard, num 1, exp 0, arm 0, wep 0

    create_unit Anorien, Gondor Trebuchet, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm Mercs, num 2, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 5
    end_while
    end_if


    ?

  14. #14
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Is this script right?

    They both test the same, but the second one can be used in conjunction with "if" whereas the first cannot.

    Test for the event that 'unlocks' the units, eg "if I_EventCounter [UnitUnlockEvent] = 1"










  15. #15

    Default Re: Is this script right?

    But you said to use "not FactionIsLocal".

    So the entry should be like this? :
    Spoiler Alert, click show to read: 

    monitor_event ButtonPressed ButtonPressed siege_maintain_button

    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege < 1
    and I_CompareCounter Anorien_Local = 0
    while I_CompareCounter PT < 1
    if event_counter large_city_barracks = 0
    if event_counter huge_city_barracks = 0

    create_unit Anorien, Gondor Spearmen Mercs, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers Mercs, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Trebuchet, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm Mercs, num 2, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 5
    end_while
    end_if

    monitor_event ButtonPressed ButtonPressed siege_maintain_button

    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege < 1
    and I_CompareCounter Anorien_Local = 0
    if event_counter large_city_barracks = 1
    if event_counter huge_city_barracks = 0

    while I_CompareCounter PT < 1
    create_unit Anorien, Gondor Spearmen Mercs, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers Mercs, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Infantry Mercs, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Trebuchet, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm Mercs, num 2, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 5
    end_while
    end_if

    monitor_event ButtonPressed ButtonPressed siege_maintain_button

    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege < 1
    and I_CompareCounter Anorien_Local = 0
    if event_counter large_city_barracks = 1
    if event_counter huge_city_barracks = 1

    while I_CompareCounter PT < 1
    create_unit Anorien, Gondor Spearmen Mercs, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers Mercs, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Infantry Mercs, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Kingsguard, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Fountain Guard, num 1, exp 0, arm 0, wep 0

    create_unit Anorien, Gondor Trebuchet, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm Mercs, num 2, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 5
    end_while
    end_if
    Last edited by k/t; December 26, 2012 at 10:14 PM.

  16. #16

    Default Re: Is this script right?

    What is the best way to arrange this script?

    Version 1:
    Spoiler Alert, click show to read: 

    monitor_event PreFactionTurnStart not FactionIsLocal
    and FactionType sicily
    set_counter ongoing_siege_gondor 0
    end_monitor

    monitor_event FactionTurnStart not FactionIsLocal
    and FactionType sicily
    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege > 1
    and I_CompareCounter Anorien_Local = 0

    inc_counter ongoing_siege_gondor 1
    end_if


    Version 2:
    Spoiler Alert, click show to read: 

    monitor_event PreFactionTurnStart FactionType sicily
    if I_EventCounter is_the_ai 1
    set_counter ongoing_siege_gondor 0
    end_monitor

    monitor_event FactionTurnStart FactionType sicily
    and I_EventCounter is_the_ai 1
    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege > 1
    and I_CompareCounter Anorien_Local = 0

    inc_counter ongoing_siege_gondor 1
    end_if


    Version 3
    Spoiler Alert, click show to read: 

    monitor_event PreFactionTurnStart FactionType sicily
    and not FactionIsLocal
    set_counter ongoing_siege_gondor 0
    end_monitor

    monitor_event FactionTurnStart FactionType sicily
    and not FactionIsLocal
    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege > 1
    and I_CompareCounter Anorien_Local = 0

    inc_counter ongoing_siege_gondor 1
    end_if

    In any case, I can scrap "and I_CompareCounter Anorien_Local = 0" because it's covered by either "not FactionIsLocal" or "and I_EventCounter is_the_ai 1".

    When should I use "not FactionIsLocal" and when should I use "IsFactionAIControlled"? Gigantus gave me contradictory information (or I didn't understand it well).

    Also, is this correct:
    Spoiler Alert, click show to read: 

    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege < 1
    and I_CompareCounter Anorien_Local = 0
    if I_EventCounter large_city_barracks = 0
    if I_EventCounter huge_city_barracks = 0
    while I_CompareCounter PT < 1
    create_unit Anorien, Fountain Guard Garrison, num 1, exp 1, arm 0, wep 0
    create_unit Anorien, Kingsguard Garrison, num 1, exp 1, arm 0, wep 0
    create_unit Anorien, Gondor Spearmen Garrison, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers Garrison, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm Garrison, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Militia Archers Garrison, num 2, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 5
    end_while
    end_if

    ?
    Or should I change

    if I_EventCounter large_city_barracks = 0
    if I_EventCounter huge_city_barracks = 0

    to

    and I_EventCounter large_city_barracks = 0
    and I_EventCounter huge_city_barracks = 0

    ?
    In this case too, which is correct:

    monitor_event PreFactionTurnStart FactionType sicily
    if I_EventCounter is_the_ai 1
    set_counter ongoing_siege_gondor 0
    end_monitor

    or

    monitor_event PreFactionTurnStart FactionType sicily
    and I_EventCounter is_the_ai 1
    set_counter ongoing_siege_gondor 0
    end_monitor
    Last edited by k/t; January 06, 2013 at 07:16 PM.

  17. #17

    Default Re: Is this script right?

    I have not been on these forums in some time and seeing as the script in question is originally one i wrote i should be able to help.

    First of all, i have explained the entire script in some detail HERE. I break it down line by line...

    To answer some of your questions...

    The script was adapted for KingKongs Third Age.

    1) Clone some of the units in the EDU and give the clones the garrison_unit attribute
    2) Add a script in the campaign_script that destroys the units with garrison_unit after a siege so the faction that was attacked cannot use those units to counterattack
    This was the original idea of the script. The script was initially written for Stainless Steel but they used all the possible unit slots in the edu (500). The original plan for this garrison script was to create a number of units to be used only in the script (a varied seection of garrison units would make the script much more interesting which ill explain later). As has been mentioned in this thread the script to delete units is a faction wide thing. But with this script the units are only spawned upon a siege taking place, and then were supposed to be destroyed immediately after, so this would not affect other battles or sieges the faction is experiencing as those units are only spawned on a siege per siege basis (when the battle begins). There was a section in the Original TATW script that was put aside for this purpose. All you need is a script to delete the spawned units after a battle takes place. PostBattle would be fine. You dont need to worry about trying to find the city or which faction or whether it was a siege or battle, just destroy ALL garrison units after any and every battle and you're good to go. This is how it was intended to work.

    How should the script that destroys the units be written?
    As i dont have any of my modding on this computer i cant be sure of the exact way to do it. but i believe PostBattle is an Event, you could use TrueCondition for the condition, and then a series of destroy_unit commands followed by end_monitor. Simple.

    Note however that its intended you create units specifically for the garrison script. Even if they are just clones of pre existing units in the EDU. The player and AI will never be able to train these units. IF you use pre existing units in the EDU, units that can be trained by a faction then you risk destroying a factions unit pools. which you dont want.

    What's the difference between "I_CompareCounter Anorien_Local = 0" and "IsFactionAIControlled"?
    They are similar, but the Counter does a little more. It more or less just determines who controls the settlement at this precise moment. This is because a settlement can change control multiple times per turn. You might own it at the start of your turn, france may own it by the end of his, and germany by the end of his, before it is your turn again.

    And this -> and I_CompareCounter Anorien_Siege > 0?
    This stops a spawn from occuring if a siege has taken place in the last 10 or 5 turns depending on whether it was previously sieged/assualted. Removing this line will allow a settlement to spawn units every time it is assaulted regardless of the time between attacks.

    monitor_event FactionTurnStart IsRegionOneOf Anorien <- how can I make it check only for AI factions here?
    The original script checks every turn who controls a settlement as previously stated by the "and I_CompareCounter Cair_Andros_Local = 0"

    If I want to make the units spawned by the garrison script depend on which units have been unlocked so far by the barracks events,
    and event_counter large_city_barracks = 0
    and event_counter huge_city_barracks = 0
    This is a part of the script that people seem to overlook. The script is set up to take into account in game events. Any event that happens in game can be used to change the type of unit available for spawn. I believe in the original script i had used dates and events as a determining factor as to when 'roughly' specific unit types would become available.

    The script is intended to spawn a variety of units based on the current conditions in game and how far along the game is. More advanced units being spawned later in game with a higher chance of more appearing etc etc and blah blah

    In the TATW script it merely uses a random counter. Allow me to provide you with an example of the original below... Notice the red parts below. These can be changed and added on for any ingame event. Be it in the events file, or actual ingame events that you script. As long as they are event conuters you can use it. The same method you allow units to become available in the EDB, you use here...

    Code:
    monitor_event PreFactionTurnStart FactionIsLocal
    	if I_EventCounter dante_born != 1
    		set_counter UWepArm 1
    	end_if
    	if I_EventCounter dante_born = 1
    	and I_EventCounter grote_mandenke != 1
    	generate_random_counter random_armwep 1 2
    		if I_EventCounter random_armwep = 1
    		set_counter UWepArm 1
    		end_if
    		if I_EventCounter random_armwep = 2
    		set_counter UWepArm 2
    		end_if
    	end_if
    	if I_EventCounter grote_mandenke = 1
    	and I_EventCounter science_de_docta_ignorantia != 1
    	generate_random_counter random_armwep 1 3
    		if I_EventCounter random_armwep = 1
    		set_counter UWepArm 1
    		end_if
    		if I_EventCounter random_armwep = 2
    		set_counter UWepArm 2
    		end_if
    		if I_EventCounter random_armwep = 3
    		set_counter UWepArm 3
    		end_if
    	end_if
    	if I_EventCounter science_de_docta_ignorantia = 1
    	generate_random_counter random_armwep 1 4
    		if I_EventCounter random_armwep = 1
    		set_counter UWepArm 1
    		end_if
    		if I_EventCounter random_armwep = 2
    		set_counter UWepArm 2
    		end_if
    		if I_EventCounter random_armwep = 3
    		set_counter UWepArm 3
    		end_if
    		if I_EventCounter random_armwep = 4
    		set_counter UWepArm 4
    		end_if
    	end_if
    end_monitor
    I hope i was able to answer your questions.
    ...longbows, in skilled hands, could reach further than trebuchets...

  18. #18

    Default Re: Is this script right?

    "What's the difference between "I_CompareCounter Anorien_Local = 0" and "IsFactionAIControlled"?"

    I get that now. However, what's the difference between the "FactionIsLocal" and "IsFactionAIControlled" types of events?

    I ended up cloning a lot of units, renaming the copies by adding "Garrison" to their names, giving them garrison_unit and making them have 0 upkeep. This is the easiest way of cloning, since it does not require making changes to export_unit or battle_models. The script only spawns Garrison units.

    The "AI vs AI" part of the script uses this as a monitor: monitor_event FactionTurnStart IsFactionAIControlled, which I am happy with, since I want the units to be spawned as soon as possible, not just when the assault begins. In this way, all the troops inside the settlement will be whittled down by a lengthy siege, instead of having fresh units pop up at the last possible moment. Apart from being unrealistic (well, more unrealistic than fresh troops popping up at the first possible moment), it will screw up the AI's ability to calculate how many forces it needs to assault the settlement.

    I also have a destroy_units script planned. All garrison_units a faction has will be killed off at the end of its turn, if none of its garrison script-equipped settlements are under siege. This will prevent the garrison_units that are currently defending Settlement B from being wiped out just because the siege on Settlement A has failed (or succeeded).

    This is how I am planning to set up that script:
    Spoiler Alert, click show to read: 

    declare_counter ongoing_siege_gondor
    declare_counter ongoing_siege_rohan
    declare_counter ongoing_siege_dwarves
    declare_counter ongoing_siege_highelves
    declare_counter ongoing_siege_silvanelves
    declare_counter ongoing_siege_eriador
    declare_counter ongoing_siege_dale
    declare_counter ongoing_siege_isengard
    declare_counter ongoing_siege_orcs
    declare_counter ongoing_siege_mordor
    declare_counter ongoing_siege_rhun
    declare_counter ongoing_siege_harad

    monitor_event PreFactionTurnStart not FactionIsLocal
    and FactionType sicily
    set_counter ongoing_siege_gondor 0
    end_monitor

    SCRIPT THAT CHECKS WHETHER EACH GARRISON SCRIPT-EQUIPPED SETTLEMENT IS UNDER SIEGE OR NOT

    monitor_event FactionTurnEnd IsFactionAIControlled
    and I_CompareCounter ongoing_siege_gondor = 0
    destroy_units sicily garrison_unit

    end_monitor


    The SCRIPT is what I'm having trouble writing, since there are several ways of doing it (the three Versions in my post above), and I'm not sure which is the best.

    The PT counter is starting to worry me now, since I don't want the garrison script to spawn the units multiple times per siege. I beefed up the Garrison spawn considerably, and I only want it to spawn once per siege. How should I handle that?

    Since I have 1.4, I do see all the UWep counters and the 11, 12, 21, 22 stuff. I like the idea of randomizing the garrison spawn, but first I want to get the script working at all. The randomization will be a nice feature to add later.
    Last edited by k/t; January 07, 2013 at 02:42 PM.

  19. #19

    Default Re: Is this script right?

    I like the sound of what you are planning to do and sounds like it will add some nice flavor. HEre are a few things in more detail that may or may not help you...

    When the units are spawned in my garrison script they are suppose to spawn only 1 of each unit (the script uses a while statement to spawn additional units only if the conditions are met). Depending on the PT counter this will cycle multiple times. The PT counter randomizes the spawn dependent on the possible technology level or year in game (sets the minimum and maximum number of units that can spawn). This is controlled by events. Thus, you end up with a higher chance of more units spawning based on events in game (the world is round in vanilla, or barracks become available in TATW for example). It also works hand in hand with the UExp and UWepArm counters, which are designed to make the spawn more varied in the types of units, and the technology level of the units that spawn. The script can handle all 500 unit types in the script and cover as many settlements as u like. Meaning, you can have multiple versions of the same settlement that will spawn under different conditions with a completely different effect (this part of the script was never put in place for TATW) this meant you could have 600 settlements (the 199 under different conditions).

    All in all, the script becomes quite random and the player never knows what will spawn. On the first incarnation of how the script was used in TATW it was a little ridiculous because the script spawned far too many, and there was no variety at all (I remember people complaining about trolls being spawned early in game, this is because the technology tree aspect of the script was never utilized). You could practically guess what would spawn. But that is not how i wrote it to be used, and as such it hasnt been used to its full potential.

    With that said, it doesnt need to have randomization at all and it is easy to remedy. I like the randomization as it isnt so obvious what will happen. Will cavalry spawn, or archers or maybe a mix. There is also suppose to be a chance that no units will spawn.

    Think of the 11, 12, 21, 22 etc as individual numbers (technological advancement). example, the first number symbolizes unit experience (UExp) and the second number represents Armor and Weapon upgrades available (Technology). So, 12, would mean the units to spawn will not be very experienced, perhaps peasants... the 2 means they are actually decently armed so may have some leather armor (14, might grant the peasants chain mail or a better weapon etc)... In Stainless Steel, i used 6 numbers. 11, 12, 13, 14, 15, 16, 21, 22..etc.. upto.. 65, 66... So there was 6 levels of unit experience, from Peasant to Professional soldier, and 6 levels of possible technological upgrades which is suppose to encompass wall upgrades, building upgrades and year in game. which is once again determined by events happening in game (event counters). Coupled with the PT counter, you then get a rather detailed spawn which is highly variable...

    It was suppose to work alongside PointBlanks Real Recruitment and such. The Stainless steel community were not interested in the script when i first revealed it. And then KingKong messaged me and asked if he could use it for TATW, so i helped him adapt it for that. But it was never fully intergrated as i had initially intended it. I was going to rewrite the script for TATW and make better use of the script, but real life has continued to take over here and there and then i was working on my own side project DOTC, so i never got around to actually updating the script for tATW. The version i have written for DOTC is even more detailed.

    If you only want the script to repeat once, so the PT doesnt spawn multiples... simply remove the part that sets PT and use a counter that sets PT to 0. PT counter counted from a negative number upto but not including positive 1. So setting it to 0 will only allow the srcipt to be read once... This however makes the While statement null and void...
    ...longbows, in skilled hands, could reach further than trebuchets...

  20. #20

    Default Re: Is this script right?

    I have checked when every unit becomes available and it will be spawned by the garrison script only then.
    Spoiler Alert, click show to read: 

    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege < 1
    and I_CompareCounter Anorien_Local = 0
    if I_EventCounter large_city_barracks = 0
    if I_EventCounter huge_city_barracks = 0
    while I_CompareCounter PT < 1
    create_unit Anorien, Fountain Guard Garrison, num 1, exp 1, arm 0, wep 0
    create_unit Anorien, Kingsguard Garrison, num 1, exp 1, arm 0, wep 0
    create_unit Anorien, Gondor Spearmen Garrison, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers Garrison, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm Garrison, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Militia Archers Garrison, num 2, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 5
    end_while
    end_if

    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege < 1
    and I_CompareCounter Anorien_Local = 0
    if I_EventCounter large_city_barracks = 1
    if I_EventCounter huge_city_barracks = 0
    while I_CompareCounter PT < 1
    create_unit Anorien, Fountain Guard Garrison, num 1, exp 1, arm 0, wep 0
    create_unit Anorien, Kingsguard Garrison, num 1, exp 1, arm 0, wep 0
    create_unit Anorien, Gondor Infantry Garrison, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Spearmen Garrison, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers Garrison, num 1, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm Garrison, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Militia Archers Garrison, num 2, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 5
    end_while
    end_if

    if I_SettlementUnderSiege Anorien
    and I_SettlementOwner Anorien = sicily
    and I_CompareCounter Anorien_Siege < 1
    and I_CompareCounter Anorien_Local = 0
    if I_EventCounter huge_city_barracks = 1
    while I_CompareCounter PT < 1
    create_unit Anorien, Fountain Guard Garrison, num 1, exp 1, arm 0, wep 0
    create_unit Anorien, Kingsguard Garrison, num 1, exp 1, arm 0, wep 0
    create_unit Anorien, Gondor Infantry Garrison, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Spearmen Garrison, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Gondor Archers Garrison, num 2, exp 0, arm 0, wep 0
    create_unit Anorien, Dismounted Kofm Garrison, num 3, exp 0, arm 0, wep 0
    create_unit Anorien, Militia Archers Garrison, num 3, exp 0, arm 0, wep 0
    inc_counter PT 1
    set_counter Anorien_Siege 5
    end_while
    end_if

    My problem now is I don't know when should I use "and" and when should I use "if"? Which Version of the script is best? That's what I'm having trouble with.

Page 1 of 4 1234 LastLast

Posting Permissions

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