Muscogee Confederacy

:goodjob: New units are way better than reskins, so I'm stoked!:D

As for the free mico's, did you look at patria grande's Tiwanaku civ? The UA gives a free shrine in your first 4 cities, just replace the shrine with a dummy building that gives a free micro!
(I have said dummy building way to much in this thread:lol:)
Looking forward to this civil!
 
Code:
-- Trait
-- Author: Firebug
-- DateCreated: 3/2/2015 7:52:10 PM
--------------------------------------------------------------

local civilisationID 			= GameInfoTypes["CIVILIZATION_MUSCOGEE"]
local IsMuscogeeCivActive 		= Muscogee_IsCivilisationActive(civilisationID)
local IsMuscogeeActivePlayer 	= activePlayer:GetCivilizationType() == civilisationID
local mathMin 					= math.min

----------------------------------------------------------------------------------------------------------------------------
-- Firebug_GetNumTradeRoutes
----------------------------------------------------------------------------------------------------------------------------
function Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city)
	local player = Players[playerID]
	local tradeRoutes = player:GetTradeRoutes()
	local numTradeRoutes = 0
	for i, v in ipairs(tradeRoutes) do
		local originatingCity = v.FromCity
		if originatingCity:GetID() == city:GetID() then
			numTradeRoutes = numTradeRoutes + 1
		end
	end
	
	return numTradeRoutes
end

----------------------------------------------------------------------------------------------------------------------------
-- Firebug_MicoScience
----------------------------------------------------------------------------------------------------------------------------

local buildingMuscogeeScienceID 	= GameInfoTypes["BUILDING_MICO_SCIENCE"]
		
function Muscogee_MicoScience(playerID)
    print("Muscogee trait is active")
	local player = Players[playerID]
	if (player:IsEverAlive() and player:GetCivilizationType() == civilisationID) then
				local numMicoScience = mathMin(Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city), 3)
				city:SetNumRealBuilding(buildingMuscogeeScienceID, numMicoScience)
			else
				if city:IsHasBuilding(buildingMuscogeeScienceID) then
					city:SetNumRealBuilding(buildingMuscogeeScienceID, 0)
				end
			end
		end
	end
end

function Muscogee_MicoScienceCityView()
local player = Players[playerID]
	if (player:IsEverAlive() and player:GetCivilizationType() == civilisationID) then
		for city in player:Cities() do
			local numMicoScience = mathMin(Muscogee_GetNumTradeRoutesLeavingThisCity(activePlayerID, city), 3)
			city:SetNumRealBuilding(buildingMuscogeeScienceID, numMicoScience)
		else
			if city:IsHasBuilding(buildingMuscogeeScienceID) then
				city:SetNumRealBuilding(buildingMuscogeeScienceID, 0)
			end
		end
	end
end

if IsMuscogeeCivActive then
	GameEvents.PlayerDoTurn.Add(Muscogee_MicoScience)
	if IsMuscogeeActivePlayer then
		Events.SerialEventEnterCityScreen.Add(Muscogee_MicoScienceCityView)
	end
end

----------------------------------------------------------------------------------------------------------------------------
-- Firebug_MicoPromotion
----------------------------------------------------------------------------------------------------------------------------

local unitMicoID = GameInfoTypes["UNIT_MICO"]
local unitPromotionMicoCombatID = GameInfoTypes["PROMOTION_MICO_COMBAT"]
local unitCombatMeleeID = GameInfoTypes["UNITCOMBAT_MELEE"]
local unitCombatRangedID = GameInfoTypes["UNITCOMBAT_RANGED"]

function MicoBoostMelee(playerID)
	local player = Players[playerID]
	local micoNearby = false
	for unit in player:Units() do
		if (unit:GetUnitCombatType() == unitCombatMeleeID and not (unit:IsEmbarked())) then
			for mico in player:Units() do
				if mico:GetUnitType() == unitMicoID then
					if Map.PlotDistance(unit:GetX(), unit:GetY(), mico:GetX(), mico:GetY()) < 3 then
						micoNearby = true
					end
				end
			end
			
			if micoNearby then
				if not unit:IsHasPromotion(unitPromotionMicoCombatID) then
					unit:SetHasPromotion(unitPromotionMicoCombatID, true)
				end
			else
				if unit:IsHasPromotion(unitPromotionMicoCombatID) then
					unit:SetHasPromotion(unitPromotionMicoCombatID, false)
				end
			end
			
		else
			if unit:IsHasPromotion(unitPromotionMicoCombatID) then
				unit:SetHasPromotion(unitPromotionMicoCombatID, false)
			end
		end
	end
end
GameEvents.UnitSetXY.Add(MicoBoostMelee) 
GameEvents.PlayerDoTurn.Add(MicoBoostMelee)

function MicoBoostRanged(playerID)
	local player = Players[playerID]
	local micoNearby = false
	for unit in player:Units() do
		if (unit:GetUnitCombatType() == unitCombatRangedID and not (unit:IsEmbarked())) then
			for mico in player:Units() do
				if mico:GetUnitType() == unitMicoID then
					if Map.PlotDistance(unit:GetX(), unit:GetY(), mico:GetX(), mico:GetY()) < 3 then
						micoNearby = true
					end
				end
			end
			
			if micoNearby then
				if not unit:IsHasPromotion(unitPromotionMicoCombatID) then
					unit:SetHasPromotion(unitPromotionMicoCombatID, true)
				end
			else
				if unit:IsHasPromotion(unitPromotionMicoCombatID) then
					unit:SetHasPromotion(unitPromotionMicoCombatID, false)
				end
			end
			
		else
			if unit:IsHasPromotion(unitPromotionMicoCombatID) then
				unit:SetHasPromotion(unitPromotionMicoCombatID, false)
			end
		end
	end
end
GameEvents.UnitSetXY.Add(MicoBoostRanged) 
GameEvents.PlayerDoTurn.Add(MicoBoostRanged)

So uh, this is my code so far. Trying to find the issues and errors that i've made.
and this is the LUA log's... log.

Code:
[206732.671] Syntax Error: C:\Users\Rich\Documents\My Games\Sid Meier's Civilization 5\MODS\Firebug's The Muscogee Confederacy (v 1)\LUA/Trait.lua:46: '<eof>' expected near 'end'
[206732.671] Runtime Error: Error loading C:\Users\Rich\Documents\My Games\Sid Meier's Civilization 5\MODS\Firebug's The Muscogee Confederacy (v 1)\LUA/Trait.lua.
 
At a quick glance I think there's something wrong in your MicoScienceCityView function. I'll take a look at it later tonight and report back.
 
Right, how's this?

Oh. Oops, should of told you. That looks great but you took a while and i wanted the icons done.
do DJSHenninger did that one too.
Sorry for wasting your time.
 
I'm just waiting on some feedback for my terrible LUA coding.

Any idea for Events and Decisions and music?
 
First, the error in the log is this:
Code:
function Muscogee_MicoScience(playerID)
    print("Muscogee trait is active")
	local player = Players[playerID]
	if (player:IsEverAlive() and player:GetCivilizationType() == civilisationID) then
				local numMicoScience = mathMin(Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city), 3)
				city:SetNumRealBuilding(buildingMuscogeeScienceID, numMicoScience)
			else
				if city:IsHasBuilding(buildingMuscogeeScienceID) then
					city:SetNumRealBuilding(buildingMuscogeeScienceID, 0)
				end
			end
		end
[COLOR="Red"]	end
end[/COLOR]
You simply had too many end statements.

BUT, I think there might be some other issues. Now, mind you, I haven't read through this entire thread, so maybe I don't understand the UA correctly, but is this function supposed to do the following: If a city has a outgoing traderoute, then a dummy building is constructed in that city. If the number of traderoutes increases, the number of the dummy building increases accordingly. But there's a minimum cap of 3 dummy buildings, so actually for 1-3 outgoing traderoute from a city, 3 dummy buildings are constructed, for 4 outgoing traderoutes from a city, 4 dummy buildings are constructed, etc. If there is no outgoing traderoutes, then all dummy buildings are deleted. Is this understood correctly?

If that is the case, I think there might be a few issues with the code. You have a function that counts the number of outgoing traderoutes from a specific city
Code:
Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city)
but the Muscogee_MicoScience function doesn't specify which city. I think you're missing a "for city in player:Cities() do" statement as you have in the Muscogee_MicoScienceCityView function. Anyways, try this:

Code:
function Muscogee_MicoScience(playerID)
	local player = Players[playerID]
	if player:IsEverAlive() and player:GetCivilizationType() == civilisationID then	
		print("Muscogee trait is active") -- only print statement if Muscogee is active
		for city in player:Cities() do
			if Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city) < 0 then -- checks if city has outgoing traderoutes
				local numMicoScience = mathMin(Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city), 3)
				city:SetNumRealBuilding(buildingMuscogeeScienceID, numMicoScience)
			else -- if don't think you need the "if city:IsHasBuilding(buildingMuscogeeScienceID) then" statement, since using if.. else.. 
				city:SetNumRealBuilding(buildingMuscogeeScienceID, 0)
			end
		end
	end
end

In the Muscogee_MicoScienceCityView() function, I think there might also be a problem. You have this
Code:
for city in player:Cities() do
			local numMicoScience = mathMin(Muscogee_GetNumTradeRoutesLeavingThisCity(activePlayerID, city), 3)
			city:SetNumRealBuilding(buildingMuscogeeScienceID, numMicoScience)
		else
			if city:IsHasBuilding(buildingMuscogeeScienceID) then
				city:SetNumRealBuilding(buildingMuscogeeScienceID, 0)
			end
		end
I'm not sure, and as said I haven't tested it, but it looks like you're missing an if statement to the else statement. Maybe it should - as in the above function - be something like this:
Code:
function Muscogee_MicoScienceCityView()
local player = Players[playerID]
	if (player:IsEverAlive() and player:GetCivilizationType() == civilisationID) then
		for city in player:Cities() do
			if Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city) < 0 then -- checks if city has outgoing traderoutes
				local numMicoScience = mathMin(Muscogee_GetNumTradeRoutesLeavingThisCity(activePlayerID, city), 3)
				city:SetNumRealBuilding(buildingMuscogeeScienceID, numMicoScience)
			else
				city:SetNumRealBuilding(buildingMuscogeeScienceID, 0)
			end
		end
	end
end

I haven't looked through the rest as I know from experience, that trying to fix everything at once is never a good idea. So focus on these functions first, and then, when they are working correctly, then move on to the next functions (if there are even any errors in them).

Hopefully you can use this. But just beware, I'm not a very skilled modder, like, at all. Still trying to get a hang of lua myself, so I can't guarantee the above changes will do you any good.
 
The code should hopefully be that everytime you send a trade route out of a city a dummy building with +10% science will be created.

I did everything above and now i get this error.

Code:
[298298.203] Runtime Error: C:\Users\Rich\Documents\My Games\Sid Meier's Civilization 5\MODS\Firebug's The Muscogee Confederacy (v 1)\LUA\Trait.lua:10: attempt to call global 'Muscogee_IsCivilisationActive' (a nil value)
 
I've been trying to work what the problem above means and can't work my head around it.
 
Muscogee_IsCivilisationActive is a localised function that is trying to be called but which does not exist. I take it you copy-pasted from my Novgorod mod, but you didn't copy over the JFD_IsCivilisationActive function found at the top of the file. This is Whoward's check to ensure that the civ is in-game before executing any code. Copy that in to resolve that particular error.
 
Muscogee_IsCivilisationActive is a localised function that is trying to be called but which does not exist. I take it you copy-pasted from my Novgorod mod, but you didn't copy over the JFD_IsCivilisationActive function found at the top of the file. This is Whoward's check to ensure that the civ is in-game before executing any code. Copy that in to resolve that particular error.


It's mainly Flanders actually, i read through different mod's LUAs to work out how LUA works because i never like any of the tutorials that are online because its not the way i learn.
I made sure to add IsCivilizationActive. (Atleast, i could swear i stared at it for a good 5 minutes asking myself why it apparently wasn't working) I'll double check now.

Edit: I'd assume by the way that your talking typing that you don't actually care if i borrow some code (i'd assume because all code is the same anyway and can't really different). I'm hoping to eventually stop taking from other people and work it out myself.

EditEdit: I do have
Code:
local IsMuscogeeCivActive 		= Muscogee_IsCivilisationActive(civilisationID)

I'm over complicating things. I've changed the lines of code that would say IsMuscogeeCivActive to
Code:
if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_MUSCOGEE"] and player:IsAlive() then

Wha---- whaaaaaat.
I fix one error and another appears.
Code:
 attempt to index global 'player' (a nil value)

I'm completely redoing the code from scratch. I'm gonna do this eventually.
 
I don't quite get what this error means.
Code:
attempt to index global 'activePlayer' (a nil value)

Since i do have the locals setup for activePlayer.
Code:
local activePlayerID 			= Game.GetActivePlayer()
 
Edit: I'd assume by the way that your talking typing that you don't actually care if i borrow some code (i'd assume because all code is the same anyway and can't really different). I'm hoping to eventually stop taking from other people and work it out myself.[/CODE]

Both Novgorod and Flanders make use of the same kinds of functions that you're after. I just assumed Novgorod as that was newer.

EditEdit: I do have
Code:
local IsMuscogeeCivActive 		= Muscogee_IsCivilisationActive(civilisationID)

Yes, thats the localised function, but the function itself ("Muscogee_IsCivilisationActive(civilisationID)") doesn't exist anywhere as far as I can tell.


I don't quite get what this error means.
Code:
attempt to index global 'activePlayer' (a nil value)

Since i do have the locals setup for activePlayer.
Code:
local activePlayerID 			= Game.GetActivePlayer()

activePlayerID ~= activePlayer :p

activePlayerID is just storing the ID of the active player - you want the player object, which you can retrieve as below.

Code:
local activePlayer = Players[activePlayerID]
 
Should i make it so the Capital ALWAYS starts with deer? because the caravansary replacement is very situational and its making a VERY useful bonus (50% trade range) into a rarer thing.
 
No more LUA errors and the Print appears in the log saying that it worked but the trait just isn't creating 10% science for each trade route sent out.

Have i done anything wrong here?

Code:
----------------------------------------------------------------------------------------------------------------------------
-- Muscogee Trait
----------------------------------------------------------------------------------------------------------------------------		

function Muscogee_MicoScience(playerID)
	print("Muscogee trait is active") -- only print statement if Muscogee is active
	if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_MUSCOGEE"] and player:IsAlive() then
		for city in player:Cities() do
			if Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city) < 0 then -- checks if city has outgoing traderoutes
				local numMicoScience = mathMin(Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city), 3)
				city:SetNumRealBuilding(buildingMuscogeeScienceID, numMicoScience)
			else -- if don't think you need the "if city:IsHasBuilding(buildingMuscogeeScienceID) then" statement, since using if.. else.. 
				city:SetNumRealBuilding(buildingMuscogeeScienceID, 0)
			end
		end
	end
end

function Muscogee_MicoScienceCityView()
	if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_MUSCOGEE"] and player:IsAlive() then
		for city in player:Cities() do
			if Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city) < 0 then -- checks if city has outgoing traderoutes
				local numMicoScience = mathMin(Muscogee_GetNumTradeRoutesLeavingThisCity(activePlayerID, city), 3)
				city:SetNumRealBuilding(buildingMuscogeeScienceID, numMicoScience)
			else
				city:SetNumRealBuilding(buildingMuscogeeScienceID, 0)
			end
		end
	end
end


GameEvents.PlayerDoTurn.Add(MuscogeeTrait)

print("my lua loaded to the end")

------------------------------------------------------------------------------------------------------------------------
-- Muscogee_GetNumTradeRoutesLeavingThisCity
------------------------------------------------------------------------------------------------------------------------
function Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city)
	local player = Players[playerID]
	local tradeRoutes = player:GetTradeRoutes()
	local numTradeRoutes = 0
	for i, v in ipairs(tradeRoutes) do
		local originatingCity = v.FromCity
		if originatingCity:GetID() == city:GetID() then
			numTradeRoutes = numTradeRoutes + 1
		end
	end
	
	return numTradeRoutes
end
 
Should i make it so the Capital ALWAYS starts with deer? because the caravansary replacement is very situational and its making a VERY useful bonus (50% trade range) into a rarer thing.

I think that's definitely a good idea. And it's definitely doable, JFD does it with sheep in Flanders.
 
I think that's definitely a good idea. And it's definitely doable, JFD does it with sheep in Flanders.

Good way of testing if my Lua really does work too. If a Deer is there, its good.

the Lua loads, it says it does. But it just doesn't do anything. And it's confusing me.
 
Good way of testing if my Lua really does work too. If a Deer is there, its good.

the Lua loads, it says it does. But it just doesn't do anything. And it's confusing me.
As mentioned earlier, you'd really be doing yourself and anyone who's helping you a favour by inserting lots of print statements in your code, and then have FireTuner opened while playing. That way you can judge how far the code executes by the print statements.

I also have a similar code in my Nuraghians civ in one of their unique decisions, which you can check out.. And I think Tomatekh has something too in his Sumer civ.

EDIT: just reread my post. Sorry if it came off a bit blunt.
 
LUA hurts my brain.
 
Top Bottom