trystero49
Prince
- Joined
- Apr 30, 2012
- Messages
- 515
Code:
local function AwardXPFinally(pUnit, XPToAward)
local XPAlreadyHave = pUnit:GetExperience()
local XPTotal = XPAlreadyHave + XPToAward
print(XPTotal)
pUnit:SetExperience(XPTotal)
end
local function CheckBuildingsInCity(pUnit)
local pPlot = pUnit:GetPlot()
local XPToAward = 0;
for _, iBuilding in pairs(buildings) do
if (pPlot:GetNumBuilding(iBuilding) > 0) then
XPToAward = XPToAward + 5
end
end
print(XPToAward)
AwardXPFinally(pUnit, XPToAward)
end
local function CheckForNewlyBuiltUnits(iPlayer, iCurrentTurn)
local pPlot = pCity:Plot()
for iUnit = 0, pPlot:GetNumUnits()-1, 1 do
local pUnit = pPlot:GetUnit(iUnit)
if pUnit:GetGameTurnCreated() == iCurrentTurn then
CheckBuildingsInCity(pUnit)
end
end
end
local function AwardXPIfSkaldic(iPlayer, iCurrentTurn)
-- Norway has skaldic verse trait
if iPlayer:GetCivilizationType() == GameInfo.Civilizations.CIVILIZATION_NORWAY.ID then
print("Norway!")
CheckForNewlyBuiltUnits(iPlayer,ICurrentTurn)
else
print("Not Norway :(")
end
end
function CheckforPreviousMajorCiv(iPlayer, iCurrentTurn)
for i = (iPlayer - 1), 0, -1 do
if (Players[i]:IsEverAlive() and not Players[i]:IsMinorCiv() and not Players[i]:IsBarbarian()) then
print("In block one")
AwardXPIfSkaldic(iPlayer, iCurrentTurn)
break
end
end
for i = GameDefines.MAX_MAJOR_CIVS - 1, (iPlayer + 1), -1 do
if (Players[i]:IsEverAlive() and not Players[i]:IsMinorCiv() and not Players[i]:IsBarbarian()) then
print("In block two")
AwardXPIfSkaldic(iPlayer, iCurrentTurn - 1)
end
end
end
function MainSkaldicScript(iPlayer)
print("This is the Skaldic Script")
local pPlayer = iPlayer
local CurrentTurn = Game.GetGameTurn()
if (Players[pPlayer]:IsEverAlive() and not Players[pPlayer]:IsMinorCiv() and not Players[pPlayer]:IsBarbarian()) then
print("It's Alive!")
CheckforPreviousMajorCiv(pPlayer, CurrentTurn)
end
end
GameEvents.PlayerDoTurn.Add(MainSkaldicScript)
That's what I have done. I may have done something glaringly obviously stupid, because I'm definitely an amateur.
But for sure, the event hook is being called, because at the very least "This is the Skaldic Script" and "It's Alive!" print. "In block one", "In block two" don't, although they did get printed when I used CheckForPreviousMajorCiv as the event hook.