pineappledan
Deity
I have been stumped with a trade unit problem for a while now.
I am trying to make a Community Patch compatible civ. I want internal land trade units to claim neutral territory they pass over.
Community Patch settings:
API_LUA_EXTENSIONS = 1
API_TRADEROUTES = 1
I tried this code:
Any attempt to use GetTradeRouteIndex() results in a CTD.
I tried using pUnit:LastMissionPlot():GetOwner() instead, to see if the destination city could be discerned that way, but no dice.
Anyone have any other ideas for how to check if the caravan is an internal trade route?
I am trying to make a Community Patch compatible civ. I want internal land trade units to claim neutral territory they pass over.
Community Patch settings:
API_LUA_EXTENSIONS = 1
API_TRADEROUTES = 1
I tried this code:
Code:
local iCanada = GameInfoTypes.CIVILIZATION_CANADA
function YorkFactoryExpress(iPlayer, iUnit, iX, iY)
local pPlayer = Players[iPlayer]
if pPlayer:GetCivilizationType() ~= iCanada then return end
local pUnit = pPlayer:GetUnitByID(iUnit)
if (pUnit == nil or pUnit:IsDelayedDeath()) then return end
if pUnit:GetUnitType() == GameInfoTypes.UNIT_CARAVAN then
if (Game.GetTradeRoute(pUnit:GetTradeRouteIndex()).ToCivilizationType == iCanada) then
local pPlot = pUnit:GetPlot()
if pPlot:GetOwner() == -1 then
pPlot:SetOwner(pPlayer, pPlayer:GetCapitalCity():GetID(), 1, 1)
end
end
end
end
I tried using pUnit:LastMissionPlot():GetOwner() instead, to see if the destination city could be discerned that way, but no dice.
Anyone have any other ideas for how to check if the caravan is an internal trade route?
Last edited: