Replacing a Faction Leader

--[[
	Script by Aexrael Dex
	Replaces the starting general for a specific faction
]]

local function replace_starting_general()
    if cm:is_new_game() then
        
        -- Creating replacement for Karl Franz with a regular Empire General
        local general_faction_str = "wh_main_emp_empire";       -- faction key from factions table
        local general_unit_list = "wh_main_emp_cav_reiksguard,wh_main_emp_cav_reiksguard,wh_main_emp_cav_reiksguard";   -- unit keys from main_units table
        local general_region_key = "wh_main_reikland_altdorf";  -- Region key from campaign_map_regions table
        local general_x_pos = 490;          -- x pos location, get these with Modding Tools: CQI and Coordinates Export mod
        local general_y_pos = 451;          -- y pos location, get these with Modding Tools: CQI and Coordinates Export mod
        local general_type = "general";     -- agent type
        local general_subtype = "emp_lord"; -- agent subtype
        local general_forename = "names_name_1904032251"; -- from local_en names table, Bernhoff the Butcher is now ruler of Reikland
        local general_clanname = "";                -- from local_en names table
        local general_surname = "";                 -- from local_en names table
        local general_othername = "";               -- from local_en names table
        local general_is_faction_leader = true;    -- bool for whether the general being replaced is the faction leader
        	
        cm:create_force_with_general(
            general_faction_str,
            general_unit_list,
            general_region_key,
            general_x_pos,
            general_y_pos,
            general_type,
            general_subtype,
            general_forename,
            general_clanname,
            general_surname,
            general_othername,
            general_is_faction_leader,

            -- Generals created this way does not come with a trait
            function(cqi)
                local char_str = cm:char_lookup_str(cqi);
                -- Adding a new trait to the above general
                cm:force_add_trait(char_str, "wh2_dlc09_trait_benevolence", true);
            end
        );
        out("Creating Neo_Karl Franz for Reikland");

        -- Killing original Karl Franz
        local fac_obj = cm:model():world():faction_by_key(general_faction_str);
        local char_list = fac_obj:character_list();
        local lord_subtype = "emp_karl_franz"; -- Karl Franz's agent subtype
        local lord_forename = "names_name_2147343849"; -- Karl Franz's forename

        for i = 0, char_list:num_items() - 1 do
            local current_char = char_list:item_at(i);
            
            if current_char:is_null_interface() == false and current_char:character_subtype_key() == lord_subtype and current_char:get_forename() == lord_forename and current_char:has_military_force() == true then
                cm:set_character_immortality("character_cqi:"..current_char:command_queue_index(), false);
                cm:disable_event_feed_events(true, "wh_event_category_character", "", "");
                cm:kill_character(current_char:command_queue_index(), true, true);
                cm:callback(function() cm:disable_event_feed_events(false, "wh_event_category_character", "", "") end, 1);
                out("Killing original Karl Franz for Reikland permanently");
            end;
        end;
    end;
end;

cm:add_first_tick_callback(function() replace_starting_general() end);
Close Menu