Guadalcanal Scenario

I just realised what the possible problem might be from the city being conquered. I'll look into it a little later this evening to verify if what I believe might be the prinme cause is in fact the prime cause.

Please shoot me your latest version of RandomFleetSpawn.lua so I can be sure not to over-write any changes you may have made recently.

I can investigate the issue without it, but I want your latest version for applying the fixes that I suspect I will need to make.

This is a seperate issue from the database.log possibility I mentioned before.
 
I just realised what the possible problem might be from the city being conquered. I'll look into it a little later this evening to verify if what I believe might be the prinme cause is in fact the prime cause.

Please shoot me your latest version of RandomFleetSpawn.lua so I can be sure not to over-write any changes you may have made recently.

I can investigate the issue without it, but I want your latest version for applying the fixes that I suspect I will need to make.

This is a seperate issue from the database.log possibility I mentioned before.

Here are both files.
 

Attachments

New Version of RandomFleetSpawn.lua

It did not spawn units twice. However, their defensive land units disappear. It's weird. I did not kill them just captured the city. And they could not have escaped.
 
Copy and paste this somewhere into the TokyoExpressUnits.lua
Probably best to do so at the end of the file
It will fire twice every time a unit is killed or removed from the game
Code:
function prekillListener(iOwner, iUnit, iUnitType, iX, iY, bDelay, iKiller)
	print("prekillListener: Dumping data..")
	print("iOwner: " .. iOwner)
	print("iUnit: " .. iUnit)
	print("iUnitType: " .. iUnitType .. " (" .. GameInfo.Units[iUnitType].Type .. ")")
	print("iX: " .. iX)
	print("iY: " .. iY)
	print("bDelay: " .. tostring(bDelay))
	-- bDelay returns true before unit is killed (before UnitKilledInCombat) and only has one unit on the plot
	-- bDelay returns false after the unit is killed (after UnitKilledInCombat) and an enemy melee unit may be on the same plot at this point
	print("iKiller: " .. iKiller)
	local pPlot = Map.GetPlot(iX, iY)
	local iNumTileUnits = pPlot:GetNumUnits()
	print("numUnits: " .. iNumTileUnits)
	--in the following loop through the units that are still 'on the tile' the unit that was killed will also be listed
	--if the killed unit was destroyed by a direct-attack unit that direct-attack unit will also be shown as occupting the tile
	--if the killed unit was destroyed by a ranged unit of any kind then the killer unit will NOT be shown as occupying the tile
	for i = 0, pPlot:GetNumUnits() do
		local pUnit = pPlot:GetUnit(i)
		if pUnit then
			print("Unit's Owner is: " .. pUnit:GetOwner())
			print("UnitType is: " .. pUnit:GetUnitType() .. " (" .. GameInfo.Units[pUnit:GetUnitType()].Type .. ")")
		end
	end
end
GameEvents.UnitPrekill.Add(prekillListener)

----------------------------------------------------------------------------------------------------------------------------

Example of the sort of print-out you get in the lua log when a unit is killed or otherwise removed from the game.
Following example print-outs were from before I changed the code to make it list all units "occupying" the tile:
Spoiler :
Code:
--settler used to create a city
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: prekillListener: Dumping data..
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iOwner: 0
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnit: 8192
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnitType: 0 (UNIT_SETTLER)
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iX: 80
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iY: 16
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: bDelay: true
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iKiller: -1
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: numUnits: 1
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: prekillListener: Dumping data..
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iOwner: 0
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnit: 8192
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnitType: 0 (UNIT_SETTLER)
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iX: 80
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iY: 16
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: bDelay: false
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iKiller: -1
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: numUnits: 1


--barb spearman killed with a crossbowman
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: prekillListener: Dumping data..
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iOwner: 63
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnit: 204822
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnitType: 78 (UNIT_SPEARMAN)
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iX: 81
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iY: 19
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: bDelay: true
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iKiller: 0
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: numUnits: 1
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: prekillListener: Dumping data..
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iOwner: 63
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnit: 204822
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnitType: 78 (UNIT_SPEARMAN)
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iX: 81
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iY: 19
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: bDelay: false
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iKiller: -1
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: numUnits: 1


