lua_scripts - army_caps.lua
Code:
local function OnCharacterSelected(context)
if isPlayerTurn() then
-- Double time removal
local navy_stance_group = scripting.m_root:Find("naval_stance_button_stack");
if navy_stance_group then
local double_time_stance = UIComponent(navy_stance_group):Find("button_double_time");
UIComponent(double_time_stance):SetDisabled(true);
UIComponent(double_time_stance):SetVisible(false);
end
end
-- Gets current char
curr_character = nil;
sel_char, sel_char_name = context:character(), context:character():get_forename();
-- If the character selected is not of the local faction we skip the process
if (sel_char:faction():name() ~= curr_local_faction_name) then return end;
Log("Character Selected");
if sel_char:has_garrison_residence() then
-- Forced March removal
local army_stance_group = scripting.m_root:Find("land_stance_button_stack");
if army_stance_group then
local forced_army_stance = UIComponent(army_stance_group):Find("button_forced_march");
UIComponent(forced_army_stance):SetDisabled(true);
-- UIComponent(forced_army_stance):SetVisible(false);
end
elseif sel_char:military_force():unit_list():num_items() < 3 then
-- Forced March removal
local army_stance_group = scripting.m_root:Find("land_stance_button_stack");
if army_stance_group then
local forced_army_stance = UIComponent(army_stance_group):Find("button_forced_march");
UIComponent(forced_army_stance):SetDisabled(true);
UIComponent(forced_army_stance):SetVisible(false);
end
elseif sel_char:military_force():unit_list():num_items() >= 3 then
-- Forced March add
local army_stance_group = scripting.m_root:Find("land_stance_button_stack");
if army_stance_group then
local forced_army_stance = UIComponent(army_stance_group):Find("button_forced_march");
UIComponent(forced_army_stance):SetDisabled(false);
UIComponent(forced_army_stance):SetVisible(true);
end
end
-- Check if the character has units
if sel_char:has_military_force() then
Log("> Character has a military force, checking what to do >");
curr_character = character:get(sel_char) or character:new(sel_char);
old_character = curr_character;
Log("< Check ended");
elseif old_character then old_character = nil end
end
local function OnCharacterSelected2(context)
-- Gets current char
curr_character = nil;
sel_char, sel_char_name = context:character(), context:character():get_forename();
-- If the character selected is not of the local faction we skip the process
if (sel_char:faction():name() ~= curr_local_faction_name) then return end;
Log("Character Selected");
if sel_char:military_force():unit_list():num_items() < 4 then
-- raid
local army_stance_group2 = scripting.m_root:Find("land_stance_button_stack");
if army_stance_group2 then
local forced_army_stance2 = UIComponent(army_stance_group2):Find("button_raid");
UIComponent(forced_army_stance2):SetDisabled(true);
UIComponent(forced_army_stance2):SetVisible(false);
end
elseif sel_char:military_force():unit_list():num_items() >= 4 then
-- raid
local army_stance_group2 = scripting.m_root:Find("land_stance_button_stack");
if army_stance_group2 then
local forced_army_stance2 = UIComponent(army_stance_group2):Find("button_raid");
UIComponent(forced_army_stance2):SetDisabled(false);
UIComponent(forced_army_stance2):SetVisible(true);
end
end
-- Check if the character has units
if sel_char:has_military_force() then
Log("> Character has a military force, checking what to do >");
curr_character = character:get(sel_char) or character:new(sel_char);
old_character = curr_character;
Log("< Check ended");
elseif old_character then old_character = nil end
end
First function removes fleet double time and also changes forced march (which is patrol region). The second function is for raiding.