pineappledan
Deity
Hi there,
I'm working on a compatibility patch for the Canadian civ, and I am getting a crash when using a code for their UA
What it does:
On move, Internal land trade routes claim tiles
The Code:
If I disable the parts of the code which check if the trade route is internal, (lines 5,6 and 13, the lines with GetTradeRouteIndex() and GetTradeRoute()), then the code works perfectly, but it works for international trade routes too.
If I run the code as seen above, the game crashes as soon as I issue an order to any unit (UnitSetXY() triggers, cannot complete and crashes the game)
This uses @whoward69's extra lua components to work (CustomModOptions 'API_LUA_EXTENSIONS' is enabled), so I can't understand why this shouldn't work.
- Is the code wrong for what I want it to do? ie. am I misusing these functions?
- Are GetTradeRouteIndex() and GetTradeRoute() not included in the DLL? Do I need to package the mod with some other part of Whoward's Pck'n'mix mods to get this lua to work?
I'm working on a compatibility patch for the Canadian civ, and I am getting a crash when using a code for their UA
What it does:
On move, Internal land trade routes claim tiles
The Code:
Code:
function YorkFactoryExpress(iPlayer, iUnit, iX, iY)
local pPlayer = Players[iPlayer]
local pCapital = pPlayer:GetCapitalCity()
local pUnit = pPlayer:GetUnitByID(iUnit)
local iRouteIndex = pUnit:GetTradeRouteIndex()
local pTrade = Game.GetTradeRoute(iRouteIndex)
if pPlayer:GetCivilizationType() ~= iCanada then return end
if (pUnit == nil or pUnit:IsDelayedDeath()) then return end
if (pUnit:GetUnitType() == GameInfoTypes.UNIT_CARAVAN) then
local pPlot = pUnit:GetPlot()
if (pTrade.ToCivilizationType == iCanada) then
if pPlot:GetOwner() == -1 then
pPlot:SetOwner(pPlayer, pCapital, 1, 1)
end
end
end
end
GameEvents.UnitSetXY.Add(YorkFactoryExpress)
If I run the code as seen above, the game crashes as soon as I issue an order to any unit (UnitSetXY() triggers, cannot complete and crashes the game)
This uses @whoward69's extra lua components to work (CustomModOptions 'API_LUA_EXTENSIONS' is enabled), so I can't understand why this shouldn't work.
- Is the code wrong for what I want it to do? ie. am I misusing these functions?
- Are GetTradeRouteIndex() and GetTradeRoute() not included in the DLL? Do I need to package the mod with some other part of Whoward's Pck'n'mix mods to get this lua to work?