--barb warrior killed with a mech infantry who occupied the tile
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: prekillListener: Dumping data..
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iOwner: 63
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnit: 196630
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnitType: 85 (UNIT_BARBARIAN_WARRIOR)
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iX: 82
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iY: 15
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: bDelay: true
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iKiller: 0
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: numUnits: 1
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: prekillListener: Dumping data..
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iOwner: 63
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnit: 196630
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnitType: 85 (UNIT_BARBARIAN_WARRIOR)
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iX: 82
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iY: 15
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: bDelay: false
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iKiller: -1
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: numUnits: 2
 
Copy and paste this somewhere into the TokyoExpressUnits.lua
Probably best to do so at the end of the file
It will fire twice every time a unit is killed or removed from the game
Code:
function prekillListener(iOwner, iUnit, iUnitType, iX, iY, bDelay, iKiller)
	print("prekillListener: Dumping data..")
	print("iOwner: " .. iOwner)
	print("iUnit: " .. iUnit)
	print("iUnitType: " .. iUnitType .. " (" .. GameInfo.Units[iUnitType].Type .. ")")
	print("iX: " .. iX)
	print("iY: " .. iY)
	print("bDelay: " .. tostring(bDelay))
	-- bDelay returns true before unit is killed (before UnitKilledInCombat) and only has one unit on the plot
	-- bDelay returns false after the unit is killed (after UnitKilledInCombat) and an enemy melee unit may be on the same plot at this point
	print("iKiller: " .. iKiller)
	local pPlot = Map.GetPlot(iX, iY)
	local iNumTileUnits = pPlot:GetNumUnits()
	print("numUnits: " .. iNumTileUnits)
	--in the following loop through the units that are still 'on the tile' the unit that was killed will also be listed
	--if the killed unit was destroyed by a direct-attack unit that direct-attack unit will also be shown as occupting the tile
	--if the killed unit was destroyed by a ranged unit of any kind then the killer unit will NOT be shown as occupying the tile
	for i = 0, pPlot:GetNumUnits() do
		local pUnit = pPlot:GetUnit(i)
		if pUnit then
			print("Unit's Owner is: " .. pUnit:GetOwner())
			print("UnitType is: " .. pUnit:GetUnitType() .. " (" .. GameInfo.Units[pUnit:GetUnitType()].Type .. ")")
		end
	end
end
GameEvents.UnitPrekill.Add(prekillListener)

----------------------------------------------------------------------------------------------------------------------------

Example of the sort of print-out you get in the lua log when a unit is killed or otherwise removed from the game.
Following example print-outs were from before I changed the code to make it list all units "occupying" the tile:
Spoiler :
Code:
--settler used to create a city
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: prekillListener: Dumping data..
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iOwner: 0
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnit: 8192
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnitType: 0 (UNIT_SETTLER)
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iX: 80
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iY: 16
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: bDelay: true
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iKiller: -1
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: numUnits: 1
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: prekillListener: Dumping data..
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iOwner: 0
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnit: 8192
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnitType: 0 (UNIT_SETTLER)
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iX: 80
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iY: 16
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: bDelay: false
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iKiller: -1
--[1913.281] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: numUnits: 1


--barb spearman killed with a crossbowman
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: prekillListener: Dumping data..
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iOwner: 63
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnit: 204822
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnitType: 78 (UNIT_SPEARMAN)
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iX: 81
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iY: 19
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: bDelay: true
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iKiller: 0
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: numUnits: 1
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: prekillListener: Dumping data..
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iOwner: 63
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnit: 204822
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnitType: 78 (UNIT_SPEARMAN)
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iX: 81
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iY: 19
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: bDelay: false
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iKiller: -1
--[2995.703] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: numUnits: 1


--barb warrior killed with a mech infantry who occupied the tile
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: prekillListener: Dumping data..
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iOwner: 63
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnit: 196630
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnitType: 85 (UNIT_BARBARIAN_WARRIOR)
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iX: 82
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iY: 15
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: bDelay: true
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iKiller: 0
--[2487.312] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: numUnits: 1
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: prekillListener: Dumping data..
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iOwner: 63
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnit: 196630
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iUnitType: 85 (UNIT_BARBARIAN_WARRIOR)
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iX: 82
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iY: 15
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: bDelay: false
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: iKiller: -1
--[2487.375] \Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\LUA test (v 1)\Lua Script1: numUnits: 2

I am getting this. Oh and I named my computer Bert. lol I forgot I did that. I put the function at the end of the file. Each function has its own "ends" right?

Spoiler :
Code:
[407276.708] Runtime Error: C:\Users\BERT\Documents\My Games\Sid Meier's Civilization 5\MODS\Guadacanal (v 14)\Lua/TokyoExpressUnits.lua:25: attempt to call global 'JapaneseIslandDefence' (a nil value)
[407276.864] TokyoExpressUnits: prekillListener: Dumping data..
[407276.864] TokyoExpressUnits: iOwner: 0
[407276.864] TokyoExpressUnits: iUnit: 262175
[407276.864] TokyoExpressUnits: iUnitType: 17 (UNIT_DESTROYER)
[407276.864] TokyoExpressUnits: iX: 49
[407276.864] TokyoExpressUnits: iY: 29
[407276.864] TokyoExpressUnits: bDelay: true
[407276.864] TokyoExpressUnits: iKiller: 1
[407276.864] TokyoExpressUnits: numUnits: 1
[407276.864] TokyoExpressUnits: Unit's Owner is: 0
[407276.864] TokyoExpressUnits: UnitType is: 17 (UNIT_DESTROYER)
[407278.658] TokyoExpressUnits: prekillListener: Dumping data..
[407278.658] TokyoExpressUnits: iOwner: 0
[407278.658] TokyoExpressUnits: iUnit: 262175
[407278.658] TokyoExpressUnits: iUnitType: 17 (UNIT_DESTROYER)
[407278.658] TokyoExpressUnits: iX: 49
[407278.658] TokyoExpressUnits: iY: 29
[407278.658] TokyoExpressUnits: bDelay: false
[407278.658] TokyoExpressUnits: iKiller: -1
[407278.658] TokyoExpressUnits: numUnits: 1
[407278.658] TokyoExpressUnits: Unit's Owner is: 0
[407278.658] TokyoExpressUnits: UnitType is: 17 (UNIT_DESTROYER)
[407284.617] Runtime Error: C:\Users\BERT\Documents\My Games\Sid Meier's Civilization 5\MODS\Guadacanal (v 14)\Lua/TokyoExpressUnits.lua:121: attempt to index global 'NavalCombatUnits' (a nil value)
[407285.631] TurnProcessing: Hiding TurnProcessing
[407298.283] InGame: OnInterfaceModeChanged
[407298.283] InGame: oldInterfaceMode: 1
[407298.283] InGame: newInterfaceMode: 11
[407299.671] InGame: OnInterfaceModeChanged
[407299.671] InGame: oldInterfaceMode: 11
[407299.671] InGame: newInterfaceMode: 1
[407299.671] TokyoExpressUnits: prekillListener: Dumping data..
[407299.671] TokyoExpressUnits: iOwner: 1
[407299.671] TokyoExpressUnits: iUnit: 311333
[407299.671] TokyoExpressUnits: iUnitType: 41 (UNIT_ARTILLERY)
[407299.671] TokyoExpressUnits: iX: 62
[407299.671] TokyoExpressUnits: iY: 35
[407299.671] TokyoExpressUnits: bDelay: true
[407299.671] TokyoExpressUnits: iKiller: 0
[407299.671] TokyoExpressUnits: numUnits: 1
[407299.671] TokyoExpressUnits: Unit's Owner is: 1
[407299.671] TokyoExpressUnits: UnitType is: 41 (UNIT_ARTILLERY)
[407299.749] TokyoExpressUnits: prekillListener: Dumping data..
[407299.749] TokyoExpressUnits: iOwner: 1
[407299.749] TokyoExpressUnits: iUnit: 311333
[407299.749] TokyoExpressUnits: iUnitType: 41 (UNIT_ARTILLERY)
[407299.749] TokyoExpressUnits: iX: 62
[407299.749] TokyoExpressUnits: iY: 35
[407299.749] TokyoExpressUnits: bDelay: false
[407299.749] TokyoExpressUnits: iKiller: -1
[407299.749] TokyoExpressUnits: numUnits: 1
[407299.749] TokyoExpressUnits: Unit's Owner is: 1
[407299.749] TokyoExpressUnits: UnitType is: 41 (UNIT_ARTILLERY)

Here is how I added the code at the end of the file.

Spoiler :
Code:
if pPlayer:IsHuman() then
				pPlayer:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, "Reinforcements!" ,"More planes and troops arrive!", -1, -1);
			end
			
			print("American Units Added")	
		end
	end
end
GameEvents.PlayerDoTurn.Add(TokyoExpress)


print("Tokyo Express Units Loaded")

function prekillListener(iOwner, iUnit, iUnitType, iX, iY, bDelay, iKiller)
	print("prekillListener: Dumping data..")
	print("iOwner: " .. iOwner)
	print("iUnit: " .. iUnit)
	print("iUnitType: " .. iUnitType .. " (" .. GameInfo.Units[iUnitType].Type .. ")")
	print("iX: " .. iX)
	print("iY: " .. iY)
	print("bDelay: " .. tostring(bDelay))
	-- bDelay returns true before unit is killed (before UnitKilledInCombat) and only has one unit on the plot
	-- bDelay returns false after the unit is killed (after UnitKilledInCombat) and an enemy melee unit may be on the same plot at this point
	print("iKiller: " .. iKiller)
	local pPlot = Map.GetPlot(iX, iY)
	local iNumTileUnits = pPlot:GetNumUnits()
	print("numUnits: " .. iNumTileUnits)
	--in the following loop through the units that are still 'on the tile' the unit that was killed will also be listed
	--if the killed unit was destroyed by a direct-attack unit that direct-attack unit will also be shown as occupting the tile
	--if the killed unit was destroyed by a ranged unit of any kind then the killer unit will NOT be shown as occupying the tile
	for i = 0, pPlot:GetNumUnits() do
		local pUnit = pPlot:GetUnit(i)
		if pUnit then
			print("Unit's Owner is: " .. pUnit:GetOwner())
			print("UnitType is: " .. pUnit:GetUnitType() .. " (" .. GameInfo.Units[pUnit:GetUnitType()].Type .. ")")
		end
	end
end
GameEvents.UnitPrekill.Add(prekillListener)
 
The way you added the code looks ok, but I am concerned as to why you are getting the runtime errors that are showing. I don't remember ever seeing any of those, nor should you be really getting them. Post the mod as it currently is.
 
The way you added the code looks ok, but I am concerned as to why you are getting the runtime errors that are showing. I don't remember ever seeing any of those, nor should you be really getting them. Post the mod as it currently is.

Here it is.
 

Attachments

Spoiler :
Code:
somehow RandomFleetSpawn.lua got set as ImportIntoVFS=false. It needs to be set as "true" in the file properties.

Alright I'll fix it. I also think Japan's economy is breaking down. That could be why it is deleting units. I am going to check on it. I may have to do something to make sure both sides stay healthy economy wise.

It seems the economy is ok with Japan, but I am going to start a new game and check from the beginning. For some reason it has disbanded two coastal artillery units. I am guessing at some point they go into the red and begin disbanding units.

