Hey guys. So my mod was working a little bit ago, and then I changed something and although I'm pretty sure I changed nothing to do with them, the promotions in my mod seem to have stopped working. They only show up as 'Heal Instantly' when assigned to units. Below is the code:
XML:
Lua
This is really frusterating because it was just working.
XML:
Spoiler :
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by ModBuddy on 5/7/2016 3:43:02 PM -->
<!-- Stopped working on 5/7/2016 3:43:02 PM -->
<GameData>
<Language_en_US>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_1_HELP">
<Text>-35% [ICON_STRENGTH] Defence Strength. Reduced healing in unfriendly lands.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_1_DESCRIPTION">
<Text>Morale: Terrified</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_2_HELP">
<Text>-25% [ICON_STRENGTH] Defence Strength.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_2_DESCRIPTION">
<Text>Morale: Panicked</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_3_HELP">
<Text>-15% [ICON_STRENGTH] Defence Strength.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_3_DESCRIPTION">
<Text>Morale: Unsettled</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_4_HELP">
<Text>No bonuses.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_4_DESCRIPTION">
<Text>Morale: Calm</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_5_HELP">
<Text>+15% [ICON_STRENGTH] Combat Strength.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_5_DESCRIPTION">
<Text>Morale: Confident</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_6_HELP">
<Text>+25% [ICON_STRENGTH] Combat Strength.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_6_DESCRIPTION">
<Text>Morale: Spirited</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_7_HELP">
<Text>+35% [ICON_STRENGTH] Combat Strength. +1 Movement.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_7_DESCRIPTION">
<Text>Morale: Assured</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_LOYALTY_1_HELP">
<Text>This unit is disloyal. There may be desertions and it may surrender on defeat.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_LOYALTY_1_DESCRIPTION">
<Text>Loyalty: Disloyal</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_LOYALTY_2_HELP">
<Text>This unit is loyal.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_LOYALTY_2_DESCRIPTION">
<Text>Loyalty: Loyal</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_SLAVE_HELP">
<Text>Slave Army</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_SLAVE_DESCRIPTION">
<Text>This unit is comprised of slaves. -33% [ICON_STRENGTH] Combat Strength. Can never be loyal, but will only suffer desertions when unadjacent to a non slave army.</Text>
</Row>
</Language_en_US>
<UnitPromotions>
<Row>
<Type>PROMOTION_JISKA_LOYALTY_1</Type>
<Description>TXT_KEY_PROMOTION_JISKA_LOYALTY_1_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_LOYALTY_1_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
</Row>
<Row>
<Type>PROMOTION_JISKA_LOYALTY_2</Type>
<Description>TXT_KEY_PROMOTION_JISKA_LOYALTY_2_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_LOYALTY_2_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
</Row>
<Row>
<Type>PROMOTION_JISKA_SLAVE</Type>
<Description>TXT_KEY_PROMOTION_JISKA_SLAVE_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_SLAVE_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CombatPercent>-33</CombatPercent>
<CannotBeChosen>true</CannotBeChosen>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_1</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_1_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_1_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
<DefenseMod>-35</DefenseMod>
<EnemyHealChange>-2</EnemyHealChange>
<NeutralHealChange>-5</NeutralHealChange>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_2</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_2_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_2_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
<DefenseMod>-25</DefenseMod>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_3</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_3_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_3_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
<DefenseMod>-15</DefenseMod>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_4</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_4_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_4_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_5</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_5_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_5_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
<CombatPercent>15</CombatPercent>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_6</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_6_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_6_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
<CombatPercent>25</CombatPercent>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_7</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_7_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_7_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
<CombatPercent>35</CombatPercent>
<MovesChange>1</MovesChange>
</Row>
</UnitPromotions>
</GameData>
<!-- Created by ModBuddy on 5/7/2016 3:43:02 PM -->
<!-- Stopped working on 5/7/2016 3:43:02 PM -->
<GameData>
<Language_en_US>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_1_HELP">
<Text>-35% [ICON_STRENGTH] Defence Strength. Reduced healing in unfriendly lands.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_1_DESCRIPTION">
<Text>Morale: Terrified</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_2_HELP">
<Text>-25% [ICON_STRENGTH] Defence Strength.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_2_DESCRIPTION">
<Text>Morale: Panicked</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_3_HELP">
<Text>-15% [ICON_STRENGTH] Defence Strength.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_3_DESCRIPTION">
<Text>Morale: Unsettled</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_4_HELP">
<Text>No bonuses.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_4_DESCRIPTION">
<Text>Morale: Calm</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_5_HELP">
<Text>+15% [ICON_STRENGTH] Combat Strength.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_5_DESCRIPTION">
<Text>Morale: Confident</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_6_HELP">
<Text>+25% [ICON_STRENGTH] Combat Strength.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_6_DESCRIPTION">
<Text>Morale: Spirited</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_7_HELP">
<Text>+35% [ICON_STRENGTH] Combat Strength. +1 Movement.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_MORALE_7_DESCRIPTION">
<Text>Morale: Assured</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_LOYALTY_1_HELP">
<Text>This unit is disloyal. There may be desertions and it may surrender on defeat.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_LOYALTY_1_DESCRIPTION">
<Text>Loyalty: Disloyal</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_LOYALTY_2_HELP">
<Text>This unit is loyal.</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_LOYALTY_2_DESCRIPTION">
<Text>Loyalty: Loyal</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_SLAVE_HELP">
<Text>Slave Army</Text>
</Row>
<Row Tag="TXT_KEY_PROMOTION_JISKA_SLAVE_DESCRIPTION">
<Text>This unit is comprised of slaves. -33% [ICON_STRENGTH] Combat Strength. Can never be loyal, but will only suffer desertions when unadjacent to a non slave army.</Text>
</Row>
</Language_en_US>
<UnitPromotions>
<Row>
<Type>PROMOTION_JISKA_LOYALTY_1</Type>
<Description>TXT_KEY_PROMOTION_JISKA_LOYALTY_1_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_LOYALTY_1_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
</Row>
<Row>
<Type>PROMOTION_JISKA_LOYALTY_2</Type>
<Description>TXT_KEY_PROMOTION_JISKA_LOYALTY_2_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_LOYALTY_2_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
</Row>
<Row>
<Type>PROMOTION_JISKA_SLAVE</Type>
<Description>TXT_KEY_PROMOTION_JISKA_SLAVE_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_SLAVE_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CombatPercent>-33</CombatPercent>
<CannotBeChosen>true</CannotBeChosen>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_1</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_1_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_1_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
<DefenseMod>-35</DefenseMod>
<EnemyHealChange>-2</EnemyHealChange>
<NeutralHealChange>-5</NeutralHealChange>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_2</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_2_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_2_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
<DefenseMod>-25</DefenseMod>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_3</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_3_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_3_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
<DefenseMod>-15</DefenseMod>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_4</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_4_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_4_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_5</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_5_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_5_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
<CombatPercent>15</CombatPercent>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_6</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_6_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_6_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
<CombatPercent>25</CombatPercent>
</Row>
<Row>
<Type>PROMOTION_JISKA_MORALE_7</Type>
<Description>TXT_KEY_PROMOTION_JISKA_MORALE_7_DESCRIPTION</Description>
<Help>TXT_KEY_PROMOTION_JISKA_MORALE_7_HELP</Help>
<PortraitIndex>59</PortraitIndex>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_CITY_ASSUALT</PediaEntry>
<CannotBeChosen>true</CannotBeChosen>
<CombatPercent>35</CombatPercent>
<MovesChange>1</MovesChange>
</Row>
</UnitPromotions>
</GameData>
Lua
Spoiler :
-- CourageAndCowardice.lua
-- Author: Jiska
-- DateCreated: 5/7/2016 3:41:59 PM
--------------------------------------------------------------
local Morale1 = GameInfoTypes["PROMOTION_JISKA_MORALE_1"]
local Morale2 = GameInfoTypes["PROMOTION_JISKA_MORALE_2"]
local Morale3 = GameInfoTypes["PROMOTION_JISKA_MORALE_3"]
local Morale4 = GameInfoTypes["PROMOTION_JISKA_MORALE_4"]
local Morale5 = GameInfoTypes["PROMOTION_JISKA_MORALE_5"]
local Morale6 = GameInfoTypes["PROMOTION_JISKA_MORALE_6"]
local Morale7 = GameInfoTypes["PROMOTION_JISKA_MORALE_7"]
local Loyalty1 = GameInfoTypes["PROMOTION_JISKA_LOYALTY_1"]
local Loyalty2 = GameInfoTypes["PROMOTION_JISKA_LOYALTY_2"]
local SlavePro = GameInfoTypes["PROMOTION_JISKA_SLAVE"]
local MaxDamage = GameDefines.MAX_HIT_POINTS
print("Courage and Cowardice Loaded")
local jiska_debug = 1
if jiska_debug == 1 then print("Courage and Cowardice: jiska_debugging.") end
function Jiska_OnDoTurn(iPlayer)
local pPlayer = Players[iPlayer]
if jiska_debug == 1 then print("Jiska_OnDoTurn Player " .. iPlayer .. " " .. pPlayer:GetName()) end
for unit in pPlayer:Units() do
--print(Loyalty2 .. Locale.ConvertTextKey("TXT_KEY_PROMOTION_JISKA_LOYALTY_2_DESCRIPTION") .. Locale.ConvertTextKey("TXT_KEY_PROMOTION_JISKA_LOYALTY_2_HELP"))
--unit:SetHasPromotion(unit, Loyalty2, true)
if (unit ~= nil and unit:IsCombatUnit()) then
if (not unit:IsHasPromotion(Loyalty1)) then
if (not unit:IsHasPromotion(Loyalty2)) then
unit:SetHasPromotion(unit, Loyalty2, true)
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": added Loyalty promotion.") end
end
end
if (not unit:IsHasPromotion(Morale1)) then
if (not unit:IsHasPromotion(Morale2)) then
if (not unit:IsHasPromotion(Morale3)) then
if (not unit:IsHasPromotion(Morale4)) then
if (not unit:IsHasPromotion(Morale5)) then
if (not unit:IsHasPromotion(Morale6)) then
if (not unit:IsHasPromotion(Morale7)) then
unit:SetHasPromotion(unit, Morale4, true)
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": added Morale promotion.") end
end
end end end end end end
local plot = unit:GetPlot()
local damage = unit:GetDamage();
local healthPercent = 1.0 - (damage / MaxDamage);
local healthTimes100 = math.floor(100 * healthPercent + 0.5);
if (unit:IsHasPromotion(Loyalty1)) and (unit:IsNearGreatGeneral() or ((plot:GetOwner() == pPlayer:GetID()) and healthTimes100 > 66 )) then
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": Disloyal and near General or in Friendly Lands and strongish. Raised Loyalty.") end
unit:SetHasPromotion(Loyalty1,false)
unit:SetHasPromotion(Loyalty2,true)
end
if (unit:IsHasPromotion(Loyalty2)) and (unit:IsHasPromotion(Morale1) or unit:IsHasPromotion(Morale2)) and healthTimes100 < 50 then
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": low Health and low Morale. Lowered Loyalty.") end
unit:SetHasPromotion(Loyalty2,false)
unit:SetHasPromotion(Loyalty1,true)
end
if unit:IsHasPromotion(Morale1) or unit:IsHasPromotion(Morale2) or unit:IsHasPromotion(Morale3) then
if plot:GetOwner() == pPlayer:GetID() then
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": in Owned Lands and lower than Calm.") end
Jiska_MoraleIncrease(unit)
end
local FortTurn = unit:GetFortifyTurns()
if FortTurn > 0 then
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": Fortified and lower than Calm.") end
Jiska_MoraleIncrease(unit)
end
end
if healthTimes100 <= 50 and plot:GetOwner() ~= pPlayer:GetID() then
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": outside Owned Lands and damaged.") end
Jiska_MoraleDecrease(unit)
end
end
end
end
GameEvents.PlayerDoTurn.Add(Jiska_OnDoTurn)
function Jiska_OnLoadScreenClose()
local activePlayer = Players[Game.GetActivePlayer()]
for unit in activePlayer:Units() do
if (unit ~= nil and unit:IsCombatUnit()) then
unit:SetHasPromotion(unit, Morale4, true)
unit:SetHasPromotion(unit, Loyalty2, true)
end
end
end
Events.LoadScreenClose.Add(Jiska_OnLoadScreenClose)
function JiskaOnCombatEnded(iAttackingPlayer, iAttackingUnit, iAttackerDamage, iAttackerFinalDamage, iAttackerMaxHP, iDefendingPlayer, iDefendingUnit, iDefenderDamage, iDefenderFinalDamage, iDefenderMaxHP, iInterceptingPlayer, iInterceptingUnit, iInterceptorDamage, iPlotX, iPlotY)
local AtkPla = Players[iAttackingPlayer]
local AtkUnit = AtkPla:GetUnitByID(iAttackingUnit)
local DefPla = Players[iDefendingPlayer]
local DefUnit = DefPla:GetUnitByID(iDefendingUnit)
local mUnitHealth = iDefenderMaxHP - iDefenderFinalDamage
if AtkPla ~= nil and DefPla ~= nil and AtkUnit ~= nil and DefUnit ~= nil then
if mUnitHealth <= 0 then
if --[[math.random(2) == 1 and--]]AtkUnit:GetRange() == nil then
if jiska_debug == 1 then print(AtkPla:GetName() .. "'s " .. AtkUnit:GetName() .. " captured " .. DefPla:GetName() .. "'s " .. DefUnit:GetName() .. ".") end
NewUnit = AtkPla:InitUnit(DefUnit:GetUnitType(), DefUnit:GetX(), DefUnit:GetY(), DefUnit:GetUnitAIType(), DefUnit:GetFacingDirection())
NewUnit:SetDamage(85, AtkPla, 0)
NewUnit:SetHasPromotion(SlavePro,true)
NewUnit:SetMoves(0)
else
if jiska_debug == 1 then print(AtkPla:GetName() .. "'s " .. AtkUnit:GetName() .. " killed " .. DefPla:GetName() .. "'s " .. DefUnit:GetName() .. ".") end
end
Jiska_MoraleIncrease(AtkUnit)
elseif iAttackerDamage > iDefenderDamage * 2 then
if jiska_debug == 1 then print(AtkPla:GetName() .. "'s " .. AtkUnit:GetName() .. " attacked " .. DefPla:GetName() .. "'s " .. DefUnit:GetName() .. ": major victory.") end
Jiska_MoraleIncrease(AtkUnit)
Jiska_MoraleDecrease(DefUnit)
elseif iAttackerDamage < iDefenderDamage * 2 then
if jiska_debug == 1 then print(AtkPla:GetName() .. "'s " .. AtkUnit:GetName() .. " attacked " .. DefPla:GetName() .. "'s " .. DefUnit:GetName() .. ": major defeat.") end
Jiska_MoraleDecrease(AtkUnit)
Jiska_MoraleIncrease(DefUnit)
end
end
end
GameEvents.CombatEnded.Add(JiskaOnCombatEnded)
function Jiska_MoraleIncrease(unit)
print(unit:GetName() .. ": increased Morale.") --pPlayer:GetName() .. " " ..
if (unit:IsHasPromotion(Morale7)) then print(unit:GetName() .. ": max Morale!") end
if (unit:IsHasPromotion(Morale6)) then
unit:SetHasPromotion(Morale6,false)
unit:SetHasPromotion(Morale7,true)
elseif (unit:IsHasPromotion(Morale5)) then
unit:SetHasPromotion(Morale5,false)
unit:SetHasPromotion(Morale6,true)
elseif (unit:IsHasPromotion(Morale4)) then
unit:SetHasPromotion(Morale4,false)
unit:SetHasPromotion(Morale5,true)
elseif (unit:IsHasPromotion(Morale3)) then
unit:SetHasPromotion(Morale3,false)
unit:SetHasPromotion(Morale4,true)
elseif (unit:IsHasPromotion(Morale2)) then
unit:SetHasPromotion(Morale2,false)
unit:SetHasPromotion(Morale3,true)
elseif (unit:IsHasPromotion(Morale1)) then
unit:SetHasPromotion(Morale1,false)
unit:SetHasPromotion(Morale2,true)
end
end
function Jiska_MoraleDecrease(unit)
print(unit:GetName() .. ": Decreased Morale.") --pPlayer:GetName() .. " " ..
if (unit:IsHasPromotion(Morale1)) then print(unit:GetName() .. ": min Morale!") end
if (unit:IsHasPromotion(Morale2)) then
unit:SetHasPromotion(Morale2,false)
unit:SetHasPromotion(Morale1,true)
elseif (unit:IsHasPromotion(Morale3)) then
unit:SetHasPromotion(Morale3,false)
unit:SetHasPromotion(Morale2,true)
elseif (unit:IsHasPromotion(Morale4)) then
unit:SetHasPromotion(Morale4,false)
unit:SetHasPromotion(Morale3,true)
elseif (unit:IsHasPromotion(Morale5)) then
unit:SetHasPromotion(Morale5,false)
unit:SetHasPromotion(Morale4,true)
elseif (unit:IsHasPromotion(Morale6)) then
unit:SetHasPromotion(Morale6,false)
unit:SetHasPromotion(Morale5,true)
elseif (unit:IsHasPromotion(Morale7)) then
unit:SetHasPromotion(Morale7,false)
unit:SetHasPromotion(Morale6,true)
end
end
-- Author: Jiska
-- DateCreated: 5/7/2016 3:41:59 PM
--------------------------------------------------------------
local Morale1 = GameInfoTypes["PROMOTION_JISKA_MORALE_1"]
local Morale2 = GameInfoTypes["PROMOTION_JISKA_MORALE_2"]
local Morale3 = GameInfoTypes["PROMOTION_JISKA_MORALE_3"]
local Morale4 = GameInfoTypes["PROMOTION_JISKA_MORALE_4"]
local Morale5 = GameInfoTypes["PROMOTION_JISKA_MORALE_5"]
local Morale6 = GameInfoTypes["PROMOTION_JISKA_MORALE_6"]
local Morale7 = GameInfoTypes["PROMOTION_JISKA_MORALE_7"]
local Loyalty1 = GameInfoTypes["PROMOTION_JISKA_LOYALTY_1"]
local Loyalty2 = GameInfoTypes["PROMOTION_JISKA_LOYALTY_2"]
local SlavePro = GameInfoTypes["PROMOTION_JISKA_SLAVE"]
local MaxDamage = GameDefines.MAX_HIT_POINTS
print("Courage and Cowardice Loaded")
local jiska_debug = 1
if jiska_debug == 1 then print("Courage and Cowardice: jiska_debugging.") end
function Jiska_OnDoTurn(iPlayer)
local pPlayer = Players[iPlayer]
if jiska_debug == 1 then print("Jiska_OnDoTurn Player " .. iPlayer .. " " .. pPlayer:GetName()) end
for unit in pPlayer:Units() do
--print(Loyalty2 .. Locale.ConvertTextKey("TXT_KEY_PROMOTION_JISKA_LOYALTY_2_DESCRIPTION") .. Locale.ConvertTextKey("TXT_KEY_PROMOTION_JISKA_LOYALTY_2_HELP"))
--unit:SetHasPromotion(unit, Loyalty2, true)
if (unit ~= nil and unit:IsCombatUnit()) then
if (not unit:IsHasPromotion(Loyalty1)) then
if (not unit:IsHasPromotion(Loyalty2)) then
unit:SetHasPromotion(unit, Loyalty2, true)
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": added Loyalty promotion.") end
end
end
if (not unit:IsHasPromotion(Morale1)) then
if (not unit:IsHasPromotion(Morale2)) then
if (not unit:IsHasPromotion(Morale3)) then
if (not unit:IsHasPromotion(Morale4)) then
if (not unit:IsHasPromotion(Morale5)) then
if (not unit:IsHasPromotion(Morale6)) then
if (not unit:IsHasPromotion(Morale7)) then
unit:SetHasPromotion(unit, Morale4, true)
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": added Morale promotion.") end
end
end end end end end end
local plot = unit:GetPlot()
local damage = unit:GetDamage();
local healthPercent = 1.0 - (damage / MaxDamage);
local healthTimes100 = math.floor(100 * healthPercent + 0.5);
if (unit:IsHasPromotion(Loyalty1)) and (unit:IsNearGreatGeneral() or ((plot:GetOwner() == pPlayer:GetID()) and healthTimes100 > 66 )) then
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": Disloyal and near General or in Friendly Lands and strongish. Raised Loyalty.") end
unit:SetHasPromotion(Loyalty1,false)
unit:SetHasPromotion(Loyalty2,true)
end
if (unit:IsHasPromotion(Loyalty2)) and (unit:IsHasPromotion(Morale1) or unit:IsHasPromotion(Morale2)) and healthTimes100 < 50 then
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": low Health and low Morale. Lowered Loyalty.") end
unit:SetHasPromotion(Loyalty2,false)
unit:SetHasPromotion(Loyalty1,true)
end
if unit:IsHasPromotion(Morale1) or unit:IsHasPromotion(Morale2) or unit:IsHasPromotion(Morale3) then
if plot:GetOwner() == pPlayer:GetID() then
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": in Owned Lands and lower than Calm.") end
Jiska_MoraleIncrease(unit)
end
local FortTurn = unit:GetFortifyTurns()
if FortTurn > 0 then
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": Fortified and lower than Calm.") end
Jiska_MoraleIncrease(unit)
end
end
if healthTimes100 <= 50 and plot:GetOwner() ~= pPlayer:GetID() then
if jiska_debug == 1 then print(pPlayer:GetName() .. " " .. unit:GetName() .. ": outside Owned Lands and damaged.") end
Jiska_MoraleDecrease(unit)
end
end
end
end
GameEvents.PlayerDoTurn.Add(Jiska_OnDoTurn)
function Jiska_OnLoadScreenClose()
local activePlayer = Players[Game.GetActivePlayer()]
for unit in activePlayer:Units() do
if (unit ~= nil and unit:IsCombatUnit()) then
unit:SetHasPromotion(unit, Morale4, true)
unit:SetHasPromotion(unit, Loyalty2, true)
end
end
end
Events.LoadScreenClose.Add(Jiska_OnLoadScreenClose)
function JiskaOnCombatEnded(iAttackingPlayer, iAttackingUnit, iAttackerDamage, iAttackerFinalDamage, iAttackerMaxHP, iDefendingPlayer, iDefendingUnit, iDefenderDamage, iDefenderFinalDamage, iDefenderMaxHP, iInterceptingPlayer, iInterceptingUnit, iInterceptorDamage, iPlotX, iPlotY)
local AtkPla = Players[iAttackingPlayer]
local AtkUnit = AtkPla:GetUnitByID(iAttackingUnit)
local DefPla = Players[iDefendingPlayer]
local DefUnit = DefPla:GetUnitByID(iDefendingUnit)
local mUnitHealth = iDefenderMaxHP - iDefenderFinalDamage
if AtkPla ~= nil and DefPla ~= nil and AtkUnit ~= nil and DefUnit ~= nil then
if mUnitHealth <= 0 then
if --[[math.random(2) == 1 and--]]AtkUnit:GetRange() == nil then
if jiska_debug == 1 then print(AtkPla:GetName() .. "'s " .. AtkUnit:GetName() .. " captured " .. DefPla:GetName() .. "'s " .. DefUnit:GetName() .. ".") end
NewUnit = AtkPla:InitUnit(DefUnit:GetUnitType(), DefUnit:GetX(), DefUnit:GetY(), DefUnit:GetUnitAIType(), DefUnit:GetFacingDirection())
NewUnit:SetDamage(85, AtkPla, 0)
NewUnit:SetHasPromotion(SlavePro,true)
NewUnit:SetMoves(0)
else
if jiska_debug == 1 then print(AtkPla:GetName() .. "'s " .. AtkUnit:GetName() .. " killed " .. DefPla:GetName() .. "'s " .. DefUnit:GetName() .. ".") end
end
Jiska_MoraleIncrease(AtkUnit)
elseif iAttackerDamage > iDefenderDamage * 2 then
if jiska_debug == 1 then print(AtkPla:GetName() .. "'s " .. AtkUnit:GetName() .. " attacked " .. DefPla:GetName() .. "'s " .. DefUnit:GetName() .. ": major victory.") end
Jiska_MoraleIncrease(AtkUnit)
Jiska_MoraleDecrease(DefUnit)
elseif iAttackerDamage < iDefenderDamage * 2 then
if jiska_debug == 1 then print(AtkPla:GetName() .. "'s " .. AtkUnit:GetName() .. " attacked " .. DefPla:GetName() .. "'s " .. DefUnit:GetName() .. ": major defeat.") end
Jiska_MoraleDecrease(AtkUnit)
Jiska_MoraleIncrease(DefUnit)
end
end
end
GameEvents.CombatEnded.Add(JiskaOnCombatEnded)
function Jiska_MoraleIncrease(unit)
print(unit:GetName() .. ": increased Morale.") --pPlayer:GetName() .. " " ..
if (unit:IsHasPromotion(Morale7)) then print(unit:GetName() .. ": max Morale!") end
if (unit:IsHasPromotion(Morale6)) then
unit:SetHasPromotion(Morale6,false)
unit:SetHasPromotion(Morale7,true)
elseif (unit:IsHasPromotion(Morale5)) then
unit:SetHasPromotion(Morale5,false)
unit:SetHasPromotion(Morale6,true)
elseif (unit:IsHasPromotion(Morale4)) then
unit:SetHasPromotion(Morale4,false)
unit:SetHasPromotion(Morale5,true)
elseif (unit:IsHasPromotion(Morale3)) then
unit:SetHasPromotion(Morale3,false)
unit:SetHasPromotion(Morale4,true)
elseif (unit:IsHasPromotion(Morale2)) then
unit:SetHasPromotion(Morale2,false)
unit:SetHasPromotion(Morale3,true)
elseif (unit:IsHasPromotion(Morale1)) then
unit:SetHasPromotion(Morale1,false)
unit:SetHasPromotion(Morale2,true)
end
end
function Jiska_MoraleDecrease(unit)
print(unit:GetName() .. ": Decreased Morale.") --pPlayer:GetName() .. " " ..
if (unit:IsHasPromotion(Morale1)) then print(unit:GetName() .. ": min Morale!") end
if (unit:IsHasPromotion(Morale2)) then
unit:SetHasPromotion(Morale2,false)
unit:SetHasPromotion(Morale1,true)
elseif (unit:IsHasPromotion(Morale3)) then
unit:SetHasPromotion(Morale3,false)
unit:SetHasPromotion(Morale2,true)
elseif (unit:IsHasPromotion(Morale4)) then
unit:SetHasPromotion(Morale4,false)
unit:SetHasPromotion(Morale3,true)
elseif (unit:IsHasPromotion(Morale5)) then
unit:SetHasPromotion(Morale5,false)
unit:SetHasPromotion(Morale4,true)
elseif (unit:IsHasPromotion(Morale6)) then
unit:SetHasPromotion(Morale6,false)
unit:SetHasPromotion(Morale5,true)
elseif (unit:IsHasPromotion(Morale7)) then
unit:SetHasPromotion(Morale7,false)
unit:SetHasPromotion(Morale6,true)
end
end
This is really frusterating because it was just working.