Adding an agent to the recruitment pool

--[[
	Script by Aexrael Dex
]]

local function unique_agent()
	-- Checking whether the script has already run for saved games and if it has then the script doesn't need to run again
	if cm:get_saved_value("unique_agent_enabled") == nil then

		-- Starting agent setup
		unique_agent_setup();
	end;
end;

local function unique_agent_setup()
	local agent_faction_str = "";			-- faction_key from factions
	local agent_forename_key = "";			-- forename_key from local_en
	local agent_family_name_key = "";		-- family_name_key from local_en
	local agent_gender_bool = true;			-- boolean for male true/false
	local agent_type_key = "";				-- agent type champion, colonel, dignitary, engineer, general, minister, runesmith, spy, wizard
	local agent_subtype_key = "";			-- agent subtype_key from agent_subtypes
	local agent_art_set_key = "";			-- agent art_set_id from campaign_character_arts

	-- Listening for FactionTurnStart for the faction the agent is to belong to
	core:add_listener(
		"unique agent_setup",
		"FactionTurnStart",
		function(context)
			return context:faction():name() == agent_faction_str;
		end,
		function(context)
			-- Unique agent is added to the recruitment menu
			cm:spawn_character_to_pool(agent_faction_str, agent_forename_key, agent_family_name_key, "", "", 18, agent_gender_bool, agent_type_key, agent_subtype_key, true, agent_art_set_key);
			out("Adding " .. agent_forename_key .. " " .. agent_family_name_key .. " to " .. agent_type_key .. " recruitment pool for " .. agent_faction_str);
      
      		local agent_saved_value = "unique_agent_enabled";

			-- Setting saved value, so that the hero script doesn't run again when reloaded from a saved game
			cm:set_saved_value(agent_saved_value, true);
			out("Setting saved value " .. agent_saved_value);
		end,
		false
	);
end;

cm:add_first_tick_callback(function() unique_agent() end);