GameEvents.CanDeclareWar (Civ5 API)
This page is a part of the Lua and UI Reference (Civ5).
This function is a member of GameEvents. This is a static method, invoke it with a dot. |
Allows provision of criteria for the ability to declare war. As this is a TestAll event, all listeners must return true for the action to be permitted. As wars are between teams, it is based entirely on teams rather than players (as far as can be inferred from scenario files).
Usage
bool GameEvents.CanDeclareWar(TeamID myTeam, TeamID theirTeam)
Event Type
- Unknown
Returned Value
- Return true if war declaration is to be permitted; false if it is not.
Parameters
myTeam: The team of the player who is hypothetically trying to declare war. theirTeam: The team of them player they are hypothetically trying to declare war on.
Source code samples
TurnsRemaining.lua - DLC_02 DLC
DLC/DLC_02/Scenarios/NewWorldScenario/TurnsRemaining.lua
0254
|
GameEvents.CanDeclareWar.Add(function(myTeam, theirTeam) |
0256
|
local myPlayer = -1; |
0257
|
local theirPlayer = -1; |
0259
|
for iLoopPlayer = 0, GameDefines.MAX_CIV_PLAYERS-1, 1 do |
0260
|
local pLoopPlayer = Players[iLoopPlayer]; |
0261
|
if (pLoopPlayer:GetTeam() == myTeam) then |
0262
|
myPlayer = iLoopPlayer; |
0263
|
end |
0264
|
if (pLoopPlayer:GetTeam() == theirTeam) then |
0265
|
theirPlayer = iLoopPlayer; |
0266
|
end |
0267
|
if (myPlayer ~= -1 and theirPlayer ~= -1) then |
0268
|
break; |
0269
|
end |
0270
|
end |
0272
|
print(myPlayer); |
0273
|
print(Players[myPlayer]); |
0275
|
local myStartingPlot = (Players[myPlayer]) and Players[myPlayer]:GetStartingPlot() or nil; |
0276
|
local theirStartingPlot = (Players[theirPlayer]) and Players[theirPlayer]:GetStartingPlot() or nil; |
0278
|
if(myStartingPlot == nil or theirStartingPlot == nil) then |
0279
|
-- no war. |
0280
|
return false; |
0281
|
end |
0283
|
-- No restrictions on native civs as either declarers or declarees |
0284
|
if (myStartingPlot:GetX() < 50) then |
0285
|
return true; |
0286
|
end |
0287
|
if (theirStartingPlot:GetX() < 50) then |
0288
|
return true; |
0289
|
end |
0291
|
-- This is European on European, so check if power declaring war has piracy |
0292
|
pTeam = Teams[myTeam]; |
0293
|
iTech = GameInfoTypes["TECH_PIRACY"]; |
0294
|
if (pTeam:GetTeamTechs():HasTech(iTech)) then |
0295
|
return true; |
0296
|
end |
0298
|
return false; |
0299
|
end); |
The initial version of this page was created by the Civ5 API Bot, see the Civ5 API Reference FAQ. Some of the texts come from the 2kgames' wiki and most of code samples are copyrighted to Firaxis.
Functions' signatures were either copied from the 2kgames' wiki, or infered from the Lua source files and the binaries. Errors are possible.
Contributors may find help in the Contributors guide to the Civ5 API.