Help needed with Civilization's Trait

MrTubbz

Chieftain
Joined
Jun 16, 2016
Messages
6
Location
West Yorkshire, England
So I already posted about this in another forum, but I know now that I'll need to use Lua so I thought it'd be more useful for me to post here.

Basically, I want my civilization have the trait of:

Dawes Plan:
After every Declaration of Friendship, the Weimar will receive 300 :c5gold: and +3 :c5gold: per turn. The other civ will also receive +4 :c5gold: per turn

As I'm new to modding (and a complete newbie to Lua), I'd probably need a lot of help to get this working. I was alos wondering if it would be possible to scale this with different game speeds, so you get less gold on Quick and more on Epic for example.

Thanks for any help in advance!
 
Code:
local iWeimarCiv = GameInfoTypes.CIVILIZATION_WEIMAR
local iWeimarDoF = 0
local tCivsInGame = {}
local iWeimarPlayer
local pWeimarPlayer
local iGoldPerTurnModifier = GameInfo.GameSpeeds[Game.GetGameSpeedType()].GoldPercent
local iWeimarGoldPerTurnForDoF = math.floor(3 * iGoldPerTurnModifier / 100)
local iGoldPerTurnForDoFWithWeimar =  math.floor(4 * iGoldPerTurnModifier / 100)
local iWeimarGoldForNewDoF = math.floor(300 * iGoldPerTurnModifier / 100)

local function OnPlayerDoTurn(iPlayer)
	if iPlayer == iWeimarPlayer then
		pWeimarPlayer:ChangeGold(iWeimarDoF * iWeimarGoldPerTurnForDoF)
	else
		local pPlayer = tCivsInGame[iPlayer]
		local iDoFCounter = pPlayer:GetDoFCounter(iWeimarPlayer)
		if iDoFCounter == 1 then
			pWeimarPlayer:ChangeGold(iWeimarGoldForNewDoF )
			pPlayer:ChangeGold(iGoldPerTurnForDoFWithWeimar)
			iWeimarDoF = iWeimarDoF + 1
		elseif iDoFCounter > 1 then
			pPlayer:ChangeGold(iGoldPerTurnForDoFWithWeimar)
		end
	end
end

for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
	local pPlayer = Players[iPlayer]
	if pPlayer:IsAlive() then
		if pPlayer:GetCivilizationType() == iWeimarCiv then
			iWeimarPlayer = iPlayer
			pWeimarPlayer = pPlayer
			GameEvents.PlayerDoTurn.Add ( OnPlayerDoTurn )
		else
			tCivsInGame[iPlayer] = pPlayer
		end
	end
end

for iPlayer, pPlayer in pairs(tCivsInGame) do
	if pPlayer:IsDoF(iWeimarPlayer) then
		iWeimarDoF = iWeimarDoF + 1
	end
end
 
Code:
local iWeimarCiv = GameInfoTypes.CIVILIZATION_WEIMAR
local iWeimarDoF = 0
local tCivsInGame = {}
local iWeimarPlayer
local pWeimarPlayer
local iGoldPerTurnModifier = GameInfo.GameSpeeds[Game.GetGameSpeedType()].GoldPercent
local iWeimarGoldPerTurnForDoF = math.floor(3 * iGoldPerTurnModifier / 100)
local iGoldPerTurnForDoFWithWeimar =  math.floor(4 * iGoldPerTurnModifier / 100)
local iWeimarGoldForNewDoF = math.floor(300 * iGoldPerTurnModifier / 100)

local function OnPlayerDoTurn(iPlayer)
	if iPlayer == iWeimarPlayer then
		pWeimarPlayer:ChangeGold(iWeimarDoF * iWeimarGoldPerTurnForDoF)
	else
		local pPlayer = tCivsInGame[iPlayer]
		local iDoFCounter = pPlayer:GetDoFCounter(iWeimarPlayer)
		if iDoFCounter == 1 then
			pWeimarPlayer:ChangeGold(iWeimarGoldForNewDoF )
			pPlayer:ChangeGold(iGoldPerTurnForDoFWithWeimar)
			iWeimarDoF = iWeimarDoF + 1
		elseif iDoFCounter > 1 then
			pPlayer:ChangeGold(iGoldPerTurnForDoFWithWeimar)
		end
	end
end

for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
	local pPlayer = Players[iPlayer]
	if pPlayer:IsAlive() then
		if pPlayer:GetCivilizationType() == iWeimarCiv then
			iWeimarPlayer = iPlayer
			pWeimarPlayer = pPlayer
			GameEvents.PlayerDoTurn.Add ( OnPlayerDoTurn )
		else
			tCivsInGame[iPlayer] = pPlayer
		end
	end
end

for iPlayer, pPlayer in pairs(tCivsInGame) do
	if pPlayer:IsDoF(iWeimarPlayer) then
		iWeimarDoF = iWeimarDoF + 1
	end
end

Wow, thank you so much! I'll be sure to try this out as soon as possible.
 
Back
Top Bottom