Meeting a City-State

bane_

Howardianism High-Priest
Joined
Nov 27, 2013
Messages
1,559
I've tried with the args being Player ID and Team ID, yet nothing works.
There is no error, it just doesn't go on.

From experience derived from earlier versions of this code, the problem seems to be IsMinorCiv, but I have no idea why and research proved fruitless.


Code:
function PlagueMet(iPlayer, iPlayerMet)
	--local pTeam = Teams[iTeam]
	--local pTeamMet = Teams[iTeamMet]
	local pPlayer = Players[iPlayer]
	local pPlayerMet = Players[iPlayerMet]
	if pPlayer:GetCivilizationType() == ePlagueLords then
		print("[PlagueMet] Started.")
		print("[PlagueMet] Player met is a City-State? " ..tostring(pPlayerMet:IsMinorCiv()))
		if pPlayerMet:IsMinorCiv() then
			print("[PlagueMet] Plaguelords met a Minor Civ.")
			if WBCTable.iTimesMetCS > 0 then
				print("[PlagueMet] Number of times met a Minor Civ is below 3.")
				local iModifier = WBCCheckMultiplierGS()
				pPlayerMet:ChangeMinorCivFriendshipWithMajor(iPlayer, (105 * iModifier))
				WBCTable.iTimesMetCS = WBCTable.iTimesMetCS - 1
			else
				print("[PlagueMet] First part of UA is DONE.")
				GameEvents.TeamMeet.Remove(PlagueMet)
			end
		end
		print("[PlagueMet] Ended.")
	end
end
 
Is this the whole code? I don't see an event hook or anywhere else where the function is called...

EDIT: Woah! I just noticed this is post #2500! That's a nice round number. :D
 
The parameters are indeed teams, not players. How were you getting player IDs from teams? Were you assuming they were the leader with GetLeaderID() or were you looping through the players and doing Player.GetTeam?
 
Firaxis used nearly an identical method to the blue highlight in one of their scenario "TurnsRemaining.lua" to translate between TeamID and PlayerID
Spoiler :
Code:
function AddTechsUponEraAdvance(teamId, eEra)
	print("The Function TeamSetEraListener is running")
	print("teamId = " .. teamId)
	print("eEra = " .. eEra)
	local pTeam = Teams[teamId]
	if pTeam:IsBarbarian() or pTeam:IsMinorCiv() then return end
	if not pTeam:IsAlive() then return end
	local iTechToSet = "NONE"
	if eEra == 1 then
		iTechToSet = DummyTechsList.gDummyTechClassical
	elseif eEra == 2 then
		iTechToSet = DummyTechsList.gDummyTechMedieval
	elseif eEra == 3 then
		iTechToSet = DummyTechsList.gDummyTechRenaissance
	elseif eEra == 4 then
		iTechToSet = DummyTechsList.gDummyTechIndustrial
	elseif eEra == 5 then
		iTechToSet = DummyTechsList.gDummyTechModern
	elseif eEra == 6 then
		iTechToSet = DummyTechsList.gDummyTechPostModern
	elseif eEra == 7 then
		iTechToSet = DummyTechsList.gDummyTechFuture
	end
	if iTechToSet ~= "NONE" then
		pTeam:SetHasTech(iTechToSet, true)
	end
	[color="blue"]for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
		if (Players[iPlayer] ~= nil) then
			if (Players[iPlayer]:GetTeam() == teamId) then
				local pPlayer = Players[iPlayer]
				if not pPlayer:IsHuman() then
					--do AI building sets
					PrintDebug("On Era Advancement running the AI Building-Sets in AI Player Cities for player # " .. iPlayer)
					for pCity in pPlayer:Cities() do
						for k,v in pairs(FreeEraBuildingsAI[eEra]) do
							if pCity:IsHasBuilding(k) then
								pCity:SetNumRealBuilding(v, 1)
								PrintDebug("Building " .. v .. " (" .. GameInfo.Buildings[v].Type .. ") was added to the city of " .. pCity:GetName() .. " for player # " .. iPlayer)
							end
						end
					end
				end
				break
 			end
		end
 	end[/color]
end
GameEvents.TeamSetEra.Add(AddTechsUponEraAdvance)
  1. I threw the "break" into that basic structure, which would probably make the whole thing, er, "break", when someone is using actual teams.
  2. Yes I know I need to de-hard-code and optimize the sorting for the era a bit, especially as this is the bit of my Era Buildings mod which will likely make it incompatible with Pouakai's new Enlightenment Era mod
  3. The Firaxis method may also be a bit too brute-force and non-optimum, but it does seem to be working properly. And no, I haven't decided what I am going to do about the whole "there can actually be teams" issue.
 
I tried the loop.
Spoiler :
Code:
function PlagueMet(iTeam, iTeamMet)
	local pTeam = Teams[iTeam]
	local pTeamMet = Teams[iTeamMet]
	--local pPlayer = Players[pTeam:GetLeaderID()]
	local pPlayerMet = Players[pTeamMet:GetLeaderID()]
	print("[PlagueMet] Some players just met.")
	for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
		print("[PlagueMet] Checking...")
		local pPlayer = Players[iPlayer]
		if pPlayer:GetTeam() == iTeam then
			print("[PlagueMet] pPlayer is meeting Civ.")
			if pPlayer:GetCivilizationType() == ePlagueLords then
				--print("[PlagueMet] Started.")
				print("[PlagueMet] Player met is a City-State? " ..tostring(pPlayerMet:IsMinorCiv()))
				if pPlayerMet:IsMinorCiv() then
					print("[PlagueMet] Plaguelords met a Minor Civ.")
					if WBCTable.iTimesMetCS > 0 then
						print("[PlagueMet] Number of times met a Minor Civ is below 3.")
						local iModifier = WBCCheckMultiplierGS()
						pPlayerMet:ChangeMinorCivFriendshipWithMajor(iPlayer, (105 * iModifier))
						WBCTable.iTimesMetCS = WBCTable.iTimesMetCS - 1
					else
						print("[PlagueMet] First part of UA is DONE.")
						GameEvents.TeamMeet.Remove(PlagueMet)
					end
					break
				end
				print("[PlagueMet] Ended.")
			end
		end
	end
end

The log:
Spoiler :
[15743.293] WBCUtilsIII: [PlagueMet] Some players just met.
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...
[15743.293] WBCUtilsIII: [PlagueMet] Checking...


I looked at some other codes, JFD uses at least twice - Switzerland and Belgium - the method I was using (with GetLeaderID()) and it works.
What am I doing wrong, Lord, what? :cry:


EDIT: It seems to me that the issue is with the Team check, but why? Both are integers, so I'm not comparing apples to oranges; at least ONE was supposed to click and go on, but none? That's weird.
 
22 "checking ..."s should be a hint that the code is incompatible with the subject line "Meeting a City-State"

22 is the default max number of civs in the game. All city states start above this number ...

... ummmm ...

... perhaps
Code:
for iPlayer = 0, [B][COLOR="Red"]GameDefines.MAX_MAJOR_CIVS[/COLOR][/B] - 1, 1 do
is the cause of the problem
 
GetLeaderID would probably not work with some scenarios (Teams).

Anyway, you have incorrectly assumed that major player's team will be always a first value. Loop for 22 is correct (since you are looking for certain major civ type), but OR statement (equal to second team) is needed. Second function (you will be calling either (iPlayer, team1) or (iPlayer, team2)) and it is done.

For future, learn to use prints... seriously, the initial values are something you should print at once.

Good luck.
 
oh. Sorry, Bane_. I just figured you would naturally see the MAX_MAJOR_CIVS and change that part to the MAX_CIV_PLAYERS for your needs.

I didn't need to let my version of the loop go through city-states because city-states never get to have the buildings I am interested in within my mod.

For future, learn to use prints... seriously, the initial values are something you should print at once.
:agree:
Has saved me endless hours of hair-pulling and :wallbash::hammer2:.

Especially when you are expecting a method or function to be passing you an integer (for example), and you instead are being given "Horseradish" by that method or function for a variable you have called iTeam.
 
oh. Sorry, Bane_. I just figured you would naturally see the MAX_MAJOR_CIVS and change that part to the MAX_CIV_PLAYERS for your needs.

No need to apologize, it's not your fault. And I did not need to change it anyway, just add another check for the second argument. :D
I put a LOT of prints, but not the most fundamentals ones, apparently. :lol::lol:
 
Back
Top Bottom