How to set a Promotion in Enemy Territory?

NevikCRN

Chieftain
Joined
Apr 13, 2016
Messages
6
Hi all.

This is my first time making a civilization, and I have to use Lua for the one of the promotions I want to give to my UU. Basically, the Unit is only supposed to have the promotion when it is on a tile owned by someone that the owner of the unit is at war with. So I wrote a Lua script to do precisely that...

Spoiler :

Code:
print( "Hello World!" )

local iBorinqueneerUnit = GameInfoTypes.UNIT_BORINQUENEER;
local iExpBonus = GameInfoTypes.PROMOTION_ENEMY_TERRITORY_EXP_BONUS;

--+50% Bonus Experience in Enemy Territory
function EnemyTerritoryExpBonus(iPlayer, iUnit, iX, iY)
	local pPlayer = Players[iPlayer];
	local pTeam = Teams[pPlayer:GetTeam()];
	if pPlayer:IsAlive() then
		local pUnit = pPlayer:GetUnitByID(iUnit);
		if pUnit:GetUnitType() == iBorinqueneerUnit then
			local pPlot = Map.GetPlot(iX, iY);
				if pTeam:IsAtWar(Teams[pPlot:GetTeam()]) then
					if not pUnit:IsHasPromotion(iExpBonus) then
						pUnit:SetHasPromotion(iExpBonus, true);
					end
				else
					if pUnit:IsHasPromotion(iExpBonus) then
						pUnit:SetHasPromotion(iExpBonus, false);
					end
				end
			end
		end
	end
end

GameEvents.UnitSetXY.Add(EnemyTerritoryExpBonus);


The Lua log does indeed print 'Hello World!', so the script is running. There are no errors showing up in the logs either. I just can't find out what's wrong.

Is there something wrong with the code? Is there something else I should do to get the same result? Please help!

Thanks,

NevikCRN
 
You could also redraft as
Code:
print( "Hello World!" )

local iBorinqueneerUnit = GameInfoTypes.UNIT_BORINQUENEER;
local iExpBonus = GameInfoTypes.PROMOTION_ENEMY_TERRITORY_EXP_BONUS;

--+50% Bonus Experience in Enemy Territory
function EnemyTerritoryExpBonus(iPlayer, iUnit, iX, iY)
	local pPlayer = Players[iPlayer];
	local pTeam = Teams[pPlayer:GetTeam()];
	if pPlayer:IsAlive() then
		local pUnit = pPlayer:GetUnitByID(iUnit);
		if pUnit:GetUnitType() == iBorinqueneerUnit then
			local pPlot = Map.GetPlot(iX, iY);
			if pPlot:GetOwner() ~= -1 then
				pUnit:SetHasPromotion(iExpBonus, pTeam:IsAtWar(pPlot:GetTeam()));
			else
				pUnit:SetHasPromotion(iExpBonus, false)
			end
		end
	end
end

GameEvents.UnitSetXY.Add(EnemyTerritoryExpBonus);
 
Back
Top Bottom