Hello, I am trying to make a lua script that stops a unit from being built unless it has met certain requirements. I know I can achieve this through xml but it I do not want it to apply to city states or barbarians so I need to use lua.
It half works in that it stops me from building the test unit (warrior) but as soon as I get iron I still can not build the unit. Thanks in advance.
It half works in that it stops me from building the test unit (warrior) but as soon as I get iron I still can not build the unit. Thanks in advance.
Code:
function PlayerTrainWarrior(iPlayer, unitTypeID)
local player = Players[iPlayer];
local unitclass = GameInfoTypes[GameInfo.Units[unitTypeID].Class];
local civtype = Players[iPlayer]:GetCivilizationType();
if (unitclass ~= GameInfoTypes["UNITCLASS_WARRIOR"]) and (civtype ~= GameDefines.MAX_MAJOR_CIVS) and (player:GetNumResourceAvailable(GameInfoTypes["RESOURCE_IRON"], true) > 0) then
return true;
end
return false;
end
GameEvents.PlayerCanTrain.Add(PlayerTrainWarrior);