Results 1 to 12 of 12

Thread: Creating Garrison Script.

  1. #1

    Question Creating Garrison Script.

    Hey, i've been working on a garrison script, nearly finished it, but something is going wrong, units don't wanna spawn. I would really appreciate any help on this question.
    Here what a script for 1 city looks like:
    City=Name of the City
    Faction1= Besieged faction
    Faction2= Besieging faction
    x,y= Coordinates


    Code:
    script
    declare_counter one
    set_counter one 0
    declare_counter Citybesieged
    
    if I_CompareCounter Citybesieged = 0
    and I_SettlementOwner Rome = [faction1]
    if I_CharacterTypeNearTile [faction2] general,  2 x,y
    set_counter Acrebesieged 1
    end_if
    if I_CharacterTypeNearTile [gauls] family,  2 x,y
    set_counter Acrebesieged 1
    end_if
    
    if I_CompareCounter Acrebesieged = 0
    and I_SettlementOwner Rome = [faction2]
    if I_CharacterTypeNearTile [faction1] general,  2 x,y
    set_counter Acrebesieged 1
    end_if
    if I_CharacterTypeNearTile [faction1] family,  2 x,y
    set_counter Acrebesieged 1
    end_if
    
    monitor_event FactionTurnStart FactionType faction1
    
    if I_CompareCounter Citybesieged = 1
    if  I_SettlementOwner City =  faction1
    if SettlementBuildingExists = governors_villa  
    if GarrisonSettlementRatio < 0.1
    console_command create_unit  City "peasants" 4
    console_command add_money -2000       
    console_command add_population City -1500
    end_if
    
    monitor_event FactionTurnStart FactionType faction2
    
    if I_CompareCounter Citybesieged = 1
    if  I_SettlementOwner City =  franks
    if SettlementBuildingExists = governors_villa  
    if GarrisonSettlementRatio < 0.1
    console_command create_unit  City "peasants" 5
    console_command add_money -2000       
    console_command add_population City -1500
    end_if
    
    set_counter one 0
    set_counter Citybesieged 0
    
    terminate_script

  2. #2
    Bibliophilic Member Atilius's Avatar
    Join Date
    Oct 2005
    Location
    America Medioccidentalis Superior
    Posts
    3,837

    Default Re: Creating Garrison Script.

    Lots of problems here:

    -This script will only run once: if you want it to run continuously you need to add a loop.

    -You have 2 event monitors but no
    Code:
    end_monitor
    statements.

    -You must declare a counter for
    Code:
    Acrebesieged
    .

    -You don't have an
    Code:
    end_if
    for
    Code:
    if I_CompareCounter Acrebesieged = 0
    .

    I'd suggest you simplify the script drastically, get it to work, and slowly add complexity.
    The truth is the most valuable thing we have. Let us economize it. - Mark Twain



  3. #3

    Default Re: Creating Garrison Script.

    I made some mistakes in the script posted, here is the updated one, but, unfortunately still ain't working :(.
    Code:
    script
    declare_counter one
    set_counter one 0
    declare_counter Citybesieged
    
    if I_CompareCounter Citybesieged = 0
    and I_SettlementOwner Rome = [faction1]
    if I_CharacterTypeNearTile [faction2] general,  2 x,y
    set_counter Citybesieged 1
    end_if
    if I_CharacterTypeNearTile [faction2] family,  2 x,y
    set_counter Citybesieged 1
    end_if
    
    if I_CompareCounter Citybesieged = 0
    and I_SettlementOwner Rome = [faction2]
    if I_CharacterTypeNearTile [faction1] general,  2 x,y
    set_counter Citybesieged 1
    end_if
    if I_CharacterTypeNearTile [faction1] family,  2 x,y
    set_counter Citybesieged 1
    end_if
    
    monitor_event FactionTurnStart FactionType faction1
    end_monitor
    
    if I_CompareCounter Citybesieged = 1
    if  I_SettlementOwner City =  faction1
    if SettlementBuildingExists = governors_villa  
    if GarrisonSettlementRatio < 0.1
    console_command create_unit  City "peasants" 4
    console_command add_money -2000       
    console_command add_population City -1500
    end_if
    
    monitor_event FactionTurnStart FactionType faction2
    end_monitor
    
    if I_CompareCounter Citybesieged = 1
    if  I_SettlementOwner City =  faction2
    if SettlementBuildingExists = governors_villa  
    if GarrisonSettlementRatio < 0.1
    console_command create_unit  City "peasants" 5
    console_command add_money -2000       
    console_command add_population City -1500
    end_if
    
    set_counter one 0
    set_counter Citybesieged 0
    
    terminate_script
    Last edited by Myrddraal; 11-05-2006 at 18:52.

  4. #4
    Bibliophilic Member Atilius's Avatar
    Join Date
    Oct 2005
    Location
    America Medioccidentalis Superior
    Posts
    3,837

    Default Re: Creating Garrison Script.

    Event monitors must start with monitor_event and must end with an end_monitor, but the stuff you wish to happen when the event triggers must be inside. Your end_monitors are now immediately after your monitor_event, so nothing will happed when the event occurs. In the lower half of the script, your ifs aren't all paired with end_ifs.

    Also "peasant" is not a unit ID.

    Take my advice: start very simple, make sure what you have works, then add on. Writing more than a half-dozen lines of script without errors is difficult, particularly if you haven't done a lot of scripting.
    The truth is the most valuable thing we have. Let us economize it. - Mark Twain



  5. #5

    Default Re: Creating Garrison Script.

    Thanks Atilius, i'll try redo it as you adviced.

  6. #6

    Default Re: Creating Garrison Script.

    You can use my Garrison script if you want. Mine is based in the Garrison script made by LorDBulA (included into SPQR mod).
    Here it is the code:

    Code:
    script
    
    ;console_command toggle_perfect_spy
    ;very useful to debug
    
    declare_counter City1Besiged
    set_counter City1Besiged 0
    declare_counter City2Besiged
    set_counter City2Besiged 0
    ;...per settlement
    
    monitor_event FactionTurnEnd FactionType [faction1]
    and I_LocalFaction [faction1]
    
       if I_CompareCounter City1Besiged = 0
          and not I_SettlementOwner [city1] = [faction1]
          if I_CharacterTypeNearTile [faction1] general,  2 x1,y1
             set_counter City1Besiged 1
          end_if
          if I_CharacterTypeNearTile [faction1] family,  2 x1,y1
             set_counter City1Besiged 1
          end_if
       end_if
       if I_CompareCounter City1Besiged = 2
          and not I_CharacterTypeNearTile [faction1] family, 2 x1,y1
          and not I_CharacterTypeNearTile [faction1] general, 2 x1,y1
          set_counter City1Besiged 0
       end_if
    
       if I_CompareCounter City2Besiged = 0
          and not I_SettlementOwner [city2] = [faction1]
          if I_CharacterTypeNearTile [faction1] general,  2 x2,y2
             set_counter City2Besiged 1
          end_if
          if I_CharacterTypeNearTile [faction1] family,  2 x2,y2
             set_counter City2Besiged 1
          end_if
       end_if
       if I_CompareCounter City2Besiged = 2
          and not I_CharacterTypeNearTile [faction1] family, 2 x2,y2
          and not I_CharacterTypeNearTile [faction1] general, 2 x2,y2
          set_counter City2Besiged 0
       end_if
       ;...per settlement
    
    end_monitor
    ;...a monitor per possible local faction
    
    monitor_event SettlementTurnEnd SettlementName [city1-mapname]
       and I_CompareCounter City1Besiged = 1
       and GarrisonSettlementRatio < 0.5
          if I_SettlementOwner [city1] = [faction1]
             console_command create_unit [city1] "unit name" 4
             console_command add_money -2000       
             console_command add_population City -1500
          end_if
          if I_SettlementOwner [city1] = [faction2]
             console_command create_unit [city1] "unit name" 4
             console_command add_money -2000       
             console_command add_population City -1500
          end_if
          set_counter City1Besiged 2
          ;...an if per faction
    end_monitor
    
    monitor_event SettlementTurnEnd SettlementName [city2-mapname]
       and I_CompareCounter City2Besiged = 1
       and GarrisonSettlementRatio < 0.5
          if I_SettlementOwner [city2] = [faction1]
             console_command create_unit [city1] "unit name" 4
             console_command add_money -2000       
             console_command add_population City -1500
          end_if
          if I_SettlementOwner [city2] = [faction2]
             console_command create_unit [city1] "unit name" 4
             console_command add_money -2000       
             console_command add_population City -1500
          end_if
          ;...an if per faction
          set_counter City2Besiged 2
    end_monitor
    ;...a monitor per settlement
    
    
    while TrueCondition
    end_while
    
    end_script
    You need to change all words in brackets, I tried to use your same nomenclature. And copy-paste the code where it says ";...per faction or settlement"

    Note: The condition "SettlementName" needs the name of the city that it is shown in the map, not the internal name.
    You can see it in the file: data\text\imperial_campaign_regions_and_settlement_names.txt

    ie:{Lepcis_Magna} Lepcis Magna
    [city1]=internal name, ie:Lepcis_Magna
    [city1-mapname]=name show in map, ie:Lepcis Magna

    I also recommend you to read the Intermediate Guide to Scripting, By Epistolary Richard & Myrddraal. (if you didn't already read it)

    Note2 - Important thing not said in this guide: When you use an "if" or "while" statment, you can only use conditions starting by "I_" . All other conditions need some Trigger requirements, and they can only be used with monitor_events. (the "Trigger requirements" of the condition must be in the "Exports" of the event)

    start very simple, make sure what you have works, then add on. Writing more than a half-dozen lines of script without errors is difficult, particularly if you haven't done a lot of scripting.
    Wise words. It is almost impossible to write the full script and get it working at the first attempt. I suggest you to test it with one city and 2 factions until the script is working. Then, you can add lines and adjust the script.

    I hope this helps

  7. #7

    Default Re: Creating Garrison Script.

    Bardo thanks a lot, i really appreciate your help! I'll start exprimenting right away!

  8. #8

    Default Re: Creating Garrison Script.

    Bardo, i got confused a bit with your instructions :(.
    Could you please just clarify this for me.
    Am i right here:

    [city name = map name = Acre, faction1 = sassanids, faction 2 = franks, unit name = crusader latin knigts (just for testing)]

    Code:
    script
    This For each Settlement
    Code:
    declare_counter AcreBesiged
    set_counter AcreBesiged 0
    Repeat For Each Faction
    Code:
    monitor_event FactionTurnEnd FactionType sassanids
    and I_LocalFaction sassanids
    
    ;;;;;;;Repeat For Each Settlement;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
       if I_CompareCounter AcreBesiged = 0
          and not I_SettlementOwner Acre = sassanids
          if I_CharacterTypeNearTile sassanids general,  2 151,162
             set_counter AcreBesiged 1
          end_if
          if I_CharacterTypeNearTile sassanids family,  2 151,162
             set_counter AcreBesiged 1
          end_if
       end_if
       if I_CompareCounter AcreBesiged = 2
          and not I_CharacterTypeNearTile sassanids family, 2 151,162
          and not I_CharacterTypeNearTile sassanids general, 2 151,162
          set_counter AcreBesiged 0
       end_if
    ;;;;;;;^^^Repeat for Each Settlement^^^;;;;;;;;;;;;;;;;;;;;
    
    end_monitor
    This Monitor For Every Settlement
    Code:
    monitor_event SettlementTurnEnd SettlementName Acre
       and I_CompareCounter AcreBesiged = 1
       and GarrisonSettlementRatio < 0.5
          if I_SettlementOwner Acre = sassanids
             console_command create_unit Acre "crusader latin knights" 4
             console_command add_money -2000       
             console_command add_population Acre -1500
          end_if
          if I_SettlementOwner Acre = franks
             console_command create_unit Acre "crusader latin knights" 4
             console_command add_money -2000       
             console_command add_population Acre -1500
          end_if
          if I_SettlementOwner Acre = slave
             console_command create_unit Acre "crusader latin knights" 4
             console_command add_money -2000       
             console_command add_population Acre -1500
          end_if
          set_counter AcreBesiged 2
    end_monitor
    Code:
    while TrueCondition
    end_while
    
    end_script
    Did i understand your instructions correctly?
    Thanks Bardo.

  9. #9

    Default Re: Creating Garrison Script.

    Bardo
    Thanks bro, i made it work!
    The problem was i forgot to add
    "declare_counter loop
    set_counter loop 0" in the begginning

    and

    "while I_CompareCounter loop = 0
    end_while
    end_script

    in the end".

    Also thanks a lot for letting me use your kind. It was very kind of you. Hopefully it is going to be included in a new patch for the Crusades!
    Now i'm gonna have to copy it for all the factions))) A lot of boring work to do))

  10. #10

    Default Re: Creating Garrison Script.

    Did i understand your instructions correctly?
    Yes, you understood right.

    Also thanks a lot for letting me use your kind.
    No problem, man. In fact, mine is just an evolution from LorDBula's.
    And I'm happy if my work is useful to other people.

    The problem was i forgot to add...
    Weird, because this code has the same effect:
    Code:
    while TrueCondition
    end_while
    than that:
    Code:
    declare_counter loop
    set_counter loop 0
    while I_CompareCounter loop = 0
    end_while
    Now i'm gonna have to copy it for all the factions))) A lot of boring work to do))
    I agree... really boring.

    You can pm me if you have some other doubt, or if you find some bug in the script.

  11. #11

    Default Re: Creating Garrison Script.

    I followed Bardo's guide and it works. Thanks!
    Last edited by Hoginator01; 09-03-2010 at 20:39.
    Respectfully,

    Hoginator01

  12. #12

    Default Re: Creating Garrison Script.

    Note I find that garrison script too complicated and hard to maintain, since it needs all the settlement names and coordinates. If I would have to create a garrison script now, from scratch, I would use one based on this simpler method:

    Code:
    monitor_event CharacterTurnEndInSettlement FactionType [faction name]
       and IsUnderSiege
       and SettlementName [settlement MAP name]
    
          console_command create_unit [settlement INTERNAL name] "[unit name]" 1
    
    end_monitor
    The limitation is it only works if there is a named character inside the city, but you only need to write one monitor per city.
    It would be easy to add one named charater at each city, and to give them a trait with penalty to movement points to avoid AI move them.

    I already used this method for siege of Helm's Deep in our mod and it works. I would just need to add a counter to avoid the script being triggered every turn.

    I tried to place other useful info about scripts here:
    http://www.twcenter.net/forums/showthread.php?t=300345
    Last edited by Bardo; 09-03-2010 at 21:43.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO