Lua - Help with Colony Script

Genghis.Khan

Person
Joined
Jun 9, 2012
Messages
934
Location
Somewhere
So, I've been working on the implementation of a Colony System, and recently I decided to expand my improvement Mod with a new concept, and integrate those mechanics into UnOfficial Expansion: Rise and Fall of Empires. The Mechanics I designed for the Colony System are fairly simple, but I have not coded all of them. I've ran a test with one of the first rules, that there is a chance that, when a Colonist founds a Colony, the second starts a revolution. I've used code from Gedemon's Revolutions and whoward's Area Plot Iterators. For some reason, the test I ran, nothing happened. Not even a print statement in Lua.log and I have logging enabled... I have no idea why did this happened, can you understand what is wrong with this code

Code:
 -- ColoniesMain.lua
-- Author: Genghis.Khan
-- Special Thanks: FramedArchitecture, whoward69, Hambil, Irkalla, Gedemon
-- Date Created: 03-07-2013 13:22
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

print(" ... please... work" )

RESERVED_CITY_STATES = 10

SECTOR_NORTH = 1
SECTOR_NORTHEAST = 2
SECTOR_SOUTHEAST = 3
SECTOR_SOUTH = 4
SECTOR_SOUTHWEST = 5
SECTOR_NORTHWEST = 6

DIRECTION_CLOCKWISE = false
DIRECTION_ANTICLOCKWISE = true

DIRECTION_OUTWARDS = false
DIRECTION_INWARDS = true

CENTRE_INCLUDE = true
CENTRE_EXCLUDE = false


function PlotAreaSpiralIterator(pPlot, r, sector, anticlock, inwards, centre) -- by whoward69
  local next = coroutine.create(function ()
    if (centre and not inwards) then
      coroutine.yield(pPlot)
    end

    if (inwards) then
      for i=r, 1, -1 do
        for pEdgePlot in PlotRingIterator(pPlot, i, sector, anticlock) do
          coroutine.yield(pEdgePlot)
        end
      end
    else
      for i=1, r, 1 do
        for pEdgePlot in PlotRingIterator(pPlot, i, sector, anticlock) do
          coroutine.yield(pEdgePlot)
        end
      end
    end

    if (centre and inwards) then
      coroutine.yield(pPlot)
    end

    return nil
  end)

  -- This function returns the next plot in the sequence
  return function ()
    local success, pAreaPlot = coroutine.resume(next)
    return success and pAreaPlot or nil
  end
end

function RebelUnitsToSpawnSettler()
 
local pPlayer = Players[playerID]
local team = pPlayer:GetTeam();
		if team:HasTech(teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
				return GameInfo.Units.UNIT_GREAT_WAR_INFANTRY.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
				return GameInfo.Units.UNIT_RIFLEMAN.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID ) then
				return GameInfo.Units.UNIT_MUSKETMAN.ID 
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
				return GameInfo.Units.UNIT_PIKEMAN.ID
		elseif    teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
				return GameInfo.Units.UNIT_SPEARMEN.ID
		else    
				return GameInfo.Units.UNIT_WARRIOR.ID
		end
end


function RebelUnitsToSpawnPrince()
 
local pPlayer = Players[playerID]
local team = pPlayer:GetTeam();
		if team:HasTech(teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
				return GameInfo.Units.UNIT_INFANTRY.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
				return GameInfo.Units.UNIT_GREAT_WAR_INFANTRY.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID ) then
				return GameInfo.Units.UNIT_RIFLEMAN.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
				return GameInfo.Units.UNIT_MUSKETMAN.ID 
		elseif    teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
				return GameInfo.Units.UNIT_PIKEMAN.ID
		else    
				return GameInfo.Units.UNIT_SPEARMEN.ID
		end
end

function RebelUnitsToSpawnEmperor()
 
local pPlayer = Players[playerID]
local team = pPlayer:GetTeam();
		if team:HasTech(teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
				return GameInfo.Units.UNIT_MECHANIZED_INFANTRY.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
				return GameInfo.Units.UNIT_INFANTRY.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID ) then
				return GameInfo.Units.UNIT_GREAT_WAR_INFANTRY.ID	
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
				return GameInfo.Units.UNIT_RIFLEMAN.ID	
		elseif    teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
				return GameInfo.Units.UNIT_MUSKETMAN.ID 	
		else    
				return GameInfo.Units.UNIT_PIKEMAN.ID
		end
end

function ReserveCS() -- by Gedemon

	local bDebug = true

	Dprint ("------------------ ", bDebug)
	Dprint ("Initializing City-States... ", bDebug)

	local numCS = modUserData.GetValue("NumMinorCivs")
	
	Dprint ("  - Number of CS required by the player = " .. numCS, bDebug)

	local loadedCS = {}
	for playerID = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS - 1 do
		local player = Players[playerID]
		local minorCivID = player:GetMinorCivType()
		-- Does this civ exist ?
		if minorCivID ~= -1 then
			table.insert(loadedCS, playerID)
		end
	end
	
	Dprint ("  - Number of active CS in game = " .. #loadedCS, bDebug)

	local reservedCS = {}
	if RESERVED_CITY_STATES > #loadedCS then
		Dprint ("  - WARNING : Loaded CS < RESERVED_CITY_STATES ")
	elseif numCS + RESERVED_CITY_STATES > #loadedCS then
		Dprint ("  - Not enough CS active for all request, keeping " .. #loadedCS - RESERVED_CITY_STATES .. " alive..." , bDebug)
		for i = #loadedCS - RESERVED_CITY_STATES, #loadedCS do
			local playerID = loadedCS[i]
			RemoveCiv (playerID)
			reservedCS[playerID] = { Action = nil, Type = nil, Reference = nil}
		end
	else
		Dprint ("  - Keeping " .. numCS .. " alive..." , bDebug)
		for i = numCS + 1, #loadedCS do
			local playerID = loadedCS[i]
			RemoveCiv (playerID)
			reservedCS[playerID] = { Action = nil, Type = nil, Reference = nil}
		end
	end
	SaveData( "ReservedCS", reservedCS )
end

function Shuffle(t) -- by Gedemon
  local n = #t
 
  while n >= 2 do
    -- n is now the last pertinent index
    local k = math.random(n) -- 1 <= k <= n
    -- Quick swap
    t[n], t[k] = t[k], t[n]
    n = n - 1
  end
 
  return t
end

function EstabilishColonyInitialRebellion ()
	for plotLoop = 0, Map.GetNumPlots() - 1, 1 do
		local improvementType = plot:GetImprovementType()
			if ( improvementType == GameInfoTypes["IMPROVEMENT_COLONY"] ) then
				local iColonyPlotX = pPlot:GetX
				local iColonyPlotY = pPlot:GetY
				local iHandicapModifier = (10 * Game.GetHandicapType())
				local pTeam = Teams[teamID]
				if ( pTeam:GetCurrentEra() == GameInfoTypes["ERA_COLONIAL"] ) then
					local iEraModifier == 0 
				elseif ( pTeam:GetCurrentEra() == GameInfoTypes["ERA_INDUSTRIAL"] ) then
					local iEraModifier == 10 
				elseif ( pTeam:GetCurrentEra() == GameInfoTypes["ERA_MODERN"] ) then
					local iEraModifier == 20
					-- Colony build is obsolete when any Atomic Era Technology is researched (see CIV5RFEBuilds.lua and CIV5RFEBuilds.sql)
				end
					if math.random(1, 100) > math.floor(iHandicapModifier + iEraModifier) then
						local pPlayer = Players[playerID]
						local rebelID = nil
							if not rebelID then
								if #freeSlots > 0 then
									rebelID = freeSlots[1]
									DeclarePermanentWar(rebelID, playerID)
									local freePlots = {}
												local pColonyPlot = Plot:At(iColonyPlotX, iColonyPlotY)
												local plotNumUnits = plot:GetNumUnits()
													if not (plot:IsWater()) and not (plotNumUnits > 3) then
													local iRadius = 2				
													for pAreaPlot in PlotAreaSpiralIterator(pColonyPlot, iRadius, SECTOR_NORTH, DIRECTION_ANTICLOCK, DIRECTION_INWARDS, CENTRE_INCLUDE) do
														print(pAreaPlot:GetX(), pAreaPlot:GetY()) 
														table.insert(freePlots, pAreaPlot)
													end
											end
									Shuffle(freePlots)
									for n, plot in pairs(freePlots) do
										local freeUnitSettler = RebelUnitsToSpawnSettler()
										local freeUnitPrince = RebelUnitsToSpawnPrince()
										local freeUnitEmperor = RebelUnitsToSpawnEmperor() 
										if Game.GetHandicapType() == 0 then
											if math.random(1,5) < 6 then
												Player[rebelID]:AddFreeUnit(freeUnitSettler, UNITAI_OFFENSE)
											else 
												return false
											end
										if Game.GetHandicapType() == 1 then
											Player[rebelID]:AddFreeUnit(freeUnitPrince, UNITAI_OFFENSE)
										if Game.GetHandicapType() == 2 then
											Player[rebelID]:AddFreeUnit(freeUnitSettler, UNITAI_OFFENSE)
											Player[rebelID]:AddFreeUnit(freeUnitSettler, UNITAI_OFFENSE)
										if Game.GetHandicapType() == 3 then
											Player[rebelID]:AddFreeUnit(freeUnitPrince, UNITAI_OFFENSE)
											Player[rebelID]:AddFreeUnit(freeUnitPrince, UNITAI_OFFENSE)
										if Game.GetHandicapType() == 4 then
											Player[rebelID]:AddFreeUnit(freeUnitPrince, UNITAI_OFFENSE)
											Player[rebelID]:AddFreeUnit(freeUnitPrince, UNITAI_OFFENSE)
											Player[rebelID]:AddFreeUnit(freeUnitSettler, UNITAI_OFFENSE)
										if Game.GetHandicapType() == 5 then
											Player[rebelID]:AddFreeUnit(freeUnitEmperor, UNITAI_OFFENSE)
											Player[rebelID]:AddFreeUnit(freeUnitEmperor, UNITAI_OFFENSE)
											Player[rebelID]:AddFreeUnit(freeUnitPrince, UNITAI_OFFENSE)
										if Game.GetHandicapType() == 6 then
											Player[rebelID]:AddFreeUnit(freeUnitEmperor, UNITAI_OFFENSE)
											Player[rebelID]:AddFreeUnit(freeUnitEmperor, UNITAI_OFFENSE)
											Player[rebelID]:AddFreeUnit(freeUnitEmperor, UNITAI_OFFENSE)	
											Player[rebelID]:AddFreeUnit(freeUnitPrince, UNITAI_OFFENSE)
										if Game.GetHandicapType() == 7 then
											Player[rebelID]:AddFreeUnit(freeUnitEmperor, UNITAI_OFFENSE)
											Player[rebelID]:AddFreeUnit(freeUnitEmperor, UNITAI_OFFENSE)
											Player[rebelID]:AddFreeUnit(freeUnitEmperor, UNITAI_OFFENSE)	
											Player[rebelID]:AddFreeUnit(freeUnitEmperor, UNITAI_OFFENSE)
											Player[rebelID]:AddFreeUnit(freeUnitPrince, UNITAI_OFFENSE)
										else return false end
									end
								else return false end
							else return false end
					else return false end
				else return false end
			else return false end
	end
end
Events.SerialEventImprovementCreated.Add(EstabilishColonyInitialRebellion)
 
No errors from that script nor the output of the first print statement can only mean one thing. You don't have an InGameUIAddin entry for the lua file
 
You're adding the rebellion function to event improvement created. Is that intentional? It sounds like you meant to use city created (or whatever the exact name of that event is).
 
Ok, confused wheteter to Set InGameUIAdding/VFS = "true" for those 3 lua files. Can somebody help me with that? My current is not wiorking...

Code below if necessary:


ColoniesMain.lua

Code:
-- ColoniesMain.lua
-- Author: Genghis.Khan
-- Special Thanks: FramedArchitecture, whoward69, Hambil, Irkalla, Gedemon
-- Date Created: 03-07-2013 13:22
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

print(" ... but please... work" )

include("ColoniesFunctions.lua")
include("ColoniesDefines.lua")

-- Missing Feature: Colonies Requests (Grant Independence, Build Hospital...)
-- Missing Feature: Calculate Rebel Units to Spawn based on Colony Size

function EstabilishColonyInitialRebellion ()
	for plotLoop = 0, Map.GetNumPlots() - 1, 1 do
		local improvementType = plot:GetImprovementType()
			if ( improvementType == GameInfoTypes["IMPROVEMENT_COLONY"] ) then
				local iColonyPlotX = pPlot:GetX
				local iColonyPlotY = pPlot:GetY
				local iHandicapModifier = (10 * Game.GetHandicapType())
				local iTurnColonyFounded = Game.GetGameTurn()
				local pTeam = Teams[teamID]
				if ( pTeam:GetCurrentEra() == GameInfoTypes["ERA_COLONIAL"] ) then
					local iEraModifier == 0 
				elseif ( pTeam:GetCurrentEra() == GameInfoTypes["ERA_INDUSTRIAL"] ) then
					local iEraModifier == 10 
				elseif ( pTeam:GetCurrentEra() == GameInfoTypes["ERA_MODERN"] ) then
					local iEraModifier == 20 -- Colonies are obsolote after reaching the Atomic Era (CIV5RFEBuilds.lua and CIV5RFEBuilds.sql)
				end
					if math.random(1, 100) < iHandicapModifier + iEraModifier then
					print("Initial Revolt has started")
						local pPlayer = Players[playerID]
						local rebelID = nil
							if not rebelID then
								if #freeSlots > 0 then
									rebelID = freeSlots[1]
									DeclarePermanentWar(rebelID, playerID)
									local freePlots = {}
												local pColonyPlot = Plot:At(iColonyPlotX, iColonyPlotY)
												local plotNumUnits = plot:GetNumUnits()
													if not (plot:IsWater()) and not (plotNumUnits > 3) then
													local iRadius = 2				
													for pAreaPlot in PlotAreaSpiralIterator(pColonyPlot, iRadius, SECTOR_NORTH, DIRECTION_ANTICLOCK, DIRECTION_INWARDS, CENTRE_INCLUDE) do
														print(pAreaPlot:GetX(), pAreaPlot:GetY()) 
														table.insert(freePlots, pAreaPlot)
													end
											end
									Shuffle(freePlots)
									for n, plot in pairs(freePlots) do
										local freeUnitSettler = RebelUnitsToSpawnSettler()
										local freeUnitPrince = RebelUnitsToSpawnPrince()
										local freeUnitEmperor = RebelUnitsToSpawnEmperor() 
										if Game.GetHandicapType() == 0 then
											if math.random(1,5) < 6 then
												Player[rebelID]:InitUnit(freeUnitSettler, pAreaPlot:GetX(), pAreaPlotlot:GetY())
											else 
												return false
											end
										if Game.GetHandicapType() == 1 then
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlotlot:GetY()) 
										if Game.GetHandicapType() == 2 then
											Player[rebelID]:InitUnit(freeUnitSettler, pAreaPlot:GetX(), pAreaPlotlot:GetY())
											Player[rebelID]:InitUnit(freeUnitSettler, pAreaPlot:GetX(), pAreaPlotlot:GetY())
										if Game.GetHandicapType() == 3 then
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlotlot:GetY())
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlotlot:GetY())
										if Game.GetHandicapType() == 4 then
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlotlot:GetY())
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlotlot:GetY())
											Player[rebelID]:InitUnit(freeUnitSettler, pAreaPlot:GetX(), pAreaPlotlot:GetY())
										if Game.GetHandicapType() == 5 then
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlotlot:GetY())
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlotlot:GetY())
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlotlot:GetY())
										if Game.GetHandicapType() == 6 then
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlotlot:GetY())
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlotlot:GetY())
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlotlot:GetY())	
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlotlot:GetY())
										if Game.GetHandicapType() == 7 then
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlotlot:GetY())
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlotlot:GetY())
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlotlot:GetY())	
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlotlot:GetY())
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlotlot:GetY())
										else return false end
									end
								else return false end
							else return false end
					else return false end
				else return false end
			else return false end
	end
end
Events.SerialEventImprovementCreated.Add(EstabilishColonyInitialRebellion)										
										
GameEvents.PlayerDoTurn.Add(function(iPlayer)
	local pPlayer = Players[playerID]
		if  pPlayer:GetID() == rebelID then
				for pUnit in pPlayer:Units() do													
					local pPlot = pUnit:GetPlot()
						for plotLoop = 0, Map.GetNumPlots() - 1, 1 do
						local improvementType = plot:GetImprovementType()
						if ( plot:GetNumUnits() > 0  and improvementType == GameInfoTypes["IMPROVEMENT_COLONY"] ) then	
							pPlot:SetOwner(rebelID, 0, false, true) -- will this turn the Colony into a CS? if yes then remove permanent war to damaged relationship
				else 
					return false 
				end
			else 
				return false 
			end				
end);

--function ExpandColonies ()
GameEvents.PlayerDoTurn.Add(function(iPlayer)
	for plotLoop = 0, Map.GetNumPlots() - 1, 1 do
		local improvementType = plot:GetImprovementType()
			if ( improvementType == GameInfoTypes["IMPROVEMENT_COLONY"] ) then
				local iColonyPlotX = pPlot:GetX
				local iColonyPlotY = pPlot:GetY
				local pColonyPlot = Plot:At(iColonyPlotX, iColonyPlotY)
				local iColonyOwner = pColonyPlot:GetOwner()
				for pAreaPlot in PlotAreaSpiralIterator(pColonyPlot, iRadius, SECTOR_NORTH, DIRECTION_ANTICLOCK, DIRECTION_INWARDS, CENTRE_INCLUDE) do
					print(pAreaPlot:GetX(), pAreaPlot:GetY()) 
					local iNumFood = pAreaPlot:CalculateYield(0, true);	
					local iNumProduction = pAreaPlot:CalculateYield(1, true);
					local iNumGold = pAreaPlotlot:CalculateYield(2, true);	
					local iNumScience = pAreaPlot:CalculateYield(3, true);
					local iNumCulture = pAreaPlot:CalculateYield(4, true);
					local iNumFaith = pAreaPlot:CalculateYield(5, true);
					local iColonyGrowthRequired = 50
					--local iColonyCompletedRequestGrowthWeight = 100 
					--local iColonyDeniedRequestHappinessWeight = -200
					local pPlayerTeam = pColonyOwner:GetTeam()
					if ( pPlayerTeam:GetCurrentEra() == GameInfoTypes["ERA_COLONIAL"] ) then
						local iEraHappinessModifier = 0
					elseif ( pPlayerTeam:GetCurrentEra() == GameInfoTypes["ERA_INDUSTRIAL"] ) then
						local iEraHappinessModifier = -30
					elseif ( pPlayerTeam:GetCurrentEra() == GameInfoTypes["ERA_MODERN"] ) then
						local iEraHappinessModifier = -50
					elseif ( pPlayerTeam:GetCurrentEra() == GameInfoTypes["ERA_ATOMIC"] ) then
						local iEraHappinessModifier = -75
					elseif ( pPlayerTeam:GetCurrentEra() == GameInfoTypes["ERA_INFORMATION"] ) then
						local iEraHappinessModifier = -100
					else return false end
					local iColonyPublicOrder = (pColonyPlot:GetUnitPower(iColonyOwner) * 0.5)
					local iOwnerHappiness = pColonyOwner:GetHappiness()
					if pColonyPlot:GetResourceType(pPlayerTeam) < 7 then 
						local iGrowthFromStrategic = iGrowthFromStrategic + 1
					elseif pColonyPlot:GetResourceType(pPlayerTeam) < 16 then	
						local iGrowthFromBonus = iGrowthFromBonus + 1
					else
						local iGrowthFromLuxury = iGrowthFromLuxury +1
					end
					local iCurrentTurn = Game.GetGameTurn()
					local iTurnsSinceColonyFounded = iCurrentTurn - iTurnColonyFounded
					local iGamePace = Game.GetGameSpeedType()
						if  iGamePace < 1 then -- Quick Speed
							iTurnsSinceColonyFounded = iTurnsSinceColonyFounded * 1.51 
						elseif iGamePace = 1 then -- Standart Speed
							iTurnsSinceColonyFounded = iTurnsSinceColonyFounded * 1 
						elseif iGamePace = 2 then -- Epic Speed
							iTurnsSinceColonyFounded = iTurnsSinceColonyFounded / 1.5  
						elseif iGamePace = 3 then -- Marathon Speed
							iTurnsSinceColonyFounded = iTurnsSinceColonyFounded / 3 
					local iColonyHappiness = iEraHappinessModifier + iGrowthFromLuxury * 40 + iGrowthFromStrategic * 60 + iGrowthFromBonus * 20 + (iNumCulture * -10) + (iNumScience * -5) + (iNumFaith * -10) + (iColonyPublicOrder * 20) + (iOwnerHappiness * 0.5) -- + iColonyCompletedRequestGrowthWeight + iColonyDeniedRequestGrowthWeight
					local iGrowthProgress = iNumFood * 3 + iNumProduction * 2 + iNumGold * 4 + iNumScience + iNumCulture + iNumFaith + iColonyHappiness + (iTurnsSinceColonyFounded * 3)
					if iGrowthProgress >= iColonyGrowthRequired then
						local iTimesGrowth = TimesGrowth()
						local iRadiusBorders = iTimesGrowth + 1 
						if iTimesGrowth = 0 then
							pAreaPlot:SetOwner(iColonyOwner, iRadiusBorders, false, true)
							iGrowthProgress = 0
							iColonyGrowthRequired =	iColonyGrowthRequired * 1
						end
						elseif iTimesGrowth = 1 then 
							pAreaPlot:SetOwner(iColonyOwner, iRadiusBorders, false, true)
							iGrowthProgress = 0
							iColonyGrowthRequired =	250
						end
						elseif iTimesGrowth = 2 then
							pAreaPlot:SetOwner(iColonyOwner, iRadiusBorders, false, true)
							iGrowthProgress = 0
							iColonyGrowthRequired = 500
						elseif iTimesGrowth = 3 then
							pAreaPlot:SetOwner(iColonyOwner, iRadiusBorders, false, true)
							iGrowthProgress = 0
							iColonyGrowthRequired = 750
						elseif iTimesGrowth = 4 then
							iColonyGrowth = 999999
							Player[iColonyOwner]:InitCity(pColonyPlotX, pColonyPlotY);
							end
						else
							print("Achievement Unlocked - Beat the Code - Grow a Colony over 4 Times")
							return false
						end
					end
					else 
						return false 
					end
				end
			end
		end			
	end
end);


-- function GrantIndependence()


--function EstabilishColonyRevolt()
GameEvents.PlayerDoTurn.Add(function(iPlayer)
	local iEraRevoltModifier = 1
	local pPlayerTeam = pColonyOwner:GetTeam()
		if ( pPlayerTeam:GetCurrentEra() == GameInfoTypes["ERA_COLONIAL"] ) then
			local iEraRevoltModifier = iEraRevoltModifier - 1
		elseif ( pPlayerTeam:GetCurrentEra() == GameInfoTypes["ERA_INDUSTRIAL"] ) then
			local iEraRevoltModifier = iEraRevoltModifier + 4
		elseif ( pPlayerTeam:GetCurrentEra() == GameInfoTypes["ERA_MODERN"] ) then
			local iEraRevoltModifier = iEraRevoltModifier + 9
		elseif ( pPlayerTeam:GetCurrentEra() == GameInfoTypes["ERA_ATOMIC"] ) then
			local iEraRevoltModifier = iEraRevoltModifier + 14
		elseif ( pPlayerTeam:GetCurrentEra() == GameInfoTypes["ERA_INFORMATION"] ) then
			local iEraRevoltModifier = iEraRevoltModifier + 19                                     
		else
			return false
		end
		local iHandicapRevoltModifier = (4 * Game.GetHandicapType())   
		local iExpansionModifier = (iTimesGrowth() * 2)
		local iColonyHappinessModifier = ConvertColonyHappinessForRevolt() -- max: +17 min  -17
		local iGameSpeedModifier = 1
			if Game.GetGameSpeedType() == 0 then 
				iGameSpeedModifier = 1
			end
			elseif  Game.GetGameSpeedType() == 1 then 
				iGameSpeedModifier = 0.66
			end
			elseif  Game.GetGameSpeedType() == 2 then 
				iGameSpeedModifier = 0.44
			end
			elseif  Game.GetGameSpeedType() == 3 then 
				iGameSpeedModifier = 0.22
			end
		local iColonyRevoltPoints = iEraRevoltModifier + iHandicapRevoltModifier + iExpansionModifier - iColonyHappinessModifier * iGameSpeedModifier  -- max 73 % per turn; min -17 % per turn
		if iColonyHappiness > 0 then 
			return false
		end
		elseif iColonyHappiness < 0 then
		local iPublicOrderForRevolt = pAreaPlot:GetUnitPower(iColonyOwner)
		local iRevoltedUnitsPower = GetRevoltedUnitsPower()
			if math.random(-100, 100) < iColonyRevoltPoints and not iColonyRevoltPoints < 40 and not (iRevoltedUnitsPower * 1.5) < PublicOrderForRevolt then
			local pPlayer = Players[playerID]
				local rebelID = nil
					if not rebelID then
						if #freeSlots > 0 then
							rebelID = freeSlots[1]
							DeclarePermanentWar(rebelID, playerID)
								local freePlots = {}
								local pColonyPlot = Plot:At(iColonyPlotX, iColonyPlotY)
								local plotNumUnits = plot:GetNumUnits()
									if not (plot:IsWater()) and not (plotNumUnits > 3) then
										local iRadius = iTimesGrowth + 2			
										for pAreaPlot in PlotAreaSpiralIterator(pColonyPlot, iRadius, SECTOR_NORTH, DIRECTION_ANTICLOCK, DIRECTION_INWARDS, CENTRE_INCLUDE) do
											print(pAreaPlot:GetX(), pAreaPlot:GetY()) 
											table.insert(freePlots, pAreaPlot)
											end
										end
									Shuffle(freePlots)
									for n, plot in pairs(freePlots) do
										local freeUnitSettler = RebelUnitsToSpawnSettler()
										local freeUnitPrince = RebelUnitsToSpawnPrince()
										local freeUnitEmperor = RebelUnitsToSpawnEmperor() 
										if Game.GetHandicapType() == 0 then
											Player[rebelID]:InitUnit(freeUnitSettler, pAreaPlot:GetX(), pAreaPlot:GetY())
										if Game.GetHandicapType() == 1 then
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlot:GetY() 
										if Game.GetHandicapType() == 2 then
											Player[rebelID]:InitUnit(freeUnitSettler, pAreaPlot:GetX(), pAreaPlot:GetY())
											Player[rebelID]:InitUnit(freeUnitSettler, pAreaPlot:GetX(), pAreaPlot:GetY())
										if Game.GetHandicapType() == 3 then
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlot:GetY())
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlot:GetY())
										if Game.GetHandicapType() == 4 then
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlot:GetY())
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlot:GetY())
											Player[rebelID]:InitUnit(freeUnitSettler, pAreaPlot:GetX(), pAreaPlot:GetY())
										if Game.GetHandicapType() == 5 then
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlot:GetY())
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlot:GetY())
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlot:GetY())
										if Game.GetHandicapType() == 6 then
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlot:GetY())
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlot:GetY())
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlot:GetY())	
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlot:GetY())
										if Game.GetHandicapType() == 7 then
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlot:GetY())
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlot:GetY())
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlot:GetY())	
											Player[rebelID]:InitUnit(freeUnitEmperor, pAreaPlot:GetX(), pAreaPlot:GetY())
											Player[rebelID]:InitUnit(freeUnitPrince, pAreaPlot:GetX(), pAreaPlot:GetY())
										else return false end
									end
								else return false end
							else return false end
					else return false end
				else return false end
			else return false end
	end
end);

ColoniesFunctions.lua

Code:
-- ColoniesMain.lua
-- Author: Genghis.Khan
-- Special Thanks: lua-users.org
-- Date Created: 05-07-2013 17:19
------------------------------------------------------------------------------------

-- include functions

include("ColoniesMain.lua")
include("ColoniesDefines.lua")
-- end include 

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

print("Hope this file is being loaded")

function PlotAreaSpiralIterator(pPlot, r, sector, anticlock, inwards, centre) -- by whoward69
  local next = coroutine.create(function ()
    if (centre and not inwards) then
      coroutine.yield(pPlot)
    end

    if (inwards) then
      for i=r, 1, -1 do
        for pEdgePlot in PlotRingIterator(pPlot, i, sector, anticlock) do
          coroutine.yield(pEdgePlot)
        end
      end
    else
      for i=1, r, 1 do
        for pEdgePlot in PlotRingIterator(pPlot, i, sector, anticlock) do
          coroutine.yield(pEdgePlot)
        end
      end
    end

    if (centre and inwards) then
      coroutine.yield(pPlot)
    end

    return nil
  end)

  -- This function returns the next plot in the sequence
  return function ()
    local success, pAreaPlot = coroutine.resume(next)
    return success and pAreaPlot or nil
  end
end

function RebelUnitsToSpawnSettler()
 
		if teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
				return GameInfo.Units.UNIT_GREAT_WAR_INFANTRY.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
				return GameInfo.Units.UNIT_RIFLEMAN.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID ) then
				return GameInfo.Units.UNIT_MUSKETMAN.ID 
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
				return GameInfo.Units.UNIT_PIKEMAN.ID
		elseif    teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
				return GameInfo.Units.UNIT_SPEARMEN.ID
		else    
				return GameInfo.Units.UNIT_WARRIOR.ID
		end
end


function RebelUnitsToSpawnPrince()
 
		if teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
				return GameInfo.Units.UNIT_INFANTRY.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
				return GameInfo.Units.UNIT_GREAT_WAR_INFANTRY.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID ) then
				return GameInfo.Units.UNIT_RIFLEMAN.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
				return GameInfo.Units.UNIT_MUSKETMAN.ID 
		elseif    teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
				return GameInfo.Units.UNIT_PIKEMAN.ID
		else    
				return GameInfo.Units.UNIT_SPEARMEN.ID
		end
end

function RebelUnitsToSpawnEmperor()

		if teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
				return GameInfo.Units.UNIT_MECHANIZED_INFANTRY.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
				return GameInfo.Units.UNIT_INFANTRY.ID
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID ) then
				return GameInfo.Units.UNIT_GREAT_WAR_INFANTRY.ID	
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
				return GameInfo.Units.UNIT_RIFLEMAN.ID	
		elseif    teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
				return GameInfo.Units.UNIT_MUSKETMAN.ID 	
		else    
				return GameInfo.Units.UNIT_PIKEMAN.ID
		end
end

function ReserveCS() -- by Gedemon

	local bDebug = true

	Dprint ("------------------ ", bDebug)
	Dprint ("Initializing City-States... ", bDebug)

	local numCS = modUserData.GetValue("NumMinorCivs")
	
	Dprint ("  - Number of CS required by the player = " .. numCS, bDebug)

	local loadedCS = {}
	for playerID = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS - 1 do
		local player = Players[playerID]
		local minorCivID = player:GetMinorCivType()
		-- Does this civ exist ?
		if minorCivID ~= -1 then
			table.insert(loadedCS, playerID)
		end
	end
	
	Dprint ("  - Number of active CS in game = " .. #loadedCS, bDebug)

	local reservedCS = {}
	if RESERVED_CITY_STATES > #loadedCS then
		Dprint ("  - WARNING : Loaded CS < RESERVED_CITY_STATES ")
	elseif numCS + RESERVED_CITY_STATES > #loadedCS then
		Dprint ("  - Not enough CS active for all request, keeping " .. #loadedCS - RESERVED_CITY_STATES .. " alive..." , bDebug)
		for i = #loadedCS - RESERVED_CITY_STATES, #loadedCS do
			local playerID = loadedCS[i]
			RemoveCiv (playerID)
			reservedCS[playerID] = { Action = nil, Type = nil, Reference = nil}
		end
	else
		Dprint ("  - Keeping " .. numCS .. " alive..." , bDebug)
		for i = numCS + 1, #loadedCS do
			local playerID = loadedCS[i]
			RemoveCiv (playerID)
			reservedCS[playerID] = { Action = nil, Type = nil, Reference = nil}
		end
	end
	SaveData( "ReservedCS", reservedCS )
end

function Shuffle(t) -- by Gedemon
  local n = #t
 
  while n >= 2 do
    -- n is now the last pertinent index
    local k = math.random(n) -- 1 <= k <= n
    -- Quick swap
    t[n], t[k] = t[k], t[n]
    n = n - 1
  end
 
  return t
end

function TimesGrowth() -- possible Bugs
	if iColonyGrowthRequired == 50 then
		local iTimesGrowth = 0
		return iTimesGrowth
	end
	elseif iColonyGrowthRequired == 250 then
		local iTimesGrowth = 1
		return iTimesGrowth
	end
	elseif iColonyGrowthRequired == 500  then
		local iTimesGrowth = 2 
		return iTimesGrowth
	end
	elseif iColonyGrowthRequired == 750  then
		local iTimesGrowth = 3
		return iTimesGrowth
	end
	elseif iColonyGrowthRequired > 750
		local iTimesGrowth = 4
		return iTimesGrowth
	end	
end

function ConvertColonyHappinessForRevolt()
	local iColonyHappinessForRevolt = (iColonyHappiness * 0.5)
		if iColonyHappinessForRevolt > 17 then
			iColonyHappinessForRevolt = 17
			return iColonyHappinessForRevolt
		end
		elseif iColonyHappiness < -17 then
			iColonyHappinessForRevolt = -17
			return iColonyHappinessForRevolt
		end
		else
			return iColonyHappinessForRevolt
		end
	end
end
	
function GetRevoltedUnitsPower()
local iRevoltedUnitsPower = 1
	if Game.GetHandicapType() == 0 then
		if teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 50	
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 34	
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID )
			iRevoltedUnitsPower = iRevoltedUnitsPower + 24	
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 16
		return iRevoltedUnitsPower end	
		elseif  teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 11
		return iRevoltedUnitsPower end	
	end
	elseif Game.GetHandicapType() == 1 then
		if teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 70	
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 50
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID )
			iRevoltedUnitsPower = iRevoltedUnitsPower + 34	
		return iRevoltedUnitsPower end
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 24
		return iRevoltedUnitsPower end	
		elseif  teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 16
		return iRevoltedUnitsPower end	
	end
	elseif Game.GetHandicapType() == 2 then
		if teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 100
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 68
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID )
			iRevoltedUnitsPower = iRevoltedUnitsPower + 48
		return iRevoltedUnitsPower end
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 32
		return iRevoltedUnitsPower end	
		elseif  teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 22
		return iRevoltedUnitsPower end	
	end
	elseif Game.GetHandicapType() == 3 then
		if teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 140
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 100
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID )
			iRevoltedUnitsPower = iRevoltedUnitsPower + 68
		return iRevoltedUnitsPower end
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 48
		return iRevoltedUnitsPower end	
		elseif  teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 32
		return iRevoltedUnitsPower end	
	end
	elseif Game.GetHandicapType() == 4 then
		if teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 190
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 134
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID )
			iRevoltedUnitsPower = iRevoltedUnitsPower + 92
		return iRevoltedUnitsPower end
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 62
		return iRevoltedUnitsPower end	
		elseif  teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 43
		return iRevoltedUnitsPower end	
	end
	elseif Game.GetHandicapType() == 5 then
		if teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 250
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 170
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID )
			iRevoltedUnitsPower = iRevoltedUnitsPower + 118
		return iRevoltedUnitsPower end
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 92
		return iRevoltedUnitsPower end	
		elseif  teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 64
		return iRevoltedUnitsPower end	
	end
	elseif Game.GetHandicapType() == 6 then
		if teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 340
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 240
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID )
			iRevoltedUnitsPower = iRevoltedUnitsPower + 168
		return iRevoltedUnitsPower end
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 116
		return iRevoltedUnitsPower end	
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 88
		return iRevoltedUnitsPower end	
	end
	elseif Game.GetHandicapType() == 7 then
		if teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 430
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 330
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID )
			iRevoltedUnitsPower = iRevoltedUnitsPower + 234	
		return iRevoltedUnitsPower end
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 150
		return iRevoltedUnitsPower end	
		elseif teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
			iRevoltedUnitsPower = iRevoltedUnitsPower + 106
		return iRevoltedUnitsPower end	
	end
	else	
		return false
	end
end

ColoniesDefines.lua

Code:
-- ColoniesDefines.lua
-- Author: Genghis.Khan
-- Special Thanks: lua-users.org
-- Date Created: 5/7/2013 11:22:48 AM
--------------------------------------------------------------


include("ColoniesMain.lua")
include("ColoniesFunctions.lua")

print("Is this being loaded")


RESERVED_CITY_STATES = 10 
SECTOR_NORTH = 1
SECTOR_NORTHEAST = 2
SECTOR_SOUTHEAST = 3
SECTOR_SOUTH = 4
SECTOR_SOUTHWEST = 5
SECTOR_NORTHWEST = 6

DIRECTION_CLOCKWISE = false
DIRECTION_ANTICLOCKWISE = true

DIRECTION_OUTWARDS = false
DIRECTION_INWARDS = true

CENTRE_INCLUDE = true
CENTRE_EXCLUDE = false
 
whoward I saw the thread and I have already sucessfully used it some million times but those two points are confusing me...

whoward69 said:
Does this file contain methods registered by events within the file, or methods that are then executed directly during game startup?
VFS: False
Requires an InGameUIAddin entry
Does this file contain methods used by other Lua files and is included into those other Lua files?
VFS: True

Especifically about ColoniesMain.lua: you said the file required an InGameUIAddin earlier in this thread but it contains variables (local ones) that are used by ColoniesFunctions.lua... And with ColoniesMain.lua VFS = "false" and InGameUIAddin Entry the Mod does not work... Maybe it's another bug, since it is one of the first tests I ran, and none of them were yet sucessfull.
 
Error in ColoniesMain (even if no output from print statements):

Code:
[170420.750] Syntax Error: C:\Users\Alex\Documents\My Games\Sid Meier's Civilization 5\MODS\Mods\UnOfficial Expansion Rise and Fall of Empires (v 13)\Colonies\Lua\ColoniesMain.lua:21: function arguments expected near 'local'
[170420.750] Runtime Error: Error loading C:\Users\Alex\Documents\My Games\Sid Meier's Civilization 5\MODS\Mods\UnOfficial Expansion Rise and Fall of Empires (v 13)\Colonies\Lua\ColoniesMain.lua.


Maybe this error was the issue.

Error:

Code:
local iColonyPlotX = pPlot:GetX
local iColonyPlotY = pPlot:GetY

Corrected Version:

Code:
local iColonyPlotX = pPlot:GetX()
local iColonyPlotY = pPlot:GetY()

Hope my code isn't full of bugs like this
 
Back
Top Bottom