Prevent war declaration and get declarer/declaree

Lort Krassbeter

Chieftain
Joined
Mar 8, 2015
Messages
17
Location
Beyond Earth
Hi,
so am trying to prevent a player from declaring war between turns and remember the declarer/declaree to declare war automatically at the start of the next turn.
This is what I tried:
Code:
local declareWarNextTurn = {}
function OnCanDeclareWar(t1, t2)
        declareWarNextTurn[t1] = t2
	return false
end
GameEvents.CanDeclareWar.Add(OnCanDeclareWar)

function OnActivePlayerTurnStart()
	for t1, t2 in pairs(declareWarNextTurn)	do
		if t1==Players[Game.GetActivePlayer()]:GetTeam() then
			Network.SendChangeWar(t2, true)
                end
	end
end
Events.ActivePlayerTurnStart.Add(OnActivePlayerTurnStart)
However, the event GameEvents.CanDeclareWar does not work the way I thought.
Instead of fireing when someone tries to declare war it fires multiple times on the beginning of the turn with all possible combinations of players that have already met.
So is there any other event I could use to do this? If not I also had another idea: Since I only care about human players in a game I could replace the popup lua file for the war declaration popup with my own version that remembers the user but declares war on the beginning of the next turn. But so far I have only been updating XML files by adding an action to the mod. How can I achieve an update/replacement of a lua game file?

Thanks in advance :)
 
Why don't you try Events.WarStateChanged?

As for your last question, it's easy to replace a base game Lua file. Just give it the same name, add it to your mod, and set it VFS=True. Leave it all lowercase for the sake of Linux users.
 
The problem with Events.WarStateChanged is, that it does not allow you to cancel the event by returning false. But I also found, that GameEvents.CanDeclareWar does not prevent the human player from declaring war even when returning false in any case. (Is perhaps only for AI?)
So I will try with replacing the war declaration popups, thanks for your help!
 
CanDeclareWar is only used by the AI.

Your code in post #1 doesn't take into account a team declaring war on more than one team per turn.

declareWarNextTurn[t1] = t2

really needs to be something like

declareWarNextTurn[t1][t2] = true

(with associated code changes to support the 2d array)
 
Top Bottom