Page 3 of 3 FirstFirst 123
Results 41 to 58 of 58

Thread: Garrison Script

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Hellvard's Avatar Senator
    Join Date
    Dec 2012
    Location
    Poland
    Posts
    1,145

    Default Re: Garrison Script

    I found this in one of your posts:

    monitor_event BuildingCompleted FactionType gerudo
    and SettlementBuildingFinished = buildingA
    and SettlementName MyFavoriteTown

    But in this case i must make monitors for all factions one after another, is there a way to make it in one monitor?

  2. #2
    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: Garrison Script

    The conditions are not available as I_... conditions - therefore you cannot use the 'if' function - the answer is 'no'










  3. #3
    StaefanBatory's Avatar Civis
    Join Date
    Feb 2009
    Location
    Cracow, Poland
    Posts
    187

    Default Re: Garrison Script

    My sugestions, about the lines:
    Code:
    monitor_conditions not I_SettlementUnderSiege          
            set_counter rome_siege 0
    end_monitor
    set_counter rome_siege 0 will be sets in every time in game, so the game speed slows down (the more similar lines the slower)

    Add second condition:

    Code:
    monitor_conditions not I_SettlementUnderSiege Rome   
            and I_CompareCounter  rome_siege = 1
            set_counter  rome_siege 0
    end_monitor
    And the conditions will be check only, when counter will be has value 1. Less work for processor



    About this command:

    Code:
            destroy_units [faction] [custom attribute]
    It is destroy all the same unit types. I tried:
    Code:
    destroy_units Venice , Italian Spear Militia, num 1, exp 0, arm 1, wep 0
    But script delete all Italian Spear Militia from Venice. Value num 1 does not affect the number of destroyed units. Any sugestions?
    Last edited by StaefanBatory; January 31, 2016 at 06:06 PM.
    Life without Total War games isn't a life

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

    Default Re: Garrison Script

    Quote Originally Posted by StaefanBatory View Post
    Code:
    monitor_conditions not I_SettlementUnderSiege Rome   
            and I_CompareCounter  rome_siege = 1
            set_counter  rome_siege 0
    end_monitor
    And the conditions will be check only, when counter will be has value 1. Less work for processor
    "set_counter rome_siege 0" will only be executed when both of those conditions are true, so in that sense there is less work for the processor. However, monitor_conditions continuously checks its conditions, whether they are true or not. That's what monitor_conditions is: "continuously check these conditions ... and if they're all true then do something". A condition being false does not pause monitor_conditions, stopping it from performing the checks, it just prevents its body from being executed, the "do something" bit: the set_counter line in your example.

    Whether Rome is under siege or not this monitor is still checking "not I_SettlementUnderSiege Rome" 20 times a second. And if that condition is true then it will also check the I_CompareCounter one. (And so on, if there were more. As soon as it finds one to be false it won't check any of the others below it.)

    That's why monitor_conditions is such a bad idea and should be avoided whenever possible. It chews up processor time checking things that don't need to be checked 99.9999% of the campaign's lifetime.

  5. #5
    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: Garrison Script

    The destroy_unit command will always remove all units as defined.

    If you spawn a garrison I would suggest to use 'cloned' units, eg make a copy of the EDU unit entry and change the name (requires new export_units entries and pictures), then give it a custom attribute which you can use in all garrison units for easy disbanding. Example:
    Code:
    type             Italian Spear Militia Garrison
    dictionary       Italian_Spear_Militia_G      ; Italian Spear Militia
    category         infantry
    class            spearmen
    voice_type       Light
    banner faction   main_spear
    banner holy      crusade
    soldier          Italian_Spear_Militia, 60, 0, 1.5
    attributes       sea_faring, hide_forest, can_withdraw, free_upkeep_unit, garrison
    To disband all of these units you would now use this command syntax:
    Code:
    destroy_units [faction] garrison
    Last edited by Gigantus; January 31, 2016 at 07:31 PM.










  6. #6
    Mr_Nygren's Avatar Berserkir
    Join Date
    Mar 2009
    Location
    Sweden
    Posts
    4,303

    Default Re: Garrison Script

    Quote Originally Posted by weissnicht View Post
    Tutorial for a Garrisonscript


    Open campaign_script.txt
    This is the code, which we implent in campaign_script.txt

    Code:
    ;=========================================================================================
    
    
    ;---------- Counter ----------
    
    declare_counter rome_siege
    
    
    ;---------- Garrionscript ----------
     
    monitor_conditions not I_SettlementUnderSiege Rome            
            set_counter rome_siege 0
    end_monitor
    
    monitor_conditions I_SettlementUnderSiege Rome            
            and I_CompareCounter rome_siege = 0
    
    if I_SettlementOwner Rome = papal_states                    
        create_unit Rome, peasant, num 2, exp 2, arm 1, wep 0
    end_if        
    
    set_counter rome_siege 1
    
    end_monitor
    First we set the counter rome_siege to 0.
    If Rome is now under siege ("I_SettlementUnderSiege Rome" ) and is controlled by the papal states ("if I_SettlementOwner Rome = papal_states"), we spawn 2 Peasants ("num 2") with 2 experience (maximum 9) 1 Weaponupgrade (maximum 9) and no Armourupgrade (maximum 9) in Rome.
    Now we set the counter rome_siege to 1, because we don't want to spawn the troops two times

    Congrats, you have no written a full functional Garrisonscript.

    Now you can implent some nice features like, if Arabs siege Rome you Spawn more troops etc.


    Code:
    ;=========================================================================================
    
    
    ;---------- Counter ----------
    
    declare_counter rome_siege
    
    
    ;---------- Garrionscript ----------
     
    monitor_conditions not I_SettlementUnderSiege Rome            
            set_counter rome_siege 0
    end_monitor
    
    monitor_conditions I_SettlementUnderSiege Rome            
            and I_CompareCounter rome_siege = 0
    
    if I_SettlementOwner Rome = papal_states 
    and I_FactionBesieging egypt                  
        create_unit Rome, Feudal Knights, num 4, exp 2, arm 5, wep 5
    end_if        
    
    set_counter rome_siege 1
    
    end_monitor
    The small additonial line "and I_FactionBesieging egypt" give the game all inforamtions ehich are needed.



    You can also make more conditions.
    For example if it is a citadel better units will spawn:


    Code:
    ;=========================================================================================
    
    ;---------- Counter ----------
    
    declare_counter rome_siege
    
    ;---------- Garrionscript ----------
    
    
    monitor_conditions not I_SettlementUnderSiege Rome            
            set_counter rome_siege 0
    end_monitor
    
    monitor_conditions I_SettlementUnderSiege Rome            
            and I_CompareCounter rome_siege = 0
    
    
    if I_SettlementOwner Rome = papal_states 
    and I_FactionBesieging egypt                  
    and SettlementBuildingExists = citadel    
        create_unit Rome, Feudal Knights, num 4, exp 2, arm 5, wep 5
        create_unit Rome, Armored Sergeants, num 4, exp 2, arm 5, wep 5
    end_if        
    
    set_counter rome_siege 1
    end_monitor
    I hope this small Tutorial will help

    regards weissnicht
    Nothing happened for me when i tried to implement the first one? Am i supposed to write the settlement name Deganwy, or the name Gwynedd_Town? I replaced Rome with both of these but nothing worked..

    Code:
    ;---------- Garrionscript ---------- 
    monitor_conditions not I_SettlementUnderSiege Deganwy            
            set_counter Deganwy_siege 0
    end_monitor
    
    
    monitor_conditions I_SettlementUnderSiege Deganwy            
            and I_CompareCounter Deganwy_siege = 0
    
    
    if I_SettlementOwner Deganwy = wales                    
        create_unit Deganwy, amaethwyr P, num 5, exp 2, arm 1, wep 0
    end_if        
    
    
    set_counter Deganwy_siege 1
    
    
    end_monitor
    
    
    
    
      wait_monitors
    
    
    end_script
    .
    Be your friend's, true friend. Return gift for gift. Repay laughter, with laughter again
    but betrayal with treachery.

    - The Havamal

  7. #7

    Default Re: Garrison Script

    Mr_Nygren, when you play with the garrison script, many variants exist. This is one of the versions that I like the most, as it gives randomness.

    ******************************************************
    monitor_event FactionTurnStart FactionType sicily
    and not I_LocalFaction sicily
    and I_SettlementOwner RunakFarm = sicily
    and I_SettlementUnderSiege RunakFarm
    if RandomPercent < 95
    create_unit RunakFarm, Waldlaufer Warrior Light, num 1, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 95
    create_unit RunakFarm, Axe Clansmen, num 1, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 95
    create_unit RunakFarm, Bow Clansmen, num 1, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 80
    create_unit RunakFarm, Waldlaeufer Speer, num 2, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 80
    create_unit RunakFarm, Waldlaufer Marksmen, num 2, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 80
    create_unit RunakFarm, Waldlaeufer Peacekeepers, num 2, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 35
    create_unit RunakFarm, Traveler Crossbowmen, num 1, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 35
    create_unit RunakFarm, Traveler Light Infantry, num 1, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 7
    create_unit RunakFarm, Waldlaufer Bogen, num 1, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 7
    create_unit RunakFarm, Druidenbegleiter, num 1, exp 3, arm 1, wep 1
    end_if
    end_monitor
    *********************************************************

    But, you can also play with this script by using a "declare_counter" to give specific conditions.. or you can use the "Dinamic Garrison Script" as well, by implementing the trait "garrison_unit" for the ones that you want to spawn during a siege.. And there are as well other models, here the choice is vast..


  8. #8
    Mr_Nygren's Avatar Berserkir
    Join Date
    Mar 2009
    Location
    Sweden
    Posts
    4,303

    Default Re: Garrison Script

    Quote Originally Posted by rafmc1989 View Post
    Mr_Nygren, when you play with the garrison script, many variants exist. This is one of the versions that I like the most, as it gives randomness.

    ******************************************************
    monitor_event FactionTurnStart FactionType sicily
    and not I_LocalFaction sicily
    and I_SettlementOwner RunakFarm = sicily
    and I_SettlementUnderSiege RunakFarm
    if RandomPercent < 95
    create_unit RunakFarm, Waldlaufer Warrior Light, num 1, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 95
    create_unit RunakFarm, Axe Clansmen, num 1, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 95
    create_unit RunakFarm, Bow Clansmen, num 1, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 80
    create_unit RunakFarm, Waldlaeufer Speer, num 2, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 80
    create_unit RunakFarm, Waldlaufer Marksmen, num 2, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 80
    create_unit RunakFarm, Waldlaeufer Peacekeepers, num 2, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 35
    create_unit RunakFarm, Traveler Crossbowmen, num 1, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 35
    create_unit RunakFarm, Traveler Light Infantry, num 1, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 7
    create_unit RunakFarm, Waldlaufer Bogen, num 1, exp 3, arm 1, wep 1
    end_if
    if RandomPercent < 7
    create_unit RunakFarm, Druidenbegleiter, num 1, exp 3, arm 1, wep 1
    end_if
    end_monitor
    *********************************************************

    But, you can also play with this script by using a "declare_counter" to give specific conditions.. or you can use the "Dinamic Garrison Script" as well, by implementing the trait "garrison_unit" for the ones that you want to spawn during a siege.. And there are as well other models, here the choice is vast..
    Thanks for your reply - I just need the garrison-script for a particular unit of the Kingdom of Gwynedd. But i couldn't get the one above to work? The campaign started but nothing happened when i got attacked. I also did remove the rvm-file and such.

    I haven't tried the method you showed but i only want one particular unit to spawn. It sucks as an ordinary unit.
    Be your friend's, true friend. Return gift for gift. Repay laughter, with laughter again
    but betrayal with treachery.

    - The Havamal

  9. #9

    Default Re: Garrison Script

    Mmh, I see. Personally, I always recommend using a script with the "monitor_event" instead of the "monitor_condition" as the processor works much less and you can create much more variability.. But the other model you were referring, listed above, I think is not correct, btw..


  10. #10
    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: Garrison Script

    Mr Nygren - have you declared the Deganwy_Siege counter? Without it the script will not work.

    Code:
    ;---------- Garrionscript ---------- 
    declare_counter Deganwy_siege
    monitor_event SettlementTurnEnd SettlementName Deganwy
            and not I_SettlementUnderSiege Deganwy
            set_counter Deganwy_siege 0
    end_monitor
    
    monitor_event SettlementTurnStart SettlementName Deganwy
            and I_SettlementUnderSiege Deganwy
            and I_CompareCounter Deganwy_siege < 1
            and I_SettlementOwner Deganwy = wales
            create_unit Deganwy, amaethwyr P, num 5, exp 2, arm 1, wep 0
            set_counter Deganwy_siege 1
    end_monitor










  11. #11

    Default Re: Garrison Script

    Here's the one we use in EBII:

    Code:
        monitor_event FactionTurnEnd FactionType slave
            ; --- Roma ----
            if I_IsFactionAIControlled f_rome
                and I_SettlementOwner sett_040 = f_rome        ; is owned by Rome
                and I_SettlementUnderSiege sett_040            ; makes sure the settlement (not a fort)
                if I_EventCounter Roma_spawn < 1               ; checking for cool down period
                    if I_EventCounter ecCamillanEra > 0
                        console_command create_unit sett_040 "roman cavalry equites camillan" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry principes camillan" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry hastati camillan" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry leves" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry triarii camillan" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry principes camillan" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry hastati camillan" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry leves" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry hastati camillan" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry leves" 1 0 0 0
                        set_event_counter Roma_spawn 10       ; setting cool down period
                        inc_counter unitlimit_f_rome 10
                    end_if
                    if I_EventCounter ecPolybianEra > 0
                        console_command create_unit sett_040 "roman cavalry equites polybian" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry principes polybian" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry hastati polybian" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry velites" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry triarii polybian" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry principes polybian" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry hastati polybian" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry velites" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry hastati polybian" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry velites" 1 0 0 0
                        set_event_counter Roma_spawn 10       ; setting cool down period
                        inc_counter unitlimit_f_rome 10
                    end_if
                    if I_EventCounter ecMarianEra > 0
                        console_command create_unit sett_040 "roman cavalry equites polybian" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry cohors reformata" 1 0 0 0  ; replace half of these with Cohors Tumultaria when done
                        console_command create_unit sett_040 "roman infantry cohors reformata" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry cohors reformata" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry antesignani" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry cohors evocatae" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry cohors reformata" 1 0 0 0  ; replace half of these with Cohors Tumultaria when done
                        console_command create_unit sett_040 "roman infantry cohors reformata" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry cohors reformata" 1 0 0 0
                        console_command create_unit sett_040 "roman infantry antesignani" 1 0 0 0
                        set_event_counter Roma_spawn 10       ; setting cool down period
                        inc_counter unitlimit_f_rome 10
                    end_if
                end_if
                if I_EventCounter Roma_spawn > 0        ; checking for cool down period
                    inc_event_counter Roma_spawn -1     ; reducing cool down period
                end_if
            end_if
            ; add other settlements
        end_monitor

  12. #12

    Default Re: Garrison Script

    Hello, I have a problem with garnison script.
    After adding an entry at the first city, everything is ok, while the next entries it doesnt work.

    ;---------- Counter ----------




    declare_counter Sicz_siege




    ;---------- Garrionscript ----------


    monitor_conditions not I_SettlementUnderSiege Sicz
    set_counter Sicz_siege 0
    end_monitor




    monitor_conditions I_SettlementUnderSiege Sicz
    and I_CompareCounter Sicz_siege = 0




    if I_SettlementOwner Sicz = kiev
    create_unit Sicz, mieszczanie2, num 4, exp 0, arm 0, wep 0
    end_if
    set_counter Sicz_siege 1
    end_monitor




    monitor_conditions not I_SettlementUnderSiege Sicz
    set_counter Sicz_siege 0
    destroy_units, kiev, garrison
    end_monitor
    wait_monitors








    ;---------- Counter ----------




    declare_counter Constanta_siege




    ;---------- Garrionscript ----------


    monitor_conditions not I_SettlementUnderSiege Constanta
    set_counter Constanta_siege 0
    end_monitor




    monitor_conditions I_SettlementUnderSiege Constanta
    and I_CompareCounter Constanta_siege = 0




    if I_SettlementOwner Constanta = kiev
    create_unit Constanta, mieszczanie2, num 4, exp 0, arm 0, wep 0
    end_if
    set_counter Constanta_siege 1
    end_monitor




    monitor_conditions not I_SettlementUnderSiege Constanta
    set_counter Constanta_siege 0
    destroy_units, kiev, garrison
    end_monitor
    wait_monitors

  13. #13
    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: Garrison Script

    Some logic issue, try this:

    Code:
    declare_counter Constanta_siege
    
    ;---------- Garrionscript ----------
    
    monitor_conditions not I_SettlementUnderSiege Constanta
        set_counter Constanta_siege 0
    end_monitor
    
    monitor_conditions I_SettlementUnderSiege Constanta
        and I_CompareCounter Constanta_siege = 0
        if I_SettlementOwner Constanta = kiev
            create_unit Constanta, mieszczanie2, num 4, exp 0, arm 0, wep 0
        end_if
        set_counter Constanta_siege 1
    end_monitor
    
    monitor_event FactionTurnEnd not I_SettlementUnderSiege Constanta
        and I_CompareCounter Constanta_siege = 1
        set_counter Constanta_siege 0
        destroy_units, kiev, garrison
    end_monitor
    Try to avoid using monitor_conditions - it slows down game turns somewhat bad when they accumulate.
    Also note that the destroy_unit command will remove all these units anywhere for the faction. Even for settlements that are under siege at the time.
    Last edited by Gigantus; July 01, 2020 at 11:53 PM.










  14. #14

    Default Re: Garrison Script

    It works, but I I changed the entry to:

    monitor_conditions not I_SettlementUnderSiege Constanta
    and I_CompareCounter Constanta_siege = 1
    set_counter Constanta_siege 0
    destroy_units, kiev, garrison
    end_monitor

    ... because the units did not remove.

    Thank you very much

  15. #15
    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: Garrison Script

    My example was set to destroy the units when you click 'next turn' - to avoid using yet another monitor_condition.










  16. #16

    Default Re: Garrison Script

    hmmm, what is the difference between our entries?
    Otherwise, which gives less use monitor_condition?

  17. #17
    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: Garrison Script

    When you use monitor_condition the initial condition gets tested for about 3-4 per second, whereas monitor_event only gets checked when the event happens. Hence the use of an increased number of monitor_condition uses will lengthen the turn end processing time significantly. The reason why monitor_condition should only be used if it is unavoidable.

    In your case there is no need to check 3-4 times a second (without break between faction turns) if the siege is under way when a simple one time check at turn end will have the same effect, eg removing the garison at the turn end of the faction it belongs to.










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

    Default Re: Garrison Script

    It's even worse than that: 20 times per second.

Page 3 of 3 FirstFirst 123

Posting Permissions

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