Results 1 to 12 of 12

Thread: Automatically destroy buildings when a city is conquered

  1. #1
    Cesco's Avatar Decanus
    Join Date
    Apr 2013
    Location
    Italia
    Posts
    595

    Default Automatically destroy buildings when a city is conquered

    I'm working on implementing an administration system in my mod, just like many other mods have already done: when you obtain another faction's city, her government building gets destroyed and you have to build yours.

    So, this is the building code in the export_descr-building:
    Code:
    building slave_administration 
    {
        levels slave_administration1 slave_administration2 
        {
            slave_administration1 requires factions { slave, } ;;;;;;;;;;;;;;; Podesteria
            {
                capability
                {
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; LIGHT INFANTRY
    		recruit_pool "Italian Militia Polearm"  0   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentLightInfantry 1
    		recruit_pool "Italian Militia Archers"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentLightInfantry 1
    		recruit_pool "Italian Militia Pikemen"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentLightInfantry 1
    		recruit_pool "Swiss Militia Pikemen URI"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Switzerland and not event_counter StopRecruitmentPikeInfantry 1
    		recruit_pool "Swiss Militia Pikemen BER"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Switzerland and not event_counter StopRecruitmentPikeInfantry 1
    		recruit_pool "Swiss Militia Pikemen SCH"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Switzerland and not event_counter StopRecruitmentPikeInfantry 1
    		recruit_pool "Swiss Militia Pikemen ZUR"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Switzerland and not event_counter StopRecruitmentPikeInfantry 1
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; SPEARMEN INFANTRY
    		recruit_pool "Hafsid Militia Spearmen"  1   0.5   4  0  requires factions { timurids, slave, } and hidden_resource Africa and not event_counter StopRecruitmentLightInfantry 1
    		recruit_pool "Hafsid Reform Spearmen"  1   0.5   4  0  requires factions { timurids, slave, } and hidden_resource Africa and not event_counter StopRecruitmentLightInfantry 1
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; MEDIUM INFANTRY
    		recruit_pool "Hafsid Militia Archers"  1   0.5   4  0  requires factions { middle_eastern, slave, } and hidden_resource Africa and not event_counter StopRecruitmentLightMissileInfantry 1
    		recruit_pool "Italian Militia Crossbowmen"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentLightCrossbowInfantry 1
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; GUN INFANTRY
    
    
    		recruit_pool "Hafsid Medium Cavalry"  1   0.5   4  0  requires factions { timurids, slave, } and hidden_resource Africa and not event_counter StopRecruitmentLightCavalry 1
                }
                material wooden
                construction  2 
                cost  600 
                settlement_min village
                upgrades
                {
                    slave_administration2
                }
            }
            slave_administration2  requires factions { slave, } ;;;;;;;;;;;;; Vicariato
            {
                capability
                {
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; LIGHT INFANTRY
    		recruit_pool "Italian Militia Polearm"  0   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentLightInfantry 1
    		recruit_pool "French Militia Polearm"  1   0.5   4  0  requires factions { france, slave, } and hidden_resource France or hidden_resource Savoy or hidden_resource Burgundy and not event_counter StopRecruitmentLightInfantry 1 
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; SPEARMEN INFANTRY
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; PIKE INFANTRY
    		recruit_pool "Italian Militia Pikemen"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentPikeInfantry 1
    		recruit_pool "Italian Professional Pike"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentPikeInfantry 1
    		recruit_pool "Italian Professional Pike Reform"  2   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentPikeInfantry 1
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; MEDIUM INFANTRY
    		recruit_pool "Italian Professional Targonieri"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentMediumInfantry 1
    		recruit_pool "Italian Professional Targonieri Reform"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentMediumInfantry 1
    		recruit_pool "Italian Professional Heavy Spearmen"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentMediumInfantry 1
    		recruit_pool "Italian Professional Ronconieri"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentMediumInfantry 1
    		recruit_pool "Italian Professional Ronconieri Reform"  2   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentMediumInfantry 1
    		recruit_pool "Swiss Militia Polearm URI"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Switzerland and not event_counter StopRecruitmentMediumInfantry 1
    		recruit_pool "Swiss Militia Polearm BER"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Switzerland and not event_counter StopRecruitmentMediumInfantry 1
    		recruit_pool "Swiss Militia Polearm SCH"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Switzerland and not event_counter StopRecruitmentMediumInfantry 1
    		recruit_pool "Swiss Militia Polearm ZUR"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Switzerland and not event_counter StopRecruitmentMediumInfantry 1
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; HEAVY INFANTRY
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; MISSILE INFANTRY
    		recruit_pool "Italian Militia Skirmishers"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentLightMissileInfantry 1
    		recruit_pool "Italian Militia Archers"  1   0.5   4  0  requires factions { slave, england, norway, crusading_orders, lithuania, poland, saxons, ireland, wales, spain, normans, egypt, portugal, milan, russia, mongols, denmark, venice, papal_states, sicily, novgorod, georgia, } and hidden_resource Italy and not event_counter StopRecruitmentLightMissileInfantry 1
    		recruit_pool "Italian Militia Crossbowmen"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentLightCrossbowInfantry 1
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; GUN INFANTRY
    		recruit_pool "Italian Professional Arquebusiers"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentHandgunInfantry 1 and not event_counter StopMercenaryRecruitment 1
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; MISSILE CAVALRY
    		recruit_pool "Italian Mounted Crossbowmen"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentLightCavalry 1
    		recruit_pool "Italian Mounted Handgunners"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentLightCavalry 1
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; LIGHT CAVALRY
    		recruit_pool "Italian Medium Cavalry"  1   0.5   4  0  requires factions { northern_european, eastern_european, southern_european, } and hidden_resource Italy and not event_counter StopRecruitmentLightCavalry 1
    		recruit_pool "Hungarian Heavy Cavalry"  1   0.5   4  0  requires factions { hungary, slave, } and hidden_resource Hungary or hidden_resource Serbia and not event_counter StopRecruitmentLightCavalry 1
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;; HEAVY CAVALRY
    		recruit_pool "Italian Heavy Cavalry"  1   0.5   4  0  requires factions { slave, england, norway, crusading_orders, lithuania, poland, saxons, ireland, wales, spain, normans, egypt, portugal, milan, russia, mongols, denmark, venice, papal_states, sicily, novgorod, georgia, } and hidden_resource Italy and not event_counter StopRecruitmentHeavyCavalry 1
    		recruit_pool "Italian Heavy Cavalry Reform"  1   0.5   4  0  requires factions { slave, england, norway, crusading_orders, lithuania, poland, saxons, ireland, wales, spain, normans, egypt, portugal, milan, russia, mongols, denmark, venice, papal_states, sicily, novgorod, georgia, } and hidden_resource Italy and not event_counter StopRecruitmentHeavyCavalry 1
                }
                material wooden
                construction  3 
                cost  1200 
                settlement_min town
                upgrades
                {
                }
            }
        }
        plugins 
        {
        }
    }
    and this is the script:
    Code:
     
    ; remove other policies from Siena
    monitor_event GeneralCaptureSettlement FactionType spain
    	destroy_buildings spain slave_administration false
    end_monitor
    
    
    monitor_event GiveSettlement TargetFactionType spain
    	destroy_buildings spain slave_administration false
    end_monitor
    
    
    monitor_event CityRebels TargetFactionType spain
    	destroy_buildings spain slave_administration false
    end_monitor
    
    
    monitor_event GovernorCityRebels TargetFactionType spain
    	destroy_buildings spain slave_administration false
    end_monitor
    
    
    ;monitor_event FactionTurnStart FactionType spain
    	;destroy_buildings spain slave_administration false
    ;end_monitor
    
    
    monitor_event BriberyMission FactionType spain
    	and MissionSuccessLevel > not_successful
    	destroy_buildings spain slave_administration false
    end_monitor
    In this case, when the Siena faction (spain) conquer a rebel settlement, it destroy its administrative_building.
    The problem is...it doesn't work! Looking at the log it seems the script works just fine:
    Code:
    20:43:02.229 [game.script.exec] [trace] exec <destroy_buildings> at line 2563 in mods/Mach_A0.5.8/data/world/maps/campaign/imperial_campaign/campaign_script.txt
    But when you actually conquer a rebel city with Siena (spain), the administrative building just stays there.

    Any idea?
    Huic ab adulescentia bella intestina, caedes, rapinae, discordia civilis grata fuerunt ibique iuventutem suam exercuit

  2. #2

    Default Re: Automatically destroy buildings when a city is conquered

    Hello Cesco,
    have you tried putting a wait before the destroy command.
    Like :

    monitor_event GeneralCaptureSettlement FactionType spain
    wait 0.5
    destroy_buildings spain slave_administration false
    end_monitor

    Otherwise you could destroy the buildings for every start turn, or check first if the building faction wide exists and destroy if it does.

    Best regards

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

    Default Re: Automatically destroy buildings when a city is conquered

    Yes, that. When GeneralCaptureSettlement fires the settlement does not yet belong to the capturing faction, so spain does not yet own that building, so it's not theirs to destroy. A small wait fixes that: "campaign_wait 0.1" is enough.

  4. #4
    Cesco's Avatar Decanus
    Join Date
    Apr 2013
    Location
    Italia
    Posts
    595

    Default Re: Automatically destroy buildings when a city is conquered

    It worked!
    Huic ab adulescentia bella intestina, caedes, rapinae, discordia civilis grata fuerunt ibique iuventutem suam exercuit

  5. #5
    Titus le Chmakus's Avatar Biarchus
    Join Date
    Aug 2014
    Location
    Skiing on the Spine of the World or hunting in Lurkwood
    Posts
    648

    Default Re: Automatically destroy buildings when a city is conquered

    Of course it works ! Withwnar has given you the code !!! That guy knows the code better than the devs

  6. #6
    Jurand of Cracow's Avatar History and gameplay!
    Join Date
    Oct 2012
    Location
    Cracovia
    Posts
    8,494

    Default Re: Automatically destroy buildings when a city is conquered

    Is there a way to achieve something like this:
    - both faction A (say Christian) and B (say Muslim) have the same building school (it has different names: School and Madrasa, but in EDB this is the same building);
    - a general from faction A conquers a settlement of faction B;
    - in that settlement there's that school - it should be destroyed upon conquest.
    - in other settlements of faction A there're also schools, so a command "destroy_buildings A school false" will not work - too many would be destroyed.
    How to cope with such a situation?
    JoC

  7. #7

    Default Re: Automatically destroy buildings when a city is conquered

    Hello Jurand,
    did you have a look at youneuoy's project : https://www.twcenter.net/forums/foru...erhaul-Project

    https://youneuoy.github.io/M2TWEOP-l...Lib/index.html

    In general one has a lot of new accesses to game data by writing a LUA code.
    For instance most events are also accessible in LUA and one can reduce the level of buildings or destroy buildings only in one settlement.
    If you consider having a look at this modification I can write some scripts for you.

    Best regards

    The code would look something like this:
    Code:
    function onGeneralCaptureSettlement (attacker, settlement)
        -- Example for religion numbers also can use a dictionary to check before
        NumberRel1 = 1 
        NumberRel2 = 2
        --Building Tree name
        NameBuilding = "Madrassa"
        capturingFaction = attacker.faction
        capturingFactionReligionNumber = capturingFaction.religion 
        lostFaction = settlement.ownerFaction
        lostFactionReligionNumber = settlement.ownerFaction.religion
        -- Here conditions of religion and then search if building present
        if (capturingFactionReligionNumber == NumberRel1 and lostFactionReligionNumber == NumberRel2)
            --Actually can skip this process if only want to destroy building
            settlement:destroyBuilding(NameBuilding,false)
            --[[
            NumberBuildings = settlement.buldingsNum
            for iterBuildings = 0, NumberBuildings-1,1
            do
                LocalBuilding = settlement:getBuilding(iterBuildings)
                if (LocalBuilding.buildingData.type == NameBuilding)
                    -- Here downgrade case
                    Levelset = math.max(0,LocalBuilding.level-1)
                    LocalBuilding.level = Levelset
                    break
                end 
            --]]
        end        
    end
    Last edited by Mountainhouzhe; July 31, 2021 at 03:02 PM. Reason: LUA code example

  8. #8
    Jurand of Cracow's Avatar History and gameplay!
    Join Date
    Oct 2012
    Location
    Cracovia
    Posts
    8,494

    Default Re: Automatically destroy buildings when a city is conquered

    Frankly speaking, I haven't had intention to go and learn the intricacies of this moding... I have plenty of plans even without the additional possibilities.
    So without getting into LUA scripting it's not possible?

  9. #9

    Default Re: Automatically destroy buildings when a city is conquered

    It is fairly convenient to script this way, no more massive "if" checks... .
    Its actually more similiar to the character trait triggers.
    Also for using this, one just needs to put the files in the folder and start a new way.
    One can also write everything in one text file.
    Last edited by Mountainhouzhe; July 31, 2021 at 02:18 PM.

  10. #10
    Jurand of Cracow's Avatar History and gameplay!
    Join Date
    Oct 2012
    Location
    Cracovia
    Posts
    8,494

    Default Re: Automatically destroy buildings when a city is conquered

    I understand, maybe I'd start a new way, but not now. There're always too many teething problems that an expected time to "start" should be multiplied by 10.
    For now, I understand there's no simple way to make such a script? Is it possible at all?

  11. #11

    Default Re: Automatically destroy buildings when a city is conquered

    The auto-destroy functionality is built into the game for religious buildings, you'd just need separate chains for each religion rather than there being a single chain for all religions. If you have plenty of slots, I'd say just make these normal religious buildings with 'city'/'castle' variants so they get auto-destroyed.

    If you're at the 128 chain limit, then the only solution is EOP as the conventional destroy_buildings command has no argument for settlement.

  12. #12
    Jurand of Cracow's Avatar History and gameplay!
    Join Date
    Oct 2012
    Location
    Cracovia
    Posts
    8,494

    Default Re: Automatically destroy buildings when a city is conquered

    Thanks, Callistonian, that's clear now!
    Indeed, I'll perhaps go with the prefix temple_, if I the SSHIP can allow for 9 additional buildings (5 for castles of each religion, and 4 for the other religions for the cities).

Posting Permissions

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