Also, I am missing a Japanese machine gun unit. What does this say or mean? I think this is talking about that particular unit. I never destroyed him he is just not visible to me. Is he still alive? :(

Spoiler :
Code:
[9936.811] TokyoExpressUnits: prekillListener: Dumping data..
[9936.811] TokyoExpressUnits: iOwner: 1
[9936.811] TokyoExpressUnits: iUnit: 1720359
[9936.811] TokyoExpressUnits: iUnitType: 137 (UNIT_MACHINE_GUN)
[9936.811] TokyoExpressUnits: iX: 37
[9936.811] TokyoExpressUnits: iY: 18
[9936.811] TokyoExpressUnits: bDelay: true
[9936.811] TokyoExpressUnits: iKiller: -1
[9936.811] TokyoExpressUnits: numUnits: 1
[9936.811] TokyoExpressUnits: Unit's Owner is: 1
[9936.811] TokyoExpressUnits: UnitType is: 137 (UNIT_MACHINE_GUN)
[9936.842] TokyoExpressUnits: Running function JapaneseIslandDefence
[9936.842] TokyoExpressUnits: For Peava bAlertMode was false
[9936.842] TokyoExpressUnits: For Peava bInvadeMode was false
[9936.842] TokyoExpressUnits: For Rendova bAlertMode was false
[9936.842] TokyoExpressUnits: For Rendova bInvadeMode was false
[9936.842] TokyoExpressUnits: For Wickham Anchorage bAlertMode was false
[9936.842] TokyoExpressUnits: For Wickham Anchorage bInvadeMode was false
[9936.842] TokyoExpressUnits: For Munda bAlertMode was false
[9936.842] TokyoExpressUnits: For Munda bInvadeMode was false
[9936.842] TokyoExpressUnits: For Ghurava bAlertMode was false
[9936.842] TokyoExpressUnits: For Ghurava bInvadeMode was false
[9936.842] TokyoExpressUnits: For Buin bAlertMode was false
[9936.842] TokyoExpressUnits: For Buin bInvadeMode was false
[9936.842] TokyoExpressUnits: For Piva bAlertMode was false
[9936.842] TokyoExpressUnits: For Piva bInvadeMode was false
[9936.842] TokyoExpressUnits: For Taki bAlertMode was false
[9936.842] TokyoExpressUnits: For Taki bInvadeMode was false
[9936.842] TokyoExpressUnits: For Panguna bAlertMode was false
[9936.842] TokyoExpressUnits: For Panguna bInvadeMode was false
[9936.842] TokyoExpressUnits: For Japanese Supply Base bAlertMode was false
[9936.842] TokyoExpressUnits: For Japanese Supply Base bInvadeMode was false
[9936.842] TokyoExpressUnits: For Ndora bAlertMode was false
[9936.842] TokyoExpressUnits: For Ndora bInvadeMode was false
[9936.842] TokyoExpressUnits: prekillListener: Dumping data..
[9936.842] TokyoExpressUnits: iOwner: 1
[9936.842] TokyoExpressUnits: iUnit: 1720359
[9936.842] TokyoExpressUnits: iUnitType: 137 (UNIT_MACHINE_GUN)
[9936.842] TokyoExpressUnits: iX: 37
[9936.842] TokyoExpressUnits: iY: 18
[9936.842] TokyoExpressUnits: bDelay: false
[9936.842] TokyoExpressUnits: iKiller: -1
[9936.842] TokyoExpressUnits: numUnits: 1
[9936.842] TokyoExpressUnits: Unit's Owner is: 1
[9936.842] TokyoExpressUnits: UnitType is: 137 (UNIT_MACHINE_GUN)
[9938.433] CityBannerManager: CityBanner CombatBegin
[9939.993] CityBannerManager: CityBanner CombatEnd
[9940.009] CityBannerManager: CityBanner CombatBegin
[9943.519] CityBannerManager: CityBanner CombatEnd
[9943.534] CityBannerManager: CityBanner CombatBegin
[9947.263] CityBannerManager: CityBanner CombatEnd
[9947.278] CityBannerManager: CityBanner CombatBegin
[9952.785] CityBannerManager: CityBanner CombatEnd
[9954.595] CityBannerManager: CityBanner CombatBegin
[9955.827] CityBannerManager: CityBanner CombatEnd
[9955.843] CityBannerManager: CityBanner CombatBegin
[9960.851] CityBannerManager: CityBanner CombatEnd
[9960.866] CityBannerManager: CityBanner CombatBegin
[9965.468] CityBannerManager: CityBanner CombatEnd
[9971.927] TokyoExpressUnits: nil

A few more things... Does the highlighted in blue, in the spoiler below, need to be there for trait FIGHT_WELL_DAMAGED? And does Japan get the TRAIT_RIVER_EXPANSION? Because they need it. Also, is there a trait that deals with Building Maintenance? So that can be reduced? This seems to be leading to turning off gold somehow for this scenario. It really is not needed.

Spoiler :
Code:
<Traits>
		<Update>
			<Where Type="TRAIT_RIVER_EXPANSION"/>
			<Set>
				<LandUnitMaintenanceModifier>-100</LandUnitMaintenanceModifier>
				<NavalUnitMaintenanceModifier>-100</NavalUnitMaintenanceModifier>
			</Set>
		</Update>
		<Update>
			<Where Type="TRAIT_FIGHT_WELL_DAMAGED"/>
			<Set>
				<[COLOR="Blue"]LandUnitMaintenanceModifier[/COLOR]>-100</[COLOR="Blue"]LandUnitMaintenanceModifier[/COLOR]>
				<[COLOR="Blue"]NavalUnitMaintenanceModifier[/COLOR]>-100</[COLOR="Blue"]NavalUnitMaintenanceModifier[/COLOR]>
				<FightWellDamaged>false</FightWellDamaged>
			</Set>
		</Update>
	</Traits>
 
  1. The log related to the machine gun is telling me the AI is most likely disbanding it, or the game itself is disbanding it because "you got too many units so X was disbanded"
  2. Any unit for which there is a spit-out of lines from the Prekill Listener means that unit was removed from the game in some manner: killed, upgraded, used to settle, disbanded, removed for not enough gold, captured by barbarians, re-captured and 'rescued' from barbarians, etc.
    • In the segment of lines where bDelay is showing as "true", if iKiller is being shown as "-1" or as the same number as the iOwner this is generally indicative of the player (the AI in this case) or the game itself eliminated the unit.
  3. The stuff in blue in the Leader-Traits <Updates> you added a while ago to deal with the unit maintenance-cost issues, but that was before a lot more units were added to the scenario.
  4. TRAIT_RIVER_EXPANSION is Washington's trait. It is quite a bit of a misnomer, because TRAIT_RIVER_EXPANSION really has absolutely nothing in it that is actually related to rivers or expansion. With the way those trait updates are structured you are already giving Japan anything useful that is also being given to America, in terms of this scenario. TRAIT_FIGHT_WELL_DAMAGED is Oda Bunganunga's Leader-Trait, so is the one usually used for Japan.
  5. There is a column <NoMaintenance>true</NoMaintenance> for use within table <Units> that is used with Guided Missiles, but I don't know if it is coded-in in such a way that adding it to other unit-types will have bizarre results.
  6. For AI's (and human players) there are really two issues, one is maintenance cost in Gold, and the other is number of units the empire can supply.
    • The number of units an empire can supply can be fixed for the scenario by simply jacking up to a crazy high number the amount of "free-supply" units from difficulty levels. There is really no downside to this since you aren't creating a condition in this scenario where this mechanic to limit a player's army based on a player's overall empire size and population really applies.
    • Putting this into the XML code should cure the issue with how many units an empire can supply and gold-maintain, assuming there is not some hard-code limit in the operating software of the game:
      Spoiler :
      Code:
      <GameData>
      	<HandicapInfos>
      		<Update>
      			<Where Type="HANDICAP_SETTLER"/>
      			<Set>
      				<ProductionFreeUnits>500</ProductionFreeUnits>
      				<Gold>5000</Gold>
      				<GoldFreeUnits>500</GoldFreeUnits>
      			</Set>
      		</Update>
      		<Update>
      			<Where Type="HANDICAP_CHIEFTAIN"/>
      			<Set>
      				<ProductionFreeUnits>500</ProductionFreeUnits>
      				<Gold>5000</Gold>
      				<GoldFreeUnits>500</GoldFreeUnits>
      			</Set>
      		</Update>
      		<Update>
      			<Where Type="HANDICAP_WARLORD"/>
      			<Set>
      				<ProductionFreeUnits>500</ProductionFreeUnits>
      				<Gold>5000</Gold>
      				<GoldFreeUnits>500</GoldFreeUnits>
      			</Set>
      		</Update>
      		<Update>
      			<Where Type="HANDICAP_PRINCE"/>
      			<Set>
      				<ProductionFreeUnits>500</ProductionFreeUnits>
      				<Gold>5000</Gold>
      				<GoldFreeUnits>500</GoldFreeUnits>
      			</Set>
      		</Update>
      		<Update>
      			<Where Type="HANDICAP_KING"/>
      			<Set>
      				<ProductionFreeUnits>500</ProductionFreeUnits>
      				<Gold>5000</Gold>
      				<GoldFreeUnits>500</GoldFreeUnits>
      			</Set>
      		</Update>
      		<Update>
      			<Where Type="HANDICAP_EMPEROR"/>
      			<Set>
      				<ProductionFreeUnits>500</ProductionFreeUnits>
      				<Gold>5000</Gold>
      				<GoldFreeUnits>500</GoldFreeUnits>
      			</Set>
      		</Update>
      		<Update>
      			<Where Type="HANDICAP_IMMORTAL"/>
      			<Set>
      				<ProductionFreeUnits>500</ProductionFreeUnits>
      				<Gold>5000</Gold>
      				<GoldFreeUnits>500</GoldFreeUnits>
      			</Set>
      		</Update>
      		<Update>
      			<Where Type="HANDICAP_DEITY"/>
      			<Set>
      				<ProductionFreeUnits>500</ProductionFreeUnits>
      				<Gold>5000</Gold>
      				<GoldFreeUnits>500</GoldFreeUnits>
      			</Set>
      		</Update>
      		<Update>
      			<Where Type="HANDICAP_AI_DEFAULT"/>
      			<Set>
      				<ProductionFreeUnits>500</ProductionFreeUnits>
      				<Gold>5000</Gold>
      				<GoldFreeUnits>500</GoldFreeUnits>
      			</Set>
      		</Update>
      	</HandicapInfos>
      </GameData>
    • I've never used the <Gold> and <GoldFreeUnits> columns in <HandicapInfos> but Firaxis have them both set to '0' within all the difficulty levels, which makes me tend to think the two columns probably do work. If this fixes the economy-issues related to the number of units that can be supported and maintained, then you wouldn't really need the reduction in Land and Sea Unit maintenance costs tied to the two leader-traits.
    • <Gold> if it works as I expect should add a set lump of gold at the start of the game. If you have an amount set in the Map Scenario Properties for each player, however, the two might clash, and I'm not sure which would take precedent over the other method for giving a player starting gold in their treasury.
 
New version of the UnitSpawnHandler.lua

Just copy the new version in as you have been doing for other lua 'replacements' I've been sending.

I have removed all other attachments I had in this thread to eliminate any chances of confusion with outdated files.

This new version of UnitSpawnHandler.lua will not allow you to specify a promotion that is 'incorrect' for a particular unit type. It wil not crash or anything, it will jsut not add the promotion to the unit. So if you added PROMOTION_MORALE accidently to a Great General or Great Admiral using the SpawnAtPlot function, that promotion would be ignored, but any others added to a list of promotions that were correct for a Great General or a Great Admiral would be added.

Air units that need to jump to a different plot tile than the one originally stated will make a 'nearest valid landing-field' type of search. If the original plot should have held a carrier, but the carrier got bumped out of position because of an interfering unit, the air unit trying to be placed will look 1st in all adjacent tiles to the original target, then will look through all carrier units that have space and use the nearest one, then will look for the nearest city if there are no valid carriers to go to. If all of these fail, the air unit will not be spawned.

If the air unit was targetted to appear at a city, but the city is full or has been captured, then the program will search for the nearest city to appear at, then will look for a valid carrier if all cities are already full. If all of these fail, the air unit will not be spawned.

I don't think there are any remaining bugs (I tried to test as many conditions as possible) but you never know.
 

Attachments

New version of the UnitSpawnHandler.lua

Just copy the new version in as you have been doing for other lua 'replacements' I've been sending.

I have removed all other attachments I had in this thread to eliminate any chances of confusion with outdated files.

This new version of UnitSpawnHandler.lua will not allow you to specify a promotion that is 'incorrect' for a particular unit type. It wil not crash or anything, it will jsut not add the promotion to the unit. So if you added PROMOTION_MORALE accidently to a Great General or Great Admiral using the SpawnAtPlot function, that promotion would be ignored, but any others added to a list of promotions that were correct for a Great General or a Great Admiral would be added.

Air units that need to jump to a different plot tile than the one originally stated will make a 'nearest valid landing-field' type of search. If the original plot should have held a carrier, but the carrier got bumped out of position because of an interfering unit, the air unit trying to be placed will look 1st in all adjacent tiles to the original target, then will look through all carrier units that have space and use the nearest one, then will look for the nearest city if there are no valid carriers to go to. If all of these fail, the air unit will not be spawned.

If the air unit was targetted to appear at a city, but the city is full or has been captured, then the program will search for the nearest city to appear at, then will look for a valid carrier if all cities are already full. If all of these fail, the air unit will not be spawned.

I don't think there are any remaining bugs (I tried to test as many conditions as possible) but you never know.

Interesting and thank you LeeS. I'll do some testing, but first have some xml to deal with.
 
Alright here is the scenario as it sits right now. With a new unit spawn handler and the HurryCostModifier for units. I am going to try to leave the buildings alone. If your economy is good enough they can be purchased. I want to leave at least that aspect of civ available. This has playtested yet.
 

Attachments

Here is the VictoryConditions file. Add it to your mod and set it up as ImportIntoVFS=false (this is the default setting, but always good to double-check) and then add it as an InGameUIAddin.

I have a few notes in comments at the top of the lua file. I'm sure you'll have questions once you look through it :)

I tested both the single-city and multiple-city victory requirement.

Also, I have a newer version of UnitSpawnHandler.lua that you might want to copy-paste over the older version. Unit Spawn Handler page.
 

Attachments

Back
Top Bottom