Hi all.
How does one go about making a unique worker unit work faster under certain conditions using Lua?
For example, let's say that I wanted to make it so that the worker works twice as fast during golden ages. As far as I know, there are no promotions that do this, nor can I make a promotion that can do this...So how does one go about doing that without it being a global worker modifier (i.e. having an invisible building or policy that uses <WorkSpeedModifier>)?
I've tried doing this by getting build progress and then reducing that build progress (maybe? the modiki doesn't exactly state what :GetBuildProgress() or :ChangeBuildProgress() actually does...)
For example:
This doesn't work for me however. What am I doing wrong? Am I using GetBuildProgress or ChangeBuildProgress wrong? Is there another better way to do this?
Thanks for the help.
NevikCRN
How does one go about making a unique worker unit work faster under certain conditions using Lua?
For example, let's say that I wanted to make it so that the worker works twice as fast during golden ages. As far as I know, there are no promotions that do this, nor can I make a promotion that can do this...So how does one go about doing that without it being a global worker modifier (i.e. having an invisible building or policy that uses <WorkSpeedModifier>)?
I've tried doing this by getting build progress and then reducing that build progress (maybe? the modiki doesn't exactly state what :GetBuildProgress() or :ChangeBuildProgress() actually does...)
For example:
Code:
local iUniqueWorker = GameInfoTypes.UNIT_UNIQUE_WORKER
function FasterWorkRate(iPlayer)
local pPlayer = Players[iPlayer];
if pPlayer:IsAlive() then
if pPlayer:IsGoldenAge() then
for pUnit in pPlayer:Units() do
if pUnit:GetUnitType() == iUniqueWorker then
local pPlot = pUnit:GetPlot();
local iCurrentBuildID = pUnit:GetBuildType();
if iCurrentBuildID ~= -1 then
local pTeam = Teams[pPlayer:GetTeam()];
local iBuildTimeLeft = pPlot:GetBuildProgress(iCurrentBuildID, pTeam);
if iBuildTimeLeft > 3 then
pPlot:ChangeBuildProgress(iCurrentBuildID, -2, pTeam);
end
end
end
end
end
end
end
GameEvents.PlayerDoTurn.Add(FasterWorkRate);
This doesn't work for me however. What am I doing wrong? Am I using GetBuildProgress or ChangeBuildProgress wrong? Is there another better way to do this?
Thanks for the help.
NevikCRN