Lua how to declare war on CS

Is this possible? DeclareWar() doesn't seem to work for Minor Civs.

Could send me script example where it works between Major players?
I have such erro when I use it in my map script:

Runtime Error: [string "Assets\Maps\NOVAL_LIGA_v4_3.lua"]:2179: attempt to call method 'declareWar' (a nil value)
stack traceback:
[string "Assets\Maps\NOVAL_LIGA_v4_3.lua"]:2179: in function 'StartPlotSystem'
[string "Assets\Gameplay\Lua\MapGenerator.lua"]:811: in function <[string "Assets\Gameplay\Lua\MapGenerator.lua"]:775>
[C]: ?
 
Is this possible? DeclareWar() doesn't seem to work for Minor Civs.

admittedly haven't done this in a while but
Code:
playerteam:DeclareWar( otherplayerteam, true )
is a bit of code that worked for me when testing out various war events. major declaring on minors included
 
Yep, it works fine for minor civs. I've used it in my own mod. The only problem is that there's nothing stopping you from making peace with the CS immediately after, unless that CS is allied to a civ that's at war with you (in which case you wouldn't have needed to set the CS to war in the first place). So it's really only effective if you're making EVERYONE hate you at once.

Nefliqus: it's case-sensitive, you have to capitalize the D.
 
@Spatzimaus
thx

@smellymummy

I have two question:

1) how do you get "playerteam" and "otherplayerteam"
is it ok?:
Code:
local player1 = Players[player1_ID];
local playerteam = player1:GetTeam();
local player2 = Players[player2_ID];
local otherplayerteam = player2:GetTeam();
playerteam:Meet( otherplayerteam, true );
playerteam:DeclareWar( otherplayerteam, true );


or sth like this? it doesnt work in map script :(

2)I'm not sure if team related methods works in maps script. Would you like to past all
include "name.lua"
lines from your script.


EDIT:
I have made some test and its works now. Thank you for inspiration. :)

Code:
print(">>>> DeclareWar");
local player1 = Players[0];
local playerteam_ID = player1:GetTeam();
local playerteam = Teams[playerteam_ID];
local playerAI = Players[1];
local otherplayerteam_ID = playerAI:GetTeam();
local otherplayerteam = Teams[otherplayerteam_ID];
otherplayerteam:Meet( playerteam, true );
playerteam:Meet( otherplayerteam, true );
otherplayerteam:DeclareWar( playerteam, true );
otherplayerteam:SetPermanentWarPeace(playerteam, true);
 
btw, does the SetPermanentWarPeace function works now ?
 
btw, does the SetPermanentWarPeace function works now ?

not exactly, result is that human can't propose peace but AI sometime sends some peace tender. With only Domination Victory set it works fine, AI don't sent peace tenders. I try to use PreGame methods to set only Domination Victory automatically but it doesn't works in map script. You can set in manually in Advance Setting Menu so it is not a problem.

EDIT:
With this correction it works (AI dont propose peace):
Code:
	-----------------------------------------------------------------------------------
	------------------------------PermanentWarPeace------------------------------------
	-----------------------------------------------------------------------------------
	local PermanentWar_useroption = Map.GetCustomOption(8);
	if PermanentWar_useroption == 1 then
		ScripSetText = ScripSetText .. " PermanentWar=ON" ; 		
		local player1 = Players[0];
		local playerAI = Players[1];
	
		if ( playerAI:IsHuman() == false ) then
			local playerteam_ID = player1:GetTeam();
			local playerteam = Teams[playerteam_ID];
			local otherplayerteam_ID = playerAI:GetTeam();
			local otherplayerteam = Teams[otherplayerteam_ID];
			if playerteam_ID ~= otherplayerteam_ID then
				otherplayerteam:Meet( playerteam, true );
				playerteam:Meet( otherplayerteam, true );
				otherplayerteam:DeclareWar( playerteam, true );
				playerteam:DeclareWar( otherplayerteam, true );
[B]				otherplayerteam:SetPermanentWarPeace(playerteam, true);
				playerteam:SetPermanentWarPeace(otherplayerteam, true);[/B]
				Game.SetOption(GameOptionTypes.GAMEOPTION_QUICK_COMBAT, true);
				Game.SetOption(GameOptionTypes.GAMEOPTION_RANDOM_PERSONALITIES, true);
				Game.SetOption(GameOptionTypes.GAMEOPTION_PROMOTION_SAVING, true);
				Game.SetOption(GameOptionTypes.GAMEOPTION_POLICY_SAVING, true);
			end
		end
	end --end PermanentWarPeace----------------------------------------------------------
 
not exactly, result is that human can't propose peace but AI sometime sends some peace tender. With only Domination Victory set it works fine, AI don't sent peace tenders. I try to use PreGame methods to set only Domination Victory automatically but it doesn't works in map script. You can set in manually in Advance Setting Menu so it is not a problem.

EDIT:
With this correction it works (AI dont propose peace):
Code:
	-----------------------------------------------------------------------------------
	------------------------------PermanentWarPeace------------------------------------
	-----------------------------------------------------------------------------------
	local PermanentWar_useroption = Map.GetCustomOption(8);
	if PermanentWar_useroption == 1 then
		ScripSetText = ScripSetText .. " PermanentWar=ON" ; 		
		local player1 = Players[0];
		local playerAI = Players[1];
	
		if ( playerAI:IsHuman() == false ) then
			local playerteam_ID = player1:GetTeam();
			local playerteam = Teams[playerteam_ID];
			local otherplayerteam_ID = playerAI:GetTeam();
			local otherplayerteam = Teams[otherplayerteam_ID];
			if playerteam_ID ~= otherplayerteam_ID then
				otherplayerteam:Meet( playerteam, true );
				playerteam:Meet( otherplayerteam, true );
				otherplayerteam:DeclareWar( playerteam, true );
				playerteam:DeclareWar( otherplayerteam, true );
[B]				otherplayerteam:SetPermanentWarPeace(playerteam, true);
				playerteam:SetPermanentWarPeace(otherplayerteam, true);[/B]
				Game.SetOption(GameOptionTypes.GAMEOPTION_QUICK_COMBAT, true);
				Game.SetOption(GameOptionTypes.GAMEOPTION_RANDOM_PERSONALITIES, true);
				Game.SetOption(GameOptionTypes.GAMEOPTION_PROMOTION_SAVING, true);
				Game.SetOption(GameOptionTypes.GAMEOPTION_POLICY_SAVING, true);
			end
		end
	end --end PermanentWarPeace----------------------------------------------------------

Sorry for postin in an old thread but I was curious if the above will cause 2 civs to declare permanent war then would changing

otherplayerteam: DeclareWar( playerteam, true );
playerteam: DeclareWar( otherplayerteam, true );

to
otherplayerteam:Make Peace( playerteam, true );
playerteam:MakePeace( otherplayerteam, true );


cause the 2 civs to go back to Pease with each other?

I am asking becasue I am working on a mod to have specific civs go to war and make peace when I want this forces the player to play a historically accurate senario
 
yes, you can force peace this way even if the 2 civs are in a permanent war state.

BTW SetPermanentWarPeace must be done for both, but you need only one MakePeace or DeclareWar.
 
Feel Free to laugh because I am just learning Lua but would the following work??

I am trying to make Rome declare war if the Samnites control 2 specific cities (Teanum & Capua)...I feel like I had to miss something because my code does not look like other code I have looked at in Lua. Please advise guys I need all the help I can get with this.


function RomeStarsFirstSamnieWar()
local rome = GameInfo.Civilizations["CIVILIZATION_ROME"].ID
local samnite = GameInfo.Civilizations["CIVILIZATION_SONGHAI"].ID
local plot1 = GetPlot(21,10)
local plot2 = GetPlot(22,6)
local teanum = plot1:GetPlotCity()
local capua = plot2:GetPlotCity()
if (teanum:GetOwner()) and (capua:GetOwner()) == samnite then
rome: DeclareWar( samnite, true );
end
end
 
Back
Top Bottom