Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: Test for current player controlling a certain region

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Stylix's Avatar MOS Team Member
    Join Date
    Apr 2008
    Location
    Alabama, U.S.A.
    Posts
    2,263

    Default Test for current player controlling a certain region

    I am trying to create code in the campaign_script.txt file that will test at the beginning of every faction's turn if they control a certain settlement.

    I have not been able to find a condition that tests, not for AI or Local control, but for the current faction's ownership.
    This is what I have so far:

    Code:
    declare_counter is_constantinople_contolled
     
    monitor_event PreFactionTurnStart SettlementName Constantinople
       and ???
       set_event_counter is_constantinople_contolled 1
    end_monitor
     
    monitor_event PreFactionTurnStart SettlementName Constantinople
      and ???
      set_event_counter is_constantinople_contolled 0
    end_monitor
    Any help or suggestions would be greatly appreciated!
    MOS v1.6.2+ Bug fixer 30 Dec 2013

  2. #2
    Stylix's Avatar MOS Team Member
    Join Date
    Apr 2008
    Location
    Alabama, U.S.A.
    Posts
    2,263

    Default Re: Test for current player controlling a certain region

    @RubiconDecision

    Thanks for the suggestion, but I want the current player, AI, Local, Rebel, whomever, to test at the beginning of their turn for control of the city. My ultimate goal is to allow for the recruitment of a particular unit if this city is controlled. As an example, if England controls Constantinople, they will be able to build this unit at one of their castles, but no one else will because they do not control the city. If another faction, should gain control of Constantinople, then they would be able to recruit this unit.
    Last edited by Stylix; January 31, 2011 at 02:52 PM.
    MOS v1.6.2+ Bug fixer 30 Dec 2013

  3. #3
    Stylix's Avatar MOS Team Member
    Join Date
    Apr 2008
    Location
    Alabama, U.S.A.
    Posts
    2,263

    Default Re: Test for current player controlling a certain region

    @RubiconDecision

    Interesting suggestion, but I would have to add a line in the EDB for each building level of that type and for each faction.
    For example:
    recruit_pool "Ostmen" 1 0.9 2 1 requires factions { england, } and event_counter is_constaninople_controlled_england=1
    recruit_pool "Ostmen" 1 0.9 2 1 requires factions { france, } and event_counter is_constaninople_controlled_france=1
    recruit_pool "Ostmen" 1 0.9 2 1 requires factions { venice, } and event_counter is_constaninople_controlled_venice=1

    And so on. Still it should work, I think I will test it now. However, I may just scale back my plans and only allow one faction to build this unit, assuming that they control Constantinople. I will have to think about it for a while. This is not the actual unit I want to add, just using your example.
    Thanks again for your help and have some +rep. (oops, have to spread it around first, will get you asap)
    Last edited by Stylix; January 31, 2011 at 04:31 PM. Reason: oops
    MOS v1.6.2+ Bug fixer 30 Dec 2013

  4. #4

    Icon1 Re: Test for current player controlling a certain region

    Stylix: Have you thought of using a ‘hidden resources’ for doing that? Take a look at this tutorial:

    [Tutorial] How-To: Make a ZoR by Vollendung

  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: Test for current player controlling a certain region

    script
    monitor_event PreFactionTurnStart FactionIsLocal
    and I_SettlementOwner Constantinople = england
    set_event_counter is_constantinople_contolled_england = 1
    end_monitor
    EDB
    recruit_pool "Ostmen" 1 0.9 2 1 requires factions { england, } and event_counter is_constaninople_controlled_england 1
    Please note the subtle changes to the code










  6. #6
    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: Test for current player controlling a certain region

    PreFactionTurnStart does not export a settlement, it only exports a faction. Which means the monitor will not work.

    monitor_event PreFactionTurnStart FactionIsLocal ;When to test - before the start of the players faction
    and I_SettlementOwner Constantinople = england ; Konstantinople has to be held by England
    set_event_counter is_constantinople_contolled_england = 1 ; then set the counter to it's new value
    end_monitor
    The counter remains on that value for all following factions until it gets reset:
    monitor_event PreFactionTurnStart FactionIsLocal ;When to test - before the start of the players faction
    and I_SettlementOwner Constantinople = england ; Konstantinople is not held by England
    set_event_counter is_constantinople_contolled_england = 0 ; then set the counter to it's new value
    end_monitor
    If you want it for all factions, you can either wrap the conditions into an "if" or make one monitor for each faction (much more memory intensive) by simply replacing FactionIsLocal with "FactionType [faction_name]"










  7. #7

    Icon1 Re: Test for current player controlling a certain region

    Quote Originally Posted by Gigantus View Post
    PreFactionTurnStart does not export a settlement, it only exports a faction. Which means the monitor will not work.


    The counter remains on that value for all following factions until it gets reset:


    If you want it for all factions, you can either wrap the conditions into an "if" or make one monitor for each faction (much more memory intensive) by simply replacing FactionIsLocal with "FactionType [faction_name]"
    Maybe this:
    Code:
    	monitor_event SettlementTurnStart SettlementName constaninople
    		if I_SettlementOwner constaninople = england
    		set_event_counter is_constantinople_contolled_england = 1
    	end_if
    		if I_SettlementOwner constaninople = france
    		set_event_counter is_constantinople_contolled_france = 1
    	end_if
    		if I_SettlementOwner constaninople = venice
    		set_event_counter is_constantinople_contolled_venice = 1
    	end_if
    	end_monitor
    
    	monitor_event SettlementTurnStart SettlementName constaninople
    		if I_EventCounter is_constantinople_contolled_england = 1
    		and not I_SettlementOwner constaninople = england
    		set_event_counter is_constantinople_contolled_england = 0
    	end_if
    		if I_EventCounter is_constantinople_contolled_france = 1
    		and not I_SettlementOwner constaninople = france
    		set_event_counter is_constantinople_contolled_france = 0
    	end_if
    		if I_EventCounter is_constantinople_contolled_venice = 1
    		and not I_SettlementOwner constaninople = venice
    		set_event_counter is_constantinople_contolled_venice = 0
    	end_if
    	end_monitor

  8. #8
    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: Test for current player controlling a certain region

    That should do the trick. There is a fancy way of coding 'not' - with an exclamation mark (and there is no need to test for the state of the event):

    Code:
        monitor_event SettlementTurnStart SettlementName constaninople
            if ! I_SettlementOwner constaninople = england
            set_event_counter is_constantinople_contolled_england = 0
        end_if
            if ! I_SettlementOwner constaninople = france
            set_event_counter is_constantinople_contolled_france = 0
        end_if
            if ! I_SettlementOwner constaninople = venice
            set_event_counter is_constantinople_contolled_venice = 0
        end_if
        end_monitor










  9. #9
    Stylix's Avatar MOS Team Member
    Join Date
    Apr 2008
    Location
    Alabama, U.S.A.
    Posts
    2,263

    Default Re: Test for current player controlling a certain region

    Thank you all for your replies. I have learned a great deal about coding since starting this 'little' project and it is only successful because of all the support I have received.

    Best regards,
    Stylix
    MOS v1.6.2+ Bug fixer 30 Dec 2013

  10. #10

    Default Re: Test for current player controlling a certain region

    Would this work?

    monitor_event FactionTurnEnd blah (do this for every faction)
    set_event_counter holds_constantinople 0
    end_monitor

    monitor_event FactionTurnStart england
    and I_SettlementOwner Constantinople = england
    set_event_counter holds_constantinople 1
    [repeat for every pertinent faction]
    end_monitor

    monitor_event GeneralCapturesSettlement
    and TargetSettlement Constantinople (I'm not certain this is the correct syntax)

    if I_SettlementOwner Constantinople = England
    set_event_counter holds_constantinople 1
    endif
    [rinse and repeat]
    end_monitor
    A well informed opinion is a well formed opinion.

  11. #11
    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: Test for current player controlling a certain region

    It would work, it just doesn't make much sense.

    You are using the same counter for every faction, which means the counter will always be 1.










  12. #12

    Default Re: Test for current player controlling a certain region

    The part on the top is to reset the counter at the end of a faction's turn, so if it is one for that faction, it won't be for any other faction, as they don't hold that settlement- the counter triggers at the beginning of a turn (if that faction holds the settlement) or when a general captures the settlement, and it always resets at the end of a turn. The only real benifit that I can see from it is a simplified EDB system.
    A well informed opinion is a well formed opinion.

  13. #13
    Squid's Avatar Opifex
    Patrician Artifex Technical Staff

    Join Date
    Feb 2007
    Location
    Frozen waste lands of the north
    Posts
    17,751
    Blog Entries
    3

    Default Re: Test for current player controlling a certain region

    The question still is why use a script when you can accomplish the same thing with a hidden_resource.
    Under the patronage of Roman_Man#3, Patron of Ishan
    Click for my tools and tutorials
    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -----Albert Einstein

  14. #14
    Stylix's Avatar MOS Team Member
    Join Date
    Apr 2008
    Location
    Alabama, U.S.A.
    Posts
    2,263

    Default Re: Test for current player controlling a certain region

    Quote Originally Posted by Sqυιd View Post
    The question still is why use a script when you can accomplish the same thing with a hidden_resource.
    If I understand the hidden resource, I would have to add it to every region because I want any faction, anywhere, to be be able to build that unit provided that they hold the key city and have the correct building in any settlement that they control. If I only wanted to allow a faction to build it in the key city settlement, then I agree that the hidden resource would be the way to go.
    MOS v1.6.2+ Bug fixer 30 Dec 2013

  15. #15

    Default Re: Test for current player controlling a certain region

    You might use a script if you've run out of hidden resources already, if you want to link the event to mercenaries, or if you want the faction to control the settlement to recruit the unit, while still being able to recruit the unit anywhere.
    A well informed opinion is a well formed opinion.

  16. #16
    Squid's Avatar Opifex
    Patrician Artifex Technical Staff

    Join Date
    Feb 2007
    Location
    Frozen waste lands of the north
    Posts
    17,751
    Blog Entries
    3

    Default Re: Test for current player controlling a certain region

    try putting the following into the building in question, don't forget to add the hidden_resource to the Constantinople region.

    Code:
    faction_capability
    { 
         recruit_pool "Ostmen" 1 0.4 2 1 requires factions { ireland, } requires hidden_resource constantinople
         recruit_pool "Ostmen" 1 0.9 2 1 requires factions { england, } requires hidden_resource constantinople
    }
    Under the patronage of Roman_Man#3, Patron of Ishan
    Click for my tools and tutorials
    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -----Albert Einstein

  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: Test for current player controlling a certain region

    Wouldn't that only make the unit available in the region that has the hidden_resource?

    The goal here was that the faction holds that one particular settlement and then has a certain level of building. Both together enable the global recruitment of a unit.

    If you combine my base from posts 8 and 10 and apply it to all factions then you don't need to reset the counter. All you need to do is then to add your building level requirement to the recruitment condition










  18. #18
    Squid's Avatar Opifex
    Patrician Artifex Technical Staff

    Join Date
    Feb 2007
    Location
    Frozen waste lands of the north
    Posts
    17,751
    Blog Entries
    3

    Default Re: Test for current player controlling a certain region

    No, its a faction capability, anything in there applies faction wide, or at least it did in RTW, provided the conditions were met (i.e. control Constantinople).
    Under the patronage of Roman_Man#3, Patron of Ishan
    Click for my tools and tutorials
    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -----Albert Einstein

  19. #19
    Stylix's Avatar MOS Team Member
    Join Date
    Apr 2008
    Location
    Alabama, U.S.A.
    Posts
    2,263

    Default Re: Test for current player controlling a certain region

    @Squid

    Quote Originally Posted by Mythic Commodore
    For example, the america hidden resource is used to ensure that the Spanish and Portuguese can only train Conquistadores in the New World.
    This is a quote from a quide I was going by to help me with the EDB. I was thinking, using this as an example, that by only putting the hidden resource in the regions of the new world, recruitment would be limited to a certain geographic region. I may be totally wrong, I am new at this level of coding, but if I am then how do I limit a unit to being recruited in just one (or a limited number) of regions?
    MOS v1.6.2+ Bug fixer 30 Dec 2013

  20. #20
    Squid's Avatar Opifex
    Patrician Artifex Technical Staff

    Join Date
    Feb 2007
    Location
    Frozen waste lands of the north
    Posts
    17,751
    Blog Entries
    3

    Default Re: Test for current player controlling a certain region

    Quote Originally Posted by Stylix View Post
    @Squid



    This is a quote from a quide I was going by to help me with the EDB. I was thinking, using this as an example, that by only putting the hidden resource in the regions of the new world, recruitment would be limited to a certain geographic region. I may be totally wrong, I am new at this level of coding, but if I am then how do I limit a unit to being recruited in just one (or a limited number) of regions?
    There are two capability sections for each building, though I don't think the second is used in vanilla, and hence likely not in any or at least many mods.

    Code:
            wooden_wall city requires factions { northern_european, mesoamerican, middle_eastern, eastern_european, greek, southern_european, } 
            {
                convert_to 2
                capability
                {
                    recruit_pool "Conquistadores"  1   0.4   3  0  requires factions { spain, portugal, }  and hidden_resource america
                }
                faction_capability
                {
                    recruit_pool "Dismounted Conquistadores"  1   0.4   3  0  requires factions { spain, portugal, }  and hidden_resource america
    
                }
                material wooden
                construction  2 
                cost  1200 
                settlement_min town
                upgrades
                {
                    stone_wall
                }
            }
    The blue part corresponds to what the tutorial you're referring to says, any recruitment lines in there are limited to the settlement in which the hidden resource occurs. The red part is what I am talking about. In the case of the recruitment line you see in my example, conquistadors would only be recruitable in a settlement with the america hidden_resource, but dismounted_conquistadors would be recruitable in all Spanish and Portuguese settlement as long as the Spain and Portugal controlled any settlement with the america hidden_resource.
    Under the patronage of Roman_Man#3, Patron of Ishan
    Click for my tools and tutorials
    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -----Albert Einstein

Page 1 of 2 12 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
  •