Results 1 to 14 of 14

Thread: How to script unit recruitment according to a characters title (Anc)

  1. #1
    Aneirin's Avatar of flowing verse
    Join Date
    Nov 2012
    Location
    Gododdin
    Posts
    2,734

    Default How to script unit recruitment according to a characters title (Anc)

    Hello everyone,

    due my recent work on IND to develop a title based recruitment system, I thought some of you might be interested in my results

    Object: Our object is to restrict the recruitment of units and bind it to a certain title of a family member or for example the title "Prince of Galiläa". Nowhere else, but at his own manor (Tiberias) the "Prince of Galiläa" should be able to recruit decent units, for example feudal spearmen. To make the story short, if the prince is at Jaffa, he won't be able to recruit any of his own men, but in Tiberias. (is it Tiberia or Tiberias?? )

    How: How are we going to accomplish that? Well, we will create two hidden traits, which trigger as soon as the prince is inside the city of Tiberias or just left the city. Additional, we will run two monitors. These monitors will check if our prince is in the field or in the city and activate the recruit_pool accordingly.

    What:What do we need?These files:

    • campaign_script
    • EDB
    • export_descr_character_traits
    • export_descr_ancillaries


    1. Step:

    To create a new anc is our first step. How to create a new anc in detail won't be explained in this tutorial. The only important thing to know is that you have to create a new Type for your anc.

    My code:
    Code:
    ;------------------------------------------
    Ancillary titel_tiberias
        Type NobleTiberias
        Transferable  0 
        Image sex_yangman.tga
        Description titel_tiberias_desc
        EffectsDescription titel_tiberias_effects_desc
        Effect Loyalty -1
    I chose Type NobleTiberias. We need that later on and of course you have to add a trigger, as well. The details are up to you

    2. Step:
    Now more fancy stuff. Open the export_descr_character_traits file and create two new trait entries.
    Note: Define these traits as hidden, so they won't show up during the campaign. Of course it's not mandatory, but it looks better

    As I already told you at the beginning, the traits serve us to check if our prince is in the field or in his city or any other city. Of course the recruit_pool should only be activated, when our prince is inside the city.

    That is why we need two traits. One to represent the case that the prince is at Tiberias (AtTiberias) and the other to represent the prince while he is not at Tiberias (NotAtTiberias).

    Code:
    ;------------------------------------------
    Trait NotAtTiberias
        Characters family
        Hidden
        
        Level StaysNotAtTiberias
            Description StaysNotAtTiberias
            EffectsDescription StaysNotAtTiberias_effects_desc
            Threshold 1    
    ;------------------------------------------
    Trait AtTiberias
        Characters family
        Hidden
        
        Level StaysAtTiberias
            Description StaysAtTiberias_desc
            EffectsDescription StaysAtTiberias_effects_desc
            Threshold 1
    We do not need any effects, because we only use these traits to represent two situations.

    3. Step:

    That is the tricky part. Our triggers shall only be triggered, when either our prince is at "home" or not. After some trail and error I come up to this code, of course it is not perfect, so feel more than free to make any suggestions!

    Trigger 1:
    Code:
    ;------------------------------------------
    Trigger StayedAtTiberias01
        WhenToTest CharacterTurnEnd
    
        Condition IsGeneral
              and HasAncType NobleTiberias
              and EndedInSettlement
              and SettlementName Tiberias
    
        Affects AtTiberias 1  Chance  100
        Affects NotAtTiberias -1 Chance 100
    The use of the first trigger is to check if the prince is in the city at the end of his turn. To prevent that we get the wrong character or city, we set conditions, that is why we need a new type, HasAncType NobleTiberias and SettlementName Tiberias.
    EndedInSettlement is used to check if the character has ended his turn inside a city.

    In case all of our conditions are met, our prince obviously have to be inside the city of Tiberias, as a consequence:
    Affects AtTiberias 1 Chance 100, our prince gets the trait, (AtTiberias). He is inside the city.

    To prevent other potential problems, we create a trigger which triggers in case our prince stays in the field.

    Trigger 2:
    Code:
    ;------------------------------------------
    Trigger StayedNotAtTiberias01
        WhenToTest CharacterTurnEnd
    
        Condition IsGeneral
              and HasAncType NobleTiberias
              and not EndedInSettlement
    
        Affects AtTiberias -1  Chance  100
        Affects NotAtTiberias 1 Chance 100
    The second trigger is quite the opposite of the previous one. In case our prince is in the field he gets the trait NotAtTiberias.
    If our prince is Not EndedInSettlement, so is he in no city at all.

    Trigger 3:

    Code:
    ;------------------------------------------
    Trigger StayedNotAtTiberias03
        WhenToTest CharacterTurnEnd
    
        Condition IsGeneral
              and HasAncType NobleTiberias
              and EndedInSettlement
              and not SettlementName Tiberias
    
        Affects AtTiberias -1  Chance  100
        Affects NotAtTiberias 1 Chance 100
    This one is the exact negation of our first trigger. He checks if our prince has ended up in another city, not Tiberias.

    Trigger 4:

    I have just found a way to exchange the traits, when our prince just left the city.

    Code:
    ;------------------------------------------
    Trigger StayedAtTiberias02
        WhenToTest CharacterSelected
    
        Condition IsGeneral
              and RemainingMPPercentage < 100
              and HasAncType NobleTiberias
              and Trait AtTiberias > 0
    
        Affects AtTiberias -1  Chance  100
        Affects NotAtTiberias 1 Chance 100


    In case our general has moved (Remaining MPPercentage < 100) and has the trait "AtTiberias", he is probably outside the city, so we give him the trait "NotAtTiberias". Our problem is now, when our prince returns back into the city, we have to wait until next turn.
    Yet I haven't found any condition, which checks the current position of a character, if somebody have an idea, please let me know!


    4. Step:
    Almost done, now open your campaign_script and EDB.

    First, campaign_script. Two monitors need to be scripted. These check the current position of our prince, using our previously created traits. This is the code:

    Code:
    ;Tiberias
    monitor_event CharacterTurnStart FactionIsLocal
    and FactionType jerusalem
    and Trait AtTiberias = 1
    and Trait NotAtTiberias < 1
    
        set_event_counter ruler_tiberias 1
    
            if I_EventCounter ruler_tiberias > 0
            and I_EventCounter pool_tiberias < 1
    
            set_recruit_pool Tiberias_Region 4 Feudal Spearmen
            set_event_counter pool_tiberias 1
        
            end_if
    end_monitor
    At the beginning of each turn of Jerusalem, our prince will be checked if he has the trait AtTiberias. If he has the trait, he is in Tiberias and not somewhere else. As a consequence, trait NotAtTiberias < 1, means 0.

    Now we set up an event counter, which we need later on in the EDU. But first we have to solve a problem of the EDU file. Our problem is we can not set an initial value to the number of units available as soon as the pool is activated, like in the descr_mercenaries. To remedy this, we use the command "set_recruit_pool" and hussaaa our problem is solved
    Otherwise you would have to wait the numbers of turns, which you have set up in the EDU for the respective recruit_pool. (Not exactly turn numbers, but points)

    Our parameters are:
    - Province: Tiberias_Region (descr_regions)
    - Number of units: 4 (depends on how many units you would like to have in your recruit_pool)
    - Unit: Feudal Spearmen

    Well, I have included an control counter, as well, even if I am not sure if it is necessary..

    Alright, next step EDB.
    Chose a building where you'd like to recruit your desired unit. I chose town_watch.
    Now, add a new recruit_pool for your unit.

    Code:
    recruit_pool  "Feudal Spearmen"  1   0.15   4  0  requires factions {  jerusalem, }   and event_counter ruler_tiberias 1
    Now we need our previously created, ruler_tiberias 1. We use it to switch the recruit_pool on and off, depending on the position of our prince.

    One last step!

    5. Step:

    To prevent other generals from using this recruit_pool, we have to check once more, if you prince is inside the city. Is he not, the pool has to be deactivated.

    Code:
    monitor_event CharacterTurnStart FactionIsLocal
    and FactionType jerusalem
    and Trait NotAtTiberias = 1
    and Trait AtTiberias < 1
    
        set_event_counter ruler_tiberias 0
        set_event_counter pool_tiberias 0
    
    end_monitor
    If our prince is not inside Tiberias, this monitor sets the event counters back to their basic values. Accordingly, our recruit_pool gets deactivated, as well as, our control counter.

    That's it!

    Note:
    This is script is far from being complete, for example I haven't tested yet what happen if your adding more units than you have defined as your max value in the EDU. Also, I have no clue, if the maximal number of units, defined for your recruit pool, is correctly calculated, since you fill up the pool again and again.
    Anyway, happy modding!

    Best regards,
    Ned

    Last edited by Aneirin; November 01, 2015 at 12:47 PM. Reason: Added a new trigger.
    Proud son of Aikanár and brother of Iskar

  2. #2
    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: How to script unit recruitment according to a characters title (Anc)

    The recruit pool will reset (accumulated replenishment and units available) to zero every time your EDB conditional counter is set to zero.
    I believe the set_recruit_pool entry overrules the EDB settings, eg setting it to 20 units should result in 20 available units even if it's limited to 4 in the EDB. I do recommend to test the latter as I am not 100% sure.










  3. #3
    Aneirin's Avatar of flowing verse
    Join Date
    Nov 2012
    Location
    Gododdin
    Posts
    2,734

    Default Re: How to script unit recruitment according to a characters title (Anc)

    Sure, I will give it a try
    Maybe I found another possibility with characterselected.
    As soon as I know more, I let you know!
    Proud son of Aikanár and brother of Iskar

  4. #4
    Aneirin's Avatar of flowing verse
    Join Date
    Nov 2012
    Location
    Gododdin
    Posts
    2,734

    Default Re: How to script unit recruitment according to a characters title (Anc)

    Updated my first post!
    I have added another trigger to check if our prince have just left the city.
    Proud son of Aikanár and brother of Iskar

  5. #5
    KEA's Avatar Senator
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    1,104

    Default Re: How to script unit recruitment according to a characters title (Anc)

    Use SettlementSelected in combination with GovernorAttribute. That way the recruitpool is updated everytime the player selects a settlement and the character with the right attribute is inside. Let's say we use the attribute Violence, that becomes "1" when the lord is inside his city, you would be able to check for it and export the counter to the campaign script. As a side effect you can use this monitor for any other lordship too without the need to add more triggers to the script: the lord of Jaffa has 1 Violence in the Jaffa, the lord of Antiochia 1 Violence inside Antiochia and so. The script would only check if the governor inside the city just selected happens to have 1 Violence or not (for reasons triggered in EDCT).

    Downsides:
    - It only works for the player. You need to set the counter to "true" on the beginning of the AI's turn. But that's recommended anyways otherwise the AI would never be able to recruit said unit because it wouldn't know that it had to move a certain character there
    - It doesn't work when the lord is inside his city but not the governor. In this case the player would need to move out other characters until the lord becomes the governor and then select the settlement again.
    - There is a problem when you click through settlements. You clearly have to deselect the one settlement before the event SettlementSelected fires again.

  6. #6
    Aneirin's Avatar of flowing verse
    Join Date
    Nov 2012
    Location
    Gododdin
    Posts
    2,734

    Default Re: How to script unit recruitment according to a characters title (Anc)

    Thank's for your suggestions, I'll give it a shot!
    Proud son of Aikanár and brother of Iskar

  7. #7
    bitterhowl's Avatar Campidoctor
    Join Date
    Feb 2011
    Location
    Russian Feodality
    Posts
    1,695

    Default Re: How to script unit recruitment according to a characters title (Anc)

    I got same system in my submod for Westeros - when only general with lordship of one current settlement can recruit and build in this settlement. Withwnar helped me with it. We use anc with attribute Magic with unique value for each settlement. When governor with current attribute is in a current settlement recruiting and building are allowed.

    My sister, do you still recall the blue Hasan and Khalkhin-Gol?
    Russian warship is winning. Proofs needed? Go find yourself!

  8. #8
    Aneirin's Avatar of flowing verse
    Join Date
    Nov 2012
    Location
    Gododdin
    Posts
    2,734

    Default Re: How to script unit recruitment according to a characters title (Anc)

    To handle it with an attribute seems quite sufficient, rather than creating extra traits.
    One could combine the title of the prince with an unique attribute.

    I'd be very glad if you could post an example!
    Proud son of Aikanár and brother of Iskar

  9. #9
    bitterhowl's Avatar Campidoctor
    Join Date
    Feb 2011
    Location
    Russian Feodality
    Posts
    1,695

    Default Re: How to script unit recruitment according to a characters title (Anc)

    Code:
    declare_counter lord_gov_status
    
    monitor_event SettlementTurnStart SettlementIsLocal
      set_counter lord_gov_status 0
    end_monitor
    
    monitor_event SettlementTurnStart SettlementIsLocal
      and SettlementName The_Dreadfort
      and GovernorAttribute Magic = 1
      set_counter lord_gov_status 1
    end_monitor
    
    monitor_event SettlementTurnStart SettlementIsLocal
      and SettlementName The_Dreadfort
    
      if I_CompareCounter lord_gov_status = 0
        filter_settlement_commands off The_Dreadfort
        inc_recruit_pool The_Dreadfort_Province -2 NE Bodyguard
        inc_recruit_pool The_Dreadfort_Province -2 Norse Swordsmen
        inc_recruit_pool The_Dreadfort_Province -2 Dismounted Feudal Knights
        inc_recruit_pool The_Dreadfort_Province -2 Feudal Knights
         end_if
      if I_CompareCounter lord_gov_status = 1
        filter_settlement_commands on The_Dreadfort
      end_if
      
    end_monitor
    
    --------------------------------------------------------------- this part is for SettlementSelected
    monitor_event SettlementSelected SettlementIsLocal
      set_counter lord_gov_status 0
    end_monitor
    
    monitor_event SettlementSelected SettlementIsLocal
      and SettlementName The_Dreadfort
      and GovernorAttribute Magic = 1
      set_counter lord_gov_status 1
    end_monitor
    
    monitor_event SettlementSelected SettlementIsLocal
      and SettlementName The_Dreadfort
    
      if I_CompareCounter lord_gov_status = 0
        filter_settlement_commands off The_Dreadfort
      end_if
          
      if I_CompareCounter lord_gov_status = 1
        filter_settlement_commands on The_Dreadfort
      end_if
      
    end_monitor
    that's it. This is for all situations - when your general starts turn in a settlement, or leave it during the turn, or arrives it during th turn. Also of course you need ancillary the_dreadfort with attribute Magic = 1

    My sister, do you still recall the blue Hasan and Khalkhin-Gol?
    Russian warship is winning. Proofs needed? Go find yourself!

  10. #10
    Aneirin's Avatar of flowing verse
    Join Date
    Nov 2012
    Location
    Gododdin
    Posts
    2,734

    Default Re: How to script unit recruitment according to a characters title (Anc)

    That is quite brilliant!

    May I updated my first post using your idea, cos your code is much more expedient than mine
    Proud son of Aikanár and brother of Iskar

  11. #11
    bitterhowl's Avatar Campidoctor
    Join Date
    Feb 2011
    Location
    Russian Feodality
    Posts
    1,695

    Default Re: How to script unit recruitment according to a characters title (Anc)

    Yes, you can. Half of credits goes to Withwnar, because he edited my first suggestions. Thread should be somewhere in scripting part of the forum.

    My sister, do you still recall the blue Hasan and Khalkhin-Gol?
    Russian warship is winning. Proofs needed? Go find yourself!

  12. #12
    Aneirin's Avatar of flowing verse
    Join Date
    Nov 2012
    Location
    Gododdin
    Posts
    2,734

    Default Re: How to script unit recruitment according to a characters title (Anc)

    Thank you!
    I'll definitely will!
    Proud son of Aikanár and brother of Iskar

  13. #13
    bitterhowl's Avatar Campidoctor
    Join Date
    Feb 2011
    Location
    Russian Feodality
    Posts
    1,695

    Default Re: How to script unit recruitment according to a characters title (Anc)


    My sister, do you still recall the blue Hasan and Khalkhin-Gol?
    Russian warship is winning. Proofs needed? Go find yourself!

  14. #14
    Aneirin's Avatar of flowing verse
    Join Date
    Nov 2012
    Location
    Gododdin
    Posts
    2,734

    Default Re: How to script unit recruitment according to a characters title (Anc)

    Great, I'll add that link as well.
    Proud son of Aikanár and brother of Iskar

Posting Permissions

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