Page 2 of 2 FirstFirst 12
Results 21 to 31 of 31

Thread: Building only buildable when character with a specific trait is in settlement

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

    Default Re: Building only buildable when character with a specific trait is in settlement

    Here is the code. I added Inluence attribute 1 threshold to Factionleader trait. I'm using Artist's Gallery building as a template.
    EDB entry, this building has some factionwide effects depend where is FL and amount of his Authority.
    Code:
    building art
    {
        levels artist_studio artist_gallery 
        {
            artist_studio requires factions { all, } 
            {
                capability
                {
                    happiness_bonus bonus 1
                }
                material wooden
                construction  1 
                cost  1000 
                settlement_min town
                upgrades
                {
                    artist_gallery requires event_counter capital 1
                }
            }
            artist_gallery requires factions { all, }
            {
                capability
                {
                     law_bonus bonus 2 requires factions { all, } and not event_counter  low_authority 1 and not event_counter ai_player 1 and event_counter  leader_capital 1 
                    law_bonus bonus -1 requires  factions { all, } and not event_counter low_authority 1 and not  event_counter ai_player 1 and event_counter no_leader_capital 1
                     law_bonus bonus -2 requires factions { all, } and not event_counter  ai_player 1 and event_counter leader_capital 1 and event_counter  low_authority 1
                    law_bonus bonus -4 requires factions {  all, } and  not event_counter ai_player 1 and not event_counter  leader_capital 1 and event_counter low_authority 1
                }
                faction_capability
                {
                 law_bonus bonus 1 requires factions { all, } and not  event_counter low_authority 1 and not event_counter ai_player 1 and  event_counter leader_capital 1
                happiness_bonus bonus 1  requires factions { all, } and not event_counter low_authority 1 and not  event_counter ai_player 1 and event_counter leader_capital 1
                law_bonus bonus -3 requires factions { all, } and  not event_counter ai_player 1 and event_counter low_authority 1 
                 happiness_bonus bonus -2 requires factions { all, } and not  event_counter ai_player 1 and event_counter low_authority 1 
                 law_bonus bonus -1 requires factions { all, } and not event_counter  ai_player 1 and not event_counter low_authority 1 and event_counter  no_leader_capital 1
                happiness_bonus bonus -1 requires  factions { all, } and not event_counter ai_player 1 and not  event_counter low_authority 1 and event_counter no_leader_capital 1
                
                
                }
                material wooden
                construction  1
                cost  2000 
                settlement_min town
                upgrades
                {
                }
            }
        }
        plugins 
        {
        }
    }


    Code:
    monitor_event SettlementSelected SettlementIsLocal
    set_event_counter capital 0
    end_monitor
    
    monitor_event CharacterTurnEnd IsFactionLeader
    and DistanceCapital = 0
    set_event_counter no_leader_capital 0
    set_event_counter leader_capital 1
    end_monitor
    
    monitor_event CharacterTurnEnd IsFactionLeader
    and DistanceCapital != 0
    set_event_counter no_leader_capital 1
    set_event_counter leader_capital 0
    end_monitor
    
    
    monitor_event CharacterSelected IsFactionLeader
    and DistanceCapital != 0
    set_event_counter leader_capital 0
    set_event_counter no_leader_capital 1
    end_monitor
    
    monitor_event CharacterSelected TrueCondition
            set_event_counter no_leader_capital 1
            set_event_counter leader_capital 0
    end_monitor
    
    
    monitor_event SettlementSelected GovernorAttribute Influence = 1
    and I_EventCounter leader_capital = 1
    set_event_counter capital 1
    end_monitor
    
    monitor_event AddedToBuildingQueue BuildingName = artist_gallery
    set_event_counter capital 0
    set_event_counter leader_capital 0
    end_monitor
    
    monitor_event SettlementTurnEnd SettlementIsLocal
    set_event_counter capital 0
    end_monitor
    
    monitor_event SettlementTurnEnd GovernorAttribute Influence = 1
    set_event_counter capital 1
    end_monitor
    This is additional part for nullifying counters, but since I've added AddedToBuildingQueve monitor I doubt this part is still necessary.
    Code:
    monitor_event ButtonPressed ButtonPressed character_info_prev_item_cycle
            campaign_wait 0.1
            
            set_event_counter capital 0
    end_monitor
    
    monitor_event ButtonPressed ButtonPressed character_info_next_item_cycle
            campaign_wait 0.1
            
            set_event_counter capital 0
    end_monitor
    
    monitor_event ButtonPressed ButtonPressed settlement_info_prev_item_cycle
            set_event_counter capital 0
    end_monitor
    
    monitor_event ButtonPressed ButtonPressed settlement_info_next_item_cycle
            set_event_counter capital 0
    end_monitor
    
    monitor_event ShortcutTriggered ShortcutTriggered select_next_selected
            campaign_wait 0.1
            
            set_event_counter capital 0
    end_monitor
    
    monitor_event ShortcutTriggered ShortcutTriggered select_prev_selected
            campaign_wait 0.1
            
            set_event_counter capital 0
    end_monitor
    The only limitations for this script is that you have to select capital settlement first after turn start. I will fix it in my case by adding message for the player to force him to build this building because it's absence fires negative factionwide effects.

    Here's the video example of how it works. At turn 2 FL died so I had to move new FL to capital to continue. The whole idea of my script about King's Court is that CeasedFactionLeader event will nullify King's Court in capital and gathering of new one will depend on newcoming FL Authority attribute.

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

  2. #22

    Default Re: Building only buildable when character with a specific trait is in settlement

    This is essentially the same script as before; using SettlementSelected and testing the governor's attribute value. You've just added an extra condition: 'and I_EventCounter leader_capital = 1', but whether or not this condition is satisfied doesn't change anything about the porosity of the SettlementSelected mechanic. The issues I raised before still apply here. The main difference with this example isn't the capital bit but the fact that there's only one building involved (as opposed to multiple clan buildings that might be available simultaneously).

    Also, I think a few of these monitors are unnecessary for what you're trying to do. The SettlementTurnEnd monitors aren't doing anything because your building only takes 1 turn to construct which means it's finished before SettlementTurnEnd fires. The CharacterSelected monitors also aren't doing anything. The ShortcutTriggered monitors aren't needed because shortcuts actually do trip the SettlementSelected event. The ButtonPressed monitors are still needed to limit the building availability before it's been added to the queue - they're just not a complete solution as I've already mentioned. The CharacterTurnEnd monitors should probably be CharacterTurnStart monitors to account for the case where the faction leader dies by any means between turns (in this scenario, the capital building would be available wherever the new leader happens to be, not necessarily the capital).

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

    Default Re: Building only buildable when character with a specific trait is in settlement

    Well, in my case with only one building it works as should be - only one building in one settlement even if FL could reach two settlements in one turn.

    When FL dies (it was multiple times during testing) when building was in queue - building finished and then FL dies, so looks like death comes not at the turn end but at the turn start. If building wasn't in queue - it disappeared from building browser.

    The main problem is that first tier doesn't work with event_counter condition, so for multiple clan buildings one should have number of pre-existing first tier buildings. So, we go to next variant -

    monitor_event SettlementSelected GovernorAttribute Whatever = 1
    and not GovernorBuildingExists clan_a_building
    and not GovernorBuildingExists clan_b_building
    and not GovernorBuildingExists clan_c_building
    historic_event clan_a_proposal true
    end_monitor

    monitor_event EventCounter EventCounterType clan_a_proposal_accepted
    and EventCounter = 1
    if I_SettlementSelected Tokyo
    create_building Tokyo clan_a_building
    set_event_counter clan_a_proposal_accepted 0
    end_if
    ...
    end_monitor
    end_if

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

  4. #24

    Default Re: Building only buildable when character with a specific trait is in settlement

    Quote Originally Posted by bitterhowl View Post
    Well, in my case with only one building it works as should be - only one building in one settlement even if FL could reach two settlements in one turn.
    It doesn't look like you're selecting the other settlement in your video after moving the faction leader over. Ironically, you're using the trick I mentioned earlier to open the building browser for that settlement without tripping the SettlementSelected event (by moving a character into the settlement). This will be a problem for any character at any settlement on the map, not just moving the FL to another settlement within his movement range - it will allow the building to be built anywhere.

    And just logically, looking at the script, the only thing that sets the 'capital' counter to 1 and allows the building to be available for construction is the 'SettlementSelected GovernorAttribute Influence = 1' monitor (the SettlementTurnEnd monitors don't do anything). If the FL ends his turn in the capital and then moves to a different settlement on the next turn and that settlement is selected, all of the conditions for that monitor will logically be met and the 'capital' counter will be set to 1.

    Quote Originally Posted by bitterhowl View Post
    When FL dies (it was multiple times during testing) when building was in queue - building finished and then FL dies, so looks like death comes not at the turn end but at the turn start. If building wasn't in queue - it disappeared from building browser.
    The fact that the building finishes even after the FL dies is the expected behavior from what I'm seeing in your script, and it seems like a bug that would be easily fixed by using CharacterTurnStart. It doesn't really matter when the FL dies, it could be due to age, assassination, battle, etc., but it always happens before CharacterTurnStart. The CharacterTurnStart event won't even fire if the character dies, so you could use order of operations:

    Code:
    monitor_event PreFactionTurnStart FactionType your_faction
     set_event_counter leader_capital 0 ;default assumption
    end_monitor
    
    monitor_event CharacterTurnStart IsFactionLeader
    and DistanceCapital == 0
     set_event_counter leader_capital 1
    end_monitor
    For reference, the execution order for things at the start of the turn is:

    PreFactionTurnStart > CharacterTurnStart > SettlementTurnStart > FactionTurnStart

    Quote Originally Posted by bitterhowl View Post
    The main problem is that first tier doesn't work with event_counter condition, so for multiple clan buildings one should have number of pre-existing first tier buildings. So, we go to next variant -
    Setting aside the aforementioned problems with SettlementSelected, this is just going back to post #14 - it's a guild with more steps and more bugs. This would also be somewhat more annoying than a guild which gets offered once every ~10 turns if conditions are still met, whereas this script would offer the yes/no every time you select the settlement. You could easily script a cool-down counter... but like... you're basically scripting a guild.

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

    Default Re: Building only buildable when character with a specific trait is in settlement

    I've just repeated test and make video, 2 attempts with selecting another settlement and with only sending FL there without selecting settlement itself - same result, construction in second settlement is not allowed, building doesn't appear in building browser. The key thing is AddedToBuildingQueue monitor which set both counters to 0. If you need I'll post video tomorrow.

    I'm not having a goal to win the discussion with tricky ways. I'm making ny own mod and answered to TS's request to help, that's all.

    By the way, IDK why this changed

    monitor_event CharacterTurnEnd IsFactionLeader
    and DistanceCapital = 0
    set_event_counter no_leader_capital 0
    set_event_counter leader_capital 1
    end_monitor

    This way it's not working. It should be turn start.
    Last edited by bitterhowl; February 05, 2024 at 05:33 AM.

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

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

    Default Re: Building only buildable when character with a specific trait is in settlement

    Two attempts for showing different ways to select settlement/character does not allow build building twice at one turn and nowhere else than in capital city. Message with GRRM appears when SettlementSelected event fires with condition "GovernorAttribute Influence = 1" match.

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

  7. #27

    Default Re: Building only buildable when character with a specific trait is in settlement

    Quote Originally Posted by bitterhowl View Post
    I'm not having a goal to win the discussion with tricky ways. I'm making ny own mod and answered to TS's request to help, that's all.
    I'm going to keep pointing out the bugs in your scripts because this is an interesting topic and every time you've posted a sample in this thread, it's gotten incrementally closer to a 100% bug free version of OP's original request for governor-dependent construction. If we keep going like this, we're going to have a solution soon!

    I like the AddedToBuildingQueue monitor; that addresses at least one of the issues I raised earlier about simultaneous construction. But I think there are still bugs. If you don't add the building to the queue, and move the FL out of the capital to another settlement, then select the other settlement, the building will probably be available for construction there. And then there's still the problem of moving characters - once you select the settlement with the FL, the 'capital' counter is set to 1, so now you just need to access the building browser of any other settlement on the map by moving a character in and the building will be available in that random settlement as well. There's also the issue of moving the capital to a different settlement but this can be handled with FactionNewCapital.

    I had a shower thought that might be of some help: the game doesn't disappear buildings from the browser when their conditions are no longer met.

    This means we can use a short timer to set the building condition event counter back to 0 and then we don't have to worry about all of the possible ways to access the building browser. The only caveat being that the building would need to be selected by double-clicking, it's the only way that would be fast enough to open the browser before the building is no longer available. But it would work for buildings of any number of levels, irrespective of how many turns the building takes to construct, which settlement is selected first/last, which settlement the governor starts/end his turn in, and without needing any yes/no events. Of course it still doesn't work for the AI because it's based on the SettlementSelected event.

    Timer-Based Governor-Dependent Construction

    campaign_script.txt

    Code:
        monitor_event FactionTurnStart TrueCondition
            set_event_counter building_available 0 ;replicate for all clan counters
        end_monitor
        
        monitor_event SettlementSelected GovernorAttribute Magic == 100 ;replicate entire monitor for all clan buildings
            set_event_counter building_available 1
            campaign_wait 0.3 ;lower values don't work consistently for me
            set_event_counter building_available 0
        end_monitor
        
        monitor_event ButtonPressed ButtonPressed end_turn
            set_event_counter building_available 1 ;replicate for all clan counters
        end_monitor
        
        monitor_event ButtonPressed ButtonPressed settlement_info_next_item_cycle
            set_event_counter building_available 0 ;replicate for all clan counters
        end_monitor
        
        monitor_event ButtonPressed ButtonPressed settlement_info_prev_item_cycle
            set_event_counter building_available 0 ;replicate for all clan counters
        end_monitor

    export_descr_buildings.txt

    Code:
    building test_building
    {
        levels test_building_a
        {
            test_building_a requires factions { england, } and event_counter building_available 1
            {
                capability
                {
                }
                material wooden
                construction 2
                cost 1000
                settlement_min village
                upgrades
                {
                }
            }
        }
        plugins
        {
        }
    }

    export_descr_character_traits.txt

    Code:
    Trait GovernorID
        Characters all
        Hidden
        Level GovernorID
            Description hidden_desc
            EffectsDescription hidden_desc
            Threshold 1
            Effect Magic 100

    There are necessary associated text entries in export_buildings.txt and export_vnvs.txt.


    The above is the simplest version of the concept: the governor can go around from settlement to settlement on the same turn and begin construction of the test_building as many times as the player wants.

    If we wanted to limit construction to one unique building on the map, we could use AddedToBuildingQueue and FactionBuildingExists, but since there's no way to test if a building is only in a queue somewhere, the building would necessarily need to take 1 turn to construct.

    Timer-Based Unique Building Governor-Dependent Construction

    campaign_script.txt

    Code:
        monitor_event FactionTurnStart TrueCondition
            set_event_counter building_available 0
            set_event_counter building_not_in_queue 1
        end_monitor
        
        monitor_event SettlementSelected GovernorAttribute Magic == 100
        and not FactionBuildingExists test_building_a
            set_event_counter building_available 1
            campaign_wait 0.3
            set_event_counter building_available 0
        end_monitor
        
        monitor_event ButtonPressed ButtonPressed end_turn
            set_event_counter building_available 1
            set_event_counter building_not_in_queue 1
        end_monitor
        
        monitor_event ButtonPressed ButtonPressed settlement_info_next_item_cycle
            set_event_counter building_available 0
        end_monitor
        
        monitor_event ButtonPressed ButtonPressed settlement_info_prev_item_cycle
            set_event_counter building_available 0
        end_monitor
        
        monitor_event AddedToBuildingQueue BuildingName test_building_a
            set_event_counter building_not_in_queue 0
        end_monitor

    export_descr_buildings.txt

    Code:
    building test_building
    {
        levels test_building_a
        {
            test_building_a requires factions { england, } and event_counter building_available 1 and event_counter building_not_in_queue 1
            {
                capability
                {
                }
                material wooden
                construction 1
                cost 1000
                settlement_min village
                upgrades
                {
                }
            }
        }
        plugins
        {
        }
    }



    Now, for your mod, where the faction leader needs to be present in the current faction capital, it's difficult because the SettlementSelected event doesn't export character which prevents us from attaching the DistanceCapital condition, and that's the only condition that tells us if a character is in the capital. The CharacterTurnStart and CharacterTurnEnd monitors aren't useful because they only tell us if the FL was in the capital at the start or end of the turn, not where he is during the turn.

    The only thing I can think of to address this is to use Withwnar's trick for effectively converting any event condition into an I_ condition by spawning a script-faction character, then hopefully you can find a way to use DistanceCapital with SettlementSelected. I can't find Withwnar's thread at the moment, it was probably the most significant bit of scripting ever contributed to TWC, now deprecated due to EOP.
    Last edited by Callistonian; February 08, 2024 at 02:12 AM.

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

    Default Re: Building only buildable when character with a specific trait is in settlement

    First of all - sorry for my emotional response, you're right. Yes, I hope we'll finish this script here by brainstorming. You was right about second character selected case - if another character is inside capital city while FL is there, in my version of code it was possible to select him, leave settlement, go to neighbours without selecting that settlement and capital building will be available there. I solved it by ScrollClosed TrueCondition event, where I set event_counter capital 0. Also - looks like I was mistaken that first tier of building doesn't work with event counter condition.

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

  9. #29
    Razor's Avatar Licenced to insult
    Join Date
    Apr 2004
    Location
    Deventer, The Netherlands
    Posts
    4,075

    Default Re: Building only buildable when character with a specific trait is in settlement

    By the way: I'm still reading this and trying to wrap my head around it all. I'm just a rookie at scripting and have nothing useful to add compared to you guys. Just saying...

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

    Default Re: Building only buildable when character with a specific trait is in settlement

    Well, ScrollClosed TrueCondition event leads to building persistence in building browser not being built at all. SettlementTurnEnd event changing event_counter capital to 1 does not work. But ButtonPressed ButtonPressed end_turn works. So now I think it's a final version of my script for unique capital building.

    If we'll return to initial task making clan buildings in any settlement where particular character is - this code should be changed, we should check if faction already has such a building and if not then create additional counter for the moment when your building was added to building queue.

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

  11. #31

    Default Re: Building only buildable when character with a specific trait is in settlement

    Quote Originally Posted by bitterhowl View Post
    Well, ScrollClosed TrueCondition event leads to building persistence in building browser not being built at all. SettlementTurnEnd event changing event_counter capital to 1 does not work. But ButtonPressed ButtonPressed end_turn works. So now I think it's a final version of my script for unique capital building.
    Yeah, construction happens between ButtonPressed end_turn and SettlementTurnEnd. You should post your script.

    Quote Originally Posted by bitterhowl View Post
    If we'll return to initial task making clan buildings in any settlement where particular character is - this code should be changed, we should check if faction already has such a building and if not then create additional counter for the moment when your building was added to building queue.
    Methinks it depends on how, exactly, the script writer wants this to work. Does the governor with the special trait need to remain in the settlement from the time the building is added to the queue to the time it is completed, or does he only need to be there when the building is added to the queue? Does the building take more than one turn to complete? I still don't think it's possible to do any of this completely bug-free, but picking the most optimal, least bug infested script will depend on the answers to such questions.

Page 2 of 2 FirstFirst 12

Posting Permissions

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