Results 1 to 14 of 14

Thread: Religion change script not working for local faction

  1. #1
    4zumi's Avatar This one sparks joy
    Join Date
    Feb 2015
    Location
    HRE - Aquis Mattiacis
    Posts
    1,239

    Default Religion change script not working for local faction

    Hello again, I would need some help... again

    I made several working religion changes in the same script, but something seems to be not right with this one, even if i looked at every inch of it and can not find out what is wrong.

    Essentially I want to make catholic HRE convert to Protestantism (yes, the religion is implemented and working). This is only the first faction that shall have this option, hence the many event_counters at the start.

    My problem comes ingame. I play as HRE, the event pops up, I agree and nothing happens (i tested both agree + decline, always the same)

    But if I now play as f.e. Ireland, I get 50% of the time (because of random_numbers) the notification, that the HRE now follows Luther, and i can see that Protestantism has sprung up in the settlements.

    If I force the trigger ("protestant_conversion_accepted_hre = 1") via script and play as HRE, everything works.

    But I can not for the life of me figure out why it does not work with the yes/no decision while all the other religion changes work.

    Please help me Modding Workshop, you are my only hope...

    Here is the complete code:

    ;------------------- We will make us some Prostatas -------------------;

    monitor_event FactionTurnStart

    ;setup Protestant CONVERSION counters

    add_events
    event counter protestant_conversion_accepted_hre
    event counter protestant_conversion_declined_hre

    event counter protestant_conversion_accepted_england
    event counter protestant_conversion_declined_england

    event counter protestant_conversion_accepted_scotland
    event counter protestant_conversion_declined_scotland

    event counter protestant_conversion_accepted_ireland
    event counter protestant_conversion_declined_ireland

    event counter protestant_conversion_accepted_spain
    event counter protestant_conversion_declined_spain

    event counter protestant_conversion_accepted_portugal
    event counter protestant_conversion_declined_portugal

    event counter protestant_conversion_accepted_france
    event counter protestant_conversion_declined_france

    event counter protestant_conversion_accepted_venice
    event counter protestant_conversion_declined_venice

    event counter protestant_conversion_accepted_milan
    event counter protestant_conversion_declined_milan

    event counter protestant_conversion_accepted_sicily
    event counter protestant_conversion_declined_sicily

    event counter protestant_conversion_accepted_hungary
    event counter protestant_conversion_declined_hungary

    event counter protestant_conversion_accepted_poland
    event counter protestant_conversion_declined_poland

    event counter protestant_conversion_accepted_denmark
    event counter protestant_conversion_declined_denmark

    event counter protestant_conversion_accepted_norway
    event counter protestant_conversion_declined_norway

    event counter protestant_conversion_accepted_lithuania
    event counter protestant_conversion_declined_lithuania

    event counter protestant_emerge
    event counter protestant_emerge_not

    event counter protestant_conversion_timer
    date 0
    end_add_events

    ;generate_random_counter protestant_conversion_timer 1 50

    set_event_counter protestant_conversion_accepted_hre 0
    set_event_counter protestant_conversion_declined_hre 0

    set_event_counter protestant_emerge_not 1
    set_event_counter protestant_emerge 0

    terminate_monitor

    end_monitor

    monitor_event PreFactionTurnStart FactionType hre

    set_event_counter protestant_emerge_not 1
    set_event_counter protestant_emerge 0

    if I_EventCounter protestant_conversion_accepted_hre = 1
    set_event_counter protestant_emerge_not 0
    set_event_counter protestant_emerge 1
    end_if


    end_monitor


    monitor_event FactionTurnStart FactionType FactionIsLocal

    inc_event_counter protestant_conversion_timer 1

    if I_EventCounter protestant_conversion_accepted_hre = 1
    terminate_monitor
    end_if

    end_monitor

    monitor_event FactionTurnStart FactionType hre

    if I_EventCounter protestant_conversion_timer >= 3 ;218 = 1517
    and I_EventCounter protestant_conversion_accepted_hre = 0

    ;offer conversion to protestantism
    historic_event protestant_conversion true factions { hre, }

    ;if AI random chance to accept
    if I_IsFactionAIControlled hre

    generate_random_counter random_accept_hre 1 2
    if I_EventCounter random_accept_hre < 2
    set_event_counter protestant_conversion_accepted_hre 1
    end_if

    end_if

    terminate_monitor

    end_if


    end_monitor

    monitor_conditions I_EventCounter protestant_conversion_timer >= 2



    ;notify all factions that Protestantism is on the rise
    historic_event hre_idebt ;event/Lithuania_converts.bik

    terminate_monitor

    end_monitor

    monitor_conditions I_EventCounter protestant_conversion_accepted_hre = 1

    ;Three easy steps for conversion

    ;1 - Convert the people
    set_religion hre protestant
    change_population_religion hre protestant 75 catholic
    link_faction_ai hre default

    ;2 - Destroy the pagan buildings
    destroy_buildings hre catholic true
    destroy_buildings hre catholic_castle true

    ;3 - Disband the pagan units
    retire_characters hre priest

    ;notify all factions that Lithuania has converted and become Catholic
    historic_event lithuania_converts event/Lithuania_converts.bik

    set_event_counter protestant_emerge 1
    set_event_counter protestant_emerge_not 0

    terminate_monitor

    end_monitor
    Proudly under the patronage of King Athelstan of the Imperial House of Hader

    Author of
    Total Vanilla Beyond mod for Medieval 2 - Kingdoms &
    Developer of
    Total Bananas mod for Medieval 2 - Kingdoms (beta)

    Steam Workshop Mods for Rome 2, Warhammer, Warhammer 2

    Discord: zumi's cookie corner
    Fighting for launch of "Cookie Friday" and "No Pants Saturday"

  2. #2
    4zumi's Avatar This one sparks joy
    Join Date
    Feb 2015
    Location
    HRE - Aquis Mattiacis
    Posts
    1,239

    Default Re: Religion change script not working for local faction

    Ok,

    i solved it myself after a glass of fine whisky

    thanks, bye



    I would not do that...

    Spoiler Alert, click show to read: 


    I made the simple mistake by naming those two counters wrong like this:

    event counter protestant_conversion_accepted_hre
    event counter protestant_conversion_declined_hre

    It should be this:

    event counter protestant_conversion_hre_accepted
    event counter protestant_conversion_hre_declined

    and later just this

    protestant_conversion_hre

    ACCEPTED and DECLINED belong at the end, otherwise it will not work

    cheers

    and here the code in full:


    ;------------------- We will make us some Prostatas -------------------;

    monitor_event FactionTurnStart

    ;setup Protestant CONVERSION counters

    add_events
    event counter protestant_conversion_hre_accepted
    event counter protestant_conversion_hre_declined



    event counter protestant_emerge
    event counter protestant_emerge_not

    event counter protestant_conversion_timer
    date 0
    end_add_events

    ;generate_random_counter protestant_conversion_timer 1 50

    set_event_counter protestant_conversion_hre_accepted 0
    set_event_counter protestant_conversion_hre_declined 0

    set_event_counter protestant_emerge_not 1
    set_event_counter protestant_emerge 0

    terminate_monitor

    end_monitor

    monitor_event PreFactionTurnStart FactionType hre

    set_event_counter protestant_emerge_not 1
    set_event_counter protestant_emerge 0

    if I_EventCounter protestant_conversion_hre_accepted = 1
    set_event_counter protestant_emerge_not 0
    set_event_counter protestant_emerge 1
    end_if


    end_monitor


    monitor_event FactionTurnStart FactionType FactionIsLocal

    inc_event_counter protestant_conversion_timer 1

    if I_EventCounter protestant_conversion_hre_accepted = 1
    terminate_monitor
    end_if

    end_monitor

    monitor_event FactionTurnStart FactionType hre

    if I_EventCounter protestant_conversion_timer >= 3 ;218 = 1517
    and I_EventCounter protestant_conversion_hre_accepted = 0

    ;offer conversion to protestantism
    historic_event protestant_conversion_hre true factions { hre, }

    ;if AI random chance to accept
    if I_IsFactionAIControlled hre

    generate_random_counter random_accept_hre 1 2
    if I_EventCounter random_accept_hre < 2
    set_event_counter protestant_conversion_hre_accepted 1
    end_if

    end_if

    terminate_monitor

    end_if


    end_monitor

    monitor_conditions I_EventCounter protestant_conversion_timer >= 2



    ;notify all factions that Protestantism is on the rise
    historic_event hre_idebt ;event/Lithuania_converts.bik

    terminate_monitor

    end_monitor

    monitor_conditions I_EventCounter protestant_conversion_hre_accepted = 1

    ;Three easy steps for conversion

    ;1 - Convert the people
    set_religion hre protestant
    change_population_religion hre protestant 75 catholic
    link_faction_ai hre default

    ;2 - Destroy the pagan buildings
    destroy_buildings hre catholic true
    destroy_buildings hre catholic_castle true

    ;3 - Disband the pagan units
    retire_characters hre priest

    ;notify all factions that Lithuania has converted and become Catholic
    historic_event lithuania_converts event/Lithuania_converts.bik

    set_event_counter protestant_emerge 1
    set_event_counter protestant_emerge_not 0

    terminate_monitor

    end_monitor
    Proudly under the patronage of King Athelstan of the Imperial House of Hader

    Author of
    Total Vanilla Beyond mod for Medieval 2 - Kingdoms &
    Developer of
    Total Bananas mod for Medieval 2 - Kingdoms (beta)

    Steam Workshop Mods for Rome 2, Warhammer, Warhammer 2

    Discord: zumi's cookie corner
    Fighting for launch of "Cookie Friday" and "No Pants Saturday"

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

    Default Re: Religion change script not working for local faction

    Code:
    add_events
      event counter protestant_conversion_hre_accepted
      event counter protestant_conversion_hre_declined
    
      event counter protestant_emerge
      event counter protestant_emerge_not
    
      event counter protestant_conversion_timer
      date 0
    end_add_events
    You don't need to do that. It's essentially just declaring them, all with a starting value of 0. But an event counter that has not been 'declared' is still treated as existing and with a value of 0 (unlike normal counters which must be declared).

    i.e. A condition like "I_EventCounter xxx = 0" will still be true if that xxx event counter has never been encountered (declared or set) by the script up until that point.

    Having said that, I think it is good practice to 'declare' them because it documents the event counters involved in this script, which can be helpful to the scripter. And you can just do it like this instead, which is cleaner I think...

    Code:
    set_event_counter protestant_conversion_hre_accepted 0
    set_event_counter protestant_conversion_hre_declined 0
    
    set_event_counter protestant_emerge 0
    set_event_counter protestant_emerge_not 0
    
    set_event_counter protestant_conversion_timer 0
    "date 0" (add_events) is also known to not work with certain TPYs. historic events surely, not sure about event counters. http://www.twcenter.net/forums/showt...ot-not-working

  4. #4
    4zumi's Avatar This one sparks joy
    Join Date
    Feb 2015
    Location
    HRE - Aquis Mattiacis
    Posts
    1,239

    Default Re: Religion change script not working for local faction

    Thanks for the additional input.

    I kept myself very strict to the original Lithuania Conversion from the kingdoms expansion, where all the counters are declared too. And I think I will stick with that practice, as you mentioned, that it is helpful and cleaner... And I am not particulary known for my good coding ;P.

    The date 0 was also in the original code, so i kept it. But I will check out the link you provided. Thanks.

    @ all

    another little tidbit i found out.

    When I implemented the rest of the catholic factions, this little monitor needs to change or you get a ctd

    monitor_event FactionTurnStart FactionType FactionIsLocal

    inc_event_counter protestant_conversion_timer 1

    if I_EventCounter protestant_conversion_hre_accepted = 1
    terminate_monitor
    end_if

    end_monitor
    Change FactionType to slave and put the monitor unter the setup for all the event counters before everything faction related starts.
    Don't ask me why, but it works
    Proudly under the patronage of King Athelstan of the Imperial House of Hader

    Author of
    Total Vanilla Beyond mod for Medieval 2 - Kingdoms &
    Developer of
    Total Bananas mod for Medieval 2 - Kingdoms (beta)

    Steam Workshop Mods for Rome 2, Warhammer, Warhammer 2

    Discord: zumi's cookie corner
    Fighting for launch of "Cookie Friday" and "No Pants Saturday"

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

    Default Re: Religion change script not working for local faction

    Strange. I can't see why that would CTD. I'd be checking that those historic events are present in historic_events.txt: correctly spelt and uppercase.

    Something else though: it is highly advisable to replace monitor_conditions with an EventCounter monitor_event...

    Code:
    monitor_conditions I_EventCounter protestant_conversion_timer >= 2
    to
    Code:
    monitor_event EventCounter EventCounterType protestant_conversion_timer
      and EventCounter >= 2
    And:

    Code:
    monitor_conditions I_EventCounter protestant_conversion_hre_accepted = 1
    to
    Code:
    monitor_event EventCounter EventCounterType protestant_conversion_hre_accepted
      and EventCounter = 1
    A little bit more text to write but without the lag that monitor_conditions adds to your campaign. Every monitor_conditions adds more lag. Noticeable lag, especially when trying to scroll around the map when a character is selected.
    Last edited by Withwnar; March 20, 2019 at 09:24 AM.

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

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

    Default Re: Religion change script not working for local faction

    That mile of (unnecessary) event counter declarations made me smile - we all did that at the beginning 'til the day the light shone upon us' and revealed that event counters always exist in the zero state until they get changed by the script.










  7. #7
    4zumi's Avatar This one sparks joy
    Join Date
    Feb 2015
    Location
    HRE - Aquis Mattiacis
    Posts
    1,239

    Default Re: Religion change script not working for local faction

    @withwnar

    As far as I know, everything is spelled correctly and uppercase.

    I wonder if the monitor_condition for the religion change is necessary to make the change immediate after the player or the ai clicked accept.
    When would the suggested monitor event EventCounter EventCounterType get checked. Is it still immediately or after the turn end?

    @gig

    Awww, I made you smile
    May the Lord have mercy and shine with the light of three suns upon my head
    Proudly under the patronage of King Athelstan of the Imperial House of Hader

    Author of
    Total Vanilla Beyond mod for Medieval 2 - Kingdoms &
    Developer of
    Total Bananas mod for Medieval 2 - Kingdoms (beta)

    Steam Workshop Mods for Rome 2, Warhammer, Warhammer 2

    Discord: zumi's cookie corner
    Fighting for launch of "Cookie Friday" and "No Pants Saturday"

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

    Default Re: Religion change script not working for local faction

    EventCounter events fire as soon as the event counter in question changes value. It probably reacts even faster than monitor_conditions because the latter only fires every 1/20 of a second, which is effectively 'immediately' to us mere humans, so nothing in it.

    I think the vanilla script is using monitor_conditions for the same reason it's using it for the historic event yes/no response, that is: no good reason at all. Either these scripts were lifted from an earlier version of M2TW that didn't yet have the EventCounter event, or the scripter didn't know that EventCounter is a much better way to do it.

  9. #9

    Default Re: Religion change script not working for local faction

    Am I missing something, or is this a hideously overcomplicated way to do something that's pretty straightforward?

    You want a randomly triggered popup asking the player if they want to change their faction's religion, right?

  10. #10
    4zumi's Avatar This one sparks joy
    Join Date
    Feb 2015
    Location
    HRE - Aquis Mattiacis
    Posts
    1,239

    Default Re: Religion change script not working for local faction

    Yes and no.

    I want to script the Catholic/Protestant split, this is, thy it includes so many counters for each catholic faction.
    At one specific date (randomized with a random counter) every catholic faction gets asked if they want to change to Protestantism or remain catholic. This happens to the player, as well as to the AI (providing the AI with a 50/50 chance of picking convert or remain.

    The script above would be not the whole script, as this would include every monitors for every faction. This is just an example for the hre test faction
    Proudly under the patronage of King Athelstan of the Imperial House of Hader

    Author of
    Total Vanilla Beyond mod for Medieval 2 - Kingdoms &
    Developer of
    Total Bananas mod for Medieval 2 - Kingdoms (beta)

    Steam Workshop Mods for Rome 2, Warhammer, Warhammer 2

    Discord: zumi's cookie corner
    Fighting for launch of "Cookie Friday" and "No Pants Saturday"

  11. #11

    Default Re: Religion change script not working for local faction

    That's still not a very complicated thing to do, especially since it's only one date trigger.

  12. #12

    Default Re: Religion change script not working for local faction

    Par exemple:

    Code:
        monitor_event FactionTurnStart TrueCondition
            if I_EventCounter FactionCounter > [Catholic factions +1]
                terminate_monitor
            end_if
            if I_TurnNumber > [whatever date]
                generate_random_counter ProtestantSwitch 1 10 ; random number between 1 and 10
                if I_EventCounter ProtestantSwitch < 2 ; 10% chance of occurring each turn after the chosen date
                    ; HRE
                    if I_IsFactionAIControlled hre  ; HRE is AI
                        generate_random_counter HRESwitch 1 2 ; random number between 1 and 2
                        if I_EventCounter HRESwitch < 2 ; 50% chance of occurring
                           ;1 - Convert the people
                           set_religion hre protestant
                           change_population_religion hre protestant 75 catholic
                           link_faction_ai hre default
                           ;2 - Destroy the pagan buildings
                           destroy_buildings hre catholic true
                           destroy_buildings hre catholic_castle true
                           ;3 - Disband the pagan units
                           retire_characters hre priest
                           ;notify all factions that Lithuania has converted and become Catholic
                           historic_event lithuania_converts event/Lithuania_converts.bik
                           set_event_counter hre_protestant_emerge 1
                        end_if
                        inc_event_counter FactionCounter 1
                    end_if
                    if not I_IsFactionAIControlled hre  ; HRE is the human player
                        historic_event hre_conversion_question true factions { hre, } ; asking the human player if they want to change
    
                        while I_EventCounter hre_conversion_question_accepted = 0        ;;; while-loop to pause the script until a decision is made
                            and I_EventCounter hre_conversion_question_declined = 0
                        end_while
    
                        if I_EventCounter hre_conversion_question_accepted = 1
                           ;1 - Convert the people
                           set_religion hre protestant
                           change_population_religion hre protestant 75 catholic
                           link_faction_ai hre default
                           ;2 - Destroy the pagan buildings
                           destroy_buildings hre catholic true
                           destroy_buildings hre catholic_castle true
                           ;3 - Disband the pagan units
                           retire_characters hre priest
                           ;notify all factions that Lithuania has converted and become Catholic
                           historic_event lithuania_converts event/Lithuania_converts.bik
                           set_event_counter hre_protestant_emerge 1
                        end_if
                        inc_event_counter FactionCounter 1
                    end_if
                    ; repeat for other Catholic factions
                end_if
            end_if
        end_monitor
    Last edited by QuintusSertorius; March 26, 2019 at 04:13 AM.

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

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

    Default Re: Religion change script not working for local faction

    The placement of the terminate line means it will terminate after a single pass, after the local faction's turn. I am assuming it should ask every faction, regardless how long it takes, in which case simply add an increasing event_counter to each loop (AI and player) and then have a terminate IF loop look the total (catholic factions * 1).










  14. #14

    Default Re: Religion change script not working for local faction

    Ah, good catch. I forgot the sequencing.
    Last edited by QuintusSertorius; March 25, 2019 at 03:12 AM.

Posting Permissions

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