Assit on DOW on a City State... LUA

Craig_Sutter

Deity
Joined
Aug 13, 2002
Messages
2,773
Location
Calgary, Canada
I'm trying to get a DOW and permanent war between a civilization and a minor civ.

This is my code... I keep getting an error in the lua log stating:


[42393.536] DiplomacyDOW: >>>> DeclareWar
[42393.536] Runtime Error: [string "C:\Users\Craig and Nancy\Documents\My Games..."]:17: attempt to index local 'iDenmark' (a number value)

I presume this means I need to do something other than call the player id, but need some sort of text string.

I'm guessing, but should:

local iDenmark = GameInfo.Civilizations["CIVILIZATION_DENMARK"].ID

be:

local pDenmark = GameInfo.Types["CIVILIZATION_DENMARK"]

and:

local iAngles = GameInfo.MinorCivilizations["MINOR_CIV_ANGLES"].ID

be:

local pAngles = GameInfo.MinorTypes["MINOR_CIV_ANGLES"]

or something like that?


Code:
-- Lua Script2
-- Author: Craig and Nancy
-- DateCreated: 8/4/2012 8:10:05 AM
--------------------------------------------------------------
--At the end of the first turn, Denmark declares war on the Angles.  We want TeamIDs, not PlayerIDs.
--First, get playerid.
--Then, get teamid
--Then team1 dow on team2
--Then set permanent war.

function DenmarkWar()
	if Game.GetGameTurn() == 1 then

print(">>>> DeclareWar");

	local iDenmark = GameInfo.Civilizations["CIVILIZATION_DENMARK"].ID
	local DenmarkTeam_ID = iDenmark:GetTeam();
	local DenmarkTeam = Teams[DenmarkTeam_ID];

	local iAngles = GameInfo.MinorCivilizations["MINOR_CIV_ANGLES"].ID
	local AnglesTeam_ID = iAngles:GetTeam();
	local AmglesTeam = Teams[AnglesTeam_ID];

	print(Players[iDenmark]:GetName())
	print(Players[iAngles]:GetName())

DenmarkTeam:DeclareWar( AnglesTeam, true );
DenmarkTeam:SetPermanentWarPeace(AnglesTeam, true);

end
end

Events.ActivePlayerTurnEnd.Add(DenmarkWar)

Thanks for you input.
 
an ID is not a player object, you can't call GetTeam() on an ID, that means nothing for the Lua interpreter.

when you write

Code:
local iDenmark = GameInfo.Civilizations["CIVILIZATION_DENMARK"].ID

iDenmark became GameInfo.Civilizations["CIVILIZATION_DENMARK"].ID wich is CIVILIZATION_DENMARK ID value in the civilization table (a number, unique for each civs, defined when the DB is filled from the game XML files).

You've called it iDenmark, but whatever the name you gave to it, it will still be a civilization ID, nothing more. the prefix "i" is conventional naming, you could have used "e", or nothing, or a suffix "ID", the naming is your to make but won't change the type of the variable.

Now if you use

Code:
local pDenmark = GameInfo.Types["CIVILIZATION_DENMARK"]

what you get there is the complete row of CIVILIZATION_DENMARK. pDenmark from that line is not a player object, it's an array containing the full row of CIVILIZATION_DENMARK from the civilization table, but it's not the player object, you still can't use it to call GetTeam() or any other player functions with it.

The fact that you've called it pDenmark will not magically change it in a player object, remember, you do the naming, what is contained in your named variable is dependent of the definition you've used.

So back to the subject, your pseudo code is correct, but you won't be able to get the player ID directly from a civilization ID, you'll have to loop each player to find which one is Denmark, or simply refer to the player ID set for Denmark if you're using a WB map with scenario setting.
 
Thank-you for the advice. I can never seem to tell exactly what is being called for in the logic of the code... player id, civ type, etc. become quite confusing to me :). I basically copy and paste and alter as seems fitting... a lot of trial and error (emphasis on the error).

This is the code I came up with. It runs without any errors in the log files; however, I am trying to think of a print command to debug and check if it is actually working.

Code:
-- Lua Script2
-- Author: Craig and Nancy
-- DateCreated: 8/4/2012 8:10:05 AM
--------------------------------------------------------------
--[[This is the list of eome of the teams on the scenario map:
1. Denmark 
5. Franks
8. Normandy
11.Wessex
12.Mercia
13.Northumbria
18.HRE

24.Domain of Sygrius
28.East Anglia
29.Kent
30.Essex
31.Sussex
35.Jutes
36.Angles
41.London
46.Winchester
48.York
51.MiddleBriton]]


--At the end of the first turn, Denmark declares war on the Angles.  We want TeamIDs, not PlayerIDs.
--First,get team ID
--Then Denmarkteam dow on Anglesteam
--Then set permanent war.

function DenmarkWar()
	if Game.GetGameTurn() == 1 then

print(">>>> DeclareWar");

	local DenmarkTeam = Teams[1];	
	local AmglesTeam = Teams[36];
	
DenmarkTeam:DeclareWar( AnglesTeam, true );
DenmarkTeam:SetPermanentWarPeace(AnglesTeam, true);

end
end

Events.ActivePlayerTurnEnd.Add(DenmarkWar)
 
Well, I began a game as Denmark. I ended up at war... with Norway (Team 2)? The Angles were angry at me, but not at war... so something is still wrong.

The team numbers are the ones I used on the scenario map. Do they change depending upon the human players? That would make a little sense, as if the human (Denmark) is player 0, then Norway would be player 1... if the team numbers worked the same way, then Norway would declare war against the Angles (or another minor (35?). But if that part of the code was providing a nil value, perhaps that would equate to team 0, Denmark, hence Norway declares on Denmark, as happened.

I guess I'll try to figure out how to determine the teams at the scenario beginning, since the numbers on the map do not seem to work.
 
Still working on this... trying to heed the advice I have gotten, but still not succeeding. At least I'm getting closer (I think).

Anyhow, I'm getting an error message near the end of the file:

2867.594] DiplomacyDOW: >>>> DeclareWar
[2867.594] DiplomacyDOW: Harald Bluetooth
[2867.594] Runtime Error: [string "C:\Users\Craig and Nancy\Documents\My Games..."]:80: attempt to index global 'DenmarkTeam' (a nil value)

As you can see, some of my print debugging is working, but I am not getting to the DOW stage. I get the error message about DenmarkTeam.

I think I am supposed to get the player via a loop, but I am not certain I am doing it right... I think that I may be calling out the wrong object, or a nonobject, to get pDenmark to get the team IDs.

I'm probably making the same error for the AnglesTeam, but have not gotten that far yet.

Here is the code:

Code:
-- Lua Script2
-- Author: Craig and Nancy
-- DateCreated: 8/4/2012 8:10:05 AM
--------------------------------------------------------------
--At the end of the first turn, Denmark declares war on the Angles.  We want TeamIDs, not PlayerIDs.
--First, set to do this in the first turn.
 
--Then, get Denmark Player ID
--Then, get Denmark Team ID

--Then,get Angles Player ID
--Then, get Angles Team ID

--Then Denmarkteam dow on Anglesteam
--Then set permanent war.

function DenmarkWar()
	if Game.GetGameTurn() == 0 then

	print(">>>> DeclareWar");

for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 
    local pDenmark = Players[iPlayer]
    if (pDenmark:IsAlive()) then
      if (pDenmark:GetCivilizationType() == GameInfoTypes.CIVILIZATION_DENMARK) then

	local DenmarkTeam_ID = pDenmark:GetTeam();
	local DenmarkTeam = Teams[DenmarkTeam_ID];

	print(pDenmark:GetName())
end
end
end

for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 
    local pAngles = Players[iPlayer]
    if (pAngles:IsAlive()) then
      if (pAngles:GetCivilizationType() == GameInfoTypes.MINOR_CIV_ANGLES) then

	local AnglesTeam_ID = pAngles:GetTeam();
	local AnglesTeam = Teams[AnglesTeam_ID];

print(pAngles:GetName())
end
end
end

[COLOR="Red"]DenmarkTeam:DeclareWar( AnglesTeam, true );[/COLOR]
DenmarkTeam:SetPermanentWarPeace(AnglesTeam, true);

end
end


Events.ActivePlayerTurnEnd.Add(DenmarkWar)

The red part is where the log says the error is, but I presume it is occurring earlier when I do the loop for Denmark and create the local variables.

Please keep in mind, I'm basically copying and pasting and using intuition and trial and error to do this, so the code is likely very clumsy. I'm learning, slowly, from this board's advice, and am trying to do this on my own. I've looked at many scenarios for examples; however, they never seem to have the simplicity I need, so pulling out code snippets I can use is a little difficult. I looked at RED, and it has some of what I need, but there are so many dependencies on other functions, some of it is hard for me to trace.

I hate going to the well too often.

Anyhow, I think that the result from my loop is not giving the type of input I need for team_ID.

Any further advice is appreciated as always.
 
Yet another failed try at the code for this DoW.

I keep getting the same error:

Spoiler :

[12580.076] DiplomacyDOW: >>>> DeclareWar
[12580.076] DiplomacyDOW: 0
[12580.076] Runtime Error: [string "C:\Users\Craig and Nancy\Documents\My Games..."]:57: attempt to index global 'DenmarkTeam' (a nil value)


I've tried all manner of ways to do this... this is my latest failure- the line for the database error is highlighted in red.

Code:
--At the end of the first turn, Denmark declares war on the Angles.  We want TeamIDs, not PlayerIDs.
--First, set to do this in the first turn.
 
--Then, get Denmark Player ID
--Then, get Denmark Team ID

--Then,get Angles Player ID
--Then, get Angles Team ID

--Then Denmarkteam dow on Anglesteam
--Then set permanent war.


function DenmarkWar()
	if Game.GetGameTurn() == 0 then

	print(">>>> DeclareWar");

for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

local pDenmark = Players[iPlayer]

    if (pDenmark:IsAlive()) then
      if (pDenmark:GetCivilizationType() == GameInfoTypes["CIVILIZATION_DENMARK"]) then

	local DenmarkTeam_ID = pDenmark:GetTeam();
	local DenmarkTeam = Teams[DenmarkTeam_ID];

	print(pDenmark:GetTeam())
	--print(pDenmark:GetName())
	else
end
end
end

for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

local pAngles = Players[iPlayer]

    if (pAngles:IsAlive()) then
      if (pAngles:GetMinorCivType() == GameInfoTypes["MINOR_CIV_ANGLES"]) then

	local AnglesTeam_ID = pAngles:GetTeam();
	local AnglesTeam = Teams[AnglesTeam_ID];

	print(pAngles:GetTeam())
	--print(pAngles:GetName())
	else
end
end
end

[COLOR="Red"]DenmarkTeam:DeclareWar( AnglesTeam, true );[/COLOR]
DenmarkTeam:SetPermanentWarPeace(AnglesTeam, true);

if (DenmarkTeam:IsAtWar(AnglesTeam)) then

print ("Denmark is at war with the Angles");

end
end
end

Events.ActivePlayerTurnEnd.Add(DenmarkWar)

The printed debug lines in the code are always the same... 0 never changes, even when playing a civ other than Denmark. This indicates to me that the snippet is only going through one iteration (iplayer=0) and running into a problem.

I wonder if my for statements should be set as separate functions... or if I should have a couple of "return"s after the "else"s.

Am I totally off course on this?
 
Code:
for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do [COLOR="Red"]--See note 1[/COLOR]

local pAngles = Players[iPlayer]

    if (pAngles:IsAlive()) then
      if (pAngles:GetMinorCivType() == GameInfoTypes["MINOR_CIV_ANGLES"]) then

	local AnglesTeam_ID = pAngles:GetTeam();
	local AnglesTeam = Teams[AnglesTeam_ID]; [COLOR="Red"]--See note 2[/COLOR]

	print(pAngles:GetTeam())
	--print(pAngles:GetName())
	else
[COLOR="Red"]--See note 3[/COLOR]
end
end
end

DenmarkTeam:DeclareWar( AnglesTeam, true );

1. Angles is a minor civilization right? (A city-state). This for loop will iterate over every major civ but stop before reaching any minor civilizations. You want:

Code:
for index = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do
    local minorCiv = Players[index];
    ...
end

2. AnglesTeam may be out of scope by the time you get to your DenmarkTeam:DeclareWar( AnglesTeam, true ); line. Since you have DenmarkTeam as a local within your other for loop, DenmarkTeam would also be out of scope once that for loop ended. In both cases you would want to have something like:

Code:
local AnglesTeam;
for index = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do
    local minorCiv = Players[index];
    ...
    AnglesTeam = Teams[something];
    ...
end

DenmarkTeam:DeclareWar( AnglesTeam, true );

3. It looks like you aren't printing anything when this for loop iterates and "pAngles:GetMinorCivType() == GameInfoTypes["MINOR_CIV_ANGLES"]" isn't true. Combined with note 1 that may mean the loop will never print anything because no major civ is going to match minor civ angles.
 
I implemented suggestion 1 and 2 as recommended above and that improved things.

Babysteps:

.. my log now has the error, which is actually a big improvement as far as I'm concerned:

Spoiler :

[4586.273] DiplomacyDOW: >>>> DeclareWar
[4586.273] DiplomacyDOW: 0
[4586.273] DiplomacyDOW: 35
[4586.273] Runtime Error: [string "C:\Users\Craig and Nancy\Documents\My Games..."]:58: attempt to index local 'DenmarkTeam' (a nil value)


so all my print statements are working...

however, it appears to be going through only one iteration for the DenmarkTeam...

I think something is not working here:

Code:
local DenmarkTeam
for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

local pDenmark = Players[iPlayer]

    if (pDenmark:IsAlive()) then
      if (pDenmark:GetCivilizationType() == GameInfoTypes["CIVILIZATION_DENMARK"]) then

	local DenmarkTeam_ID = pDenmark:GetTeam();
	local DenmarkTeam = Teams[DenmarkTeam_ID];

	print(pDenmark:GetTeam())
	--print(pDenmark:GetName())
	else
end
end
end

The first iteration would result in 0, as indicated by the log... (I ran the mod twice, once as Denmark and once as another player civ... and got the same error in the log).

So the code is finished after the first iteration, it has successfully gone through its cycle and did not need to reiterate. pDenmark is coming out as player 0, but the Denmark civ is not player 0 so
Code:
  if (pDenmark:GetCivilizationType() == GameInfoTypes["CIVILIZATION_DENMARK"]) then
is likely wrong.

Finally, whether the the number that comes out is 0 or not, I should not be getting a nil value on line 57 for DenmarkTeam
Code:
DenmarkTeam:DeclareWar( AnglesTeam, true );
DenmarkTeam:SetPermanentWarPeace(AnglesTeam, true);
as DenmarkTeam should at least be 0, so the variable must somehow be wrong as well, maybe the wrong type.

I'll continue to fiddle with this... thanks for the advice. It has really helped me to pick away at some of the mistakes in the code and progress is being made.
 
Well, after more fiddling, I've made more progress... but am still kind of stuck.

As the log shows, the iteration process is working and my print functions are printing... however, the process continues without stopping at the appropriate player numbers, so something is not working. And I am still getting a nil value error for DenmarkTeam.

Here is the log:

Spoiler :


[12183.475] DiplomacyDOW: >>>> DeclareWar
[12183.475] DiplomacyDOW: 18
[12183.475] DiplomacyDOW: 1
[12183.475] DiplomacyDOW: 2
[12183.490] DiplomacyDOW: 3
[12183.490] DiplomacyDOW: 4
[12183.490] DiplomacyDOW: 5
[12183.490] DiplomacyDOW: 6
[12183.490] DiplomacyDOW: 7
[12183.490] DiplomacyDOW: 8
[12183.490] DiplomacyDOW: 9
[12183.490] DiplomacyDOW: 10
[12183.506] DiplomacyDOW: 11
[12183.506] DiplomacyDOW: 12
[12183.506] DiplomacyDOW: 13
[12183.506] DiplomacyDOW: 14
[12183.506] DiplomacyDOW: 15
[12183.506] DiplomacyDOW: 16
[12183.506] DiplomacyDOW: 17
[12183.506] DiplomacyDOW: 0
[12183.522] DiplomacyDOW: 19
[12183.522] DiplomacyDOW: 20
[12183.522] DiplomacyDOW: 21
[12183.522] DiplomacyDOW: 22
[12183.522] DiplomacyDOW: 23
[12183.522] DiplomacyDOW: 24
[12183.522] DiplomacyDOW: 25
[12183.522] DiplomacyDOW: 26
[12183.537] DiplomacyDOW: 27
[12183.537] DiplomacyDOW: 28
[12183.537] DiplomacyDOW: 29
[12183.537] DiplomacyDOW: 30
[12183.537] DiplomacyDOW: 31
[12183.537] DiplomacyDOW: 32
[12183.537] DiplomacyDOW: 33
[12183.553] DiplomacyDOW: 34
[12183.553] DiplomacyDOW: 35
[12183.553] DiplomacyDOW: 36
[12183.553] DiplomacyDOW: 37
[12183.553] DiplomacyDOW: 38
[12183.553] DiplomacyDOW: 39
[12183.553] DiplomacyDOW: 40
[12183.553] DiplomacyDOW: 41
[12183.568] DiplomacyDOW: 42
[12183.568] DiplomacyDOW: 43
[12183.568] DiplomacyDOW: 44
[12183.568] DiplomacyDOW: 45
[12183.568] DiplomacyDOW: 46
[12183.568] DiplomacyDOW: 47
[12183.568] DiplomacyDOW: 48
[12183.568] DiplomacyDOW: 49
[12183.584] DiplomacyDOW: 50
[12183.584] DiplomacyDOW: 51
[12183.584] DiplomacyDOW: 52
[12183.584] DiplomacyDOW: 53
[12183.584] DiplomacyDOW: 54
[12183.584] DiplomacyDOW: 55
[12183.584] DiplomacyDOW: 56
[12183.584] Runtime Error: [string "C:\Users\Craig and Nancy\Documents\My Games..."]:57: attempt to index local 'DenmarkTeam' (a nil value)


And here is the code.

Code:
function DenmarkWar()
	if Game.GetGameTurn() == 0 then

	print(">>>> DeclareWar");
local DenmarkTeam
for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

local pDenmark = Players[iPlayer]

    if (pDenmark:IsAlive()) then
		if (GameInfo.Civilizations.CIVILIZATION_DENMARK.ID == GameInfoTypes["CIVILIZATION_DENMARK"]) then
		
	local DenmarkTeam = Teams[pDenmark:GetTeam()];
	
	print(pDenmark:GetTeam())
	--print(pDenmark:GetName())
	
	else
end
end
end

local AnglesTeam
for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do 

local pAngles = Players[iPlayer]

    if (pAngles:IsAlive()) then
		if (GameInfo.MinorCivilizations.MINOR_CIV_ANGLES.ID == GameInfoTypes["MINOR_CIV_ANGLES"]) then
		
	local AnglesTeam = Teams[pAngles:GetTeam()];
	
	print(pAngles:GetTeam())
	--print(pAngles:GetName())
	
	else
end
end
end

DenmarkTeam:DeclareWar( AnglesTeam, true );
DenmarkTeam:SetPermanentWarPeace(AnglesTeam, true);

if (DenmarkTeam:IsAtWar(AnglesTeam)) then

print ("Denmark is at war with the Angles");

end
end
end

Events.ActivePlayerTurnEnd.Add(DenmarkWar)

I feel I am missing some step in translating the iteration into the proper thing. I think I need some other variable using GameInfoTypes["CIVILIZATION_DENMARK"] to get the team. Similarly, with GameInfoTypes["MINOR_CIV_ANGLES"].

I'll keep working on it. As always, advice would be appreciated.
 
Now, it's just weird...

I finally got all of my print debugs to go off.

However, the last try, the Visigoths declared war on the Danes? Previously, I had not played as the Danes, and was not getting any printout of my Declaration of War message, but was not receiving any errors in the log either. The last time,though, as Denmark, I got no errors, and my final print command as well, meaning, according to the function, Denmark should be at war with the Angles... but as mentioned, the war was declared by the Visigoths on me, the Danes!

Not certain how that came about...

Here is the log:

Spoiler :


[13211.163] DiplomacyDOW: >>>> DeclareWar
[13211.163] DiplomacyDOW: Harald Bluetooth
[13211.163] DiplomacyDOW: 0
[13211.163] DiplomacyDOW: table: 14B27400
[13211.163] DiplomacyDOW: OLAF
[13211.178] DiplomacyDOW: 1
[13211.178] DiplomacyDOW: table: 14B25268
[13211.178] DiplomacyDOW: TURLOUGH
[13211.178] DiplomacyDOW: 2
[13211.178] DiplomacyDOW: table: 14B25178
[13211.178] DiplomacyDOW: ANGUS
[13211.178] DiplomacyDOW: 3
[13211.178] DiplomacyDOW: table: 14B25D80
[13211.194] DiplomacyDOW: CLOVIS
[13211.194] DiplomacyDOW: 4
[13211.194] DiplomacyDOW: table: 14B20A60
[13211.194] DiplomacyDOW: RIDERCH
[13211.194] DiplomacyDOW: 5
[13211.194] DiplomacyDOW: table: 14B212A8
[13211.194] DiplomacyDOW: WITTEKIND
[13211.194] DiplomacyDOW: 6
[13211.209] DiplomacyDOW: table: 14B21CA8
[13211.209] DiplomacyDOW: William
[13211.209] DiplomacyDOW: 7
[13211.209] DiplomacyDOW: table: 14B21910
[13211.209] DiplomacyDOW: BORU
[13211.209] DiplomacyDOW: 8
[13211.209] DiplomacyDOW: table: 14B21D48
[13211.209] DiplomacyDOW: Kenny
[13211.225] DiplomacyDOW: 9
[13211.225] DiplomacyDOW: table: 14B22BF8
[13211.225] DiplomacyDOW: Alfred
[13211.225] DiplomacyDOW: 10
[13211.225] DiplomacyDOW: table: 14B215C8
[13211.225] DiplomacyDOW: PENDA
[13211.225] DiplomacyDOW: 11
[13211.225] DiplomacyDOW: table: 14B21C58
[13211.241] DiplomacyDOW: OSWALD
[13211.241] DiplomacyDOW: 12
[13211.241] DiplomacyDOW: table: 14B21CF8
[13211.241] DiplomacyDOW: Elisedd
[13211.241] DiplomacyDOW: 13
[13211.241] DiplomacyDOW: table: 14B28EE0
[13211.241] DiplomacyDOW: Haakon
[13211.256] DiplomacyDOW: 14
[13211.256] DiplomacyDOW: table: 14B24228
[13211.256] DiplomacyDOW: ERIK
[13211.256] DiplomacyDOW: 15
[13211.256] DiplomacyDOW: table: 14B28A08
[13211.256] DiplomacyDOW: Constantine
[13211.256] DiplomacyDOW: 16
[13211.256] DiplomacyDOW: table: 14B28F08
[13211.272] DiplomacyDOW: OTTO
[13211.272] DiplomacyDOW: 17
[13211.272] DiplomacyDOW: table: 14B2CBF8
[13211.272] DiplomacyDOW: Alaric
[13211.272] DiplomacyDOW: 18
[13211.272] DiplomacyDOW: table: 14B230F8
[13211.272] DiplomacyDOW: Iona
[13211.272] DiplomacyDOW: 19
[13211.287] DiplomacyDOW: table: 14B2B5F0
[13211.287] DiplomacyDOW: Brittany
[13211.287] DiplomacyDOW: 20
[13211.287] DiplomacyDOW: table: 14B24818
[13211.287] DiplomacyDOW: Gwent
[13211.287] DiplomacyDOW: 21
[13211.287] DiplomacyDOW: table: 14B24B10
[13211.287] DiplomacyDOW: Wiht
[13211.303] DiplomacyDOW: 22
[13211.303] DiplomacyDOW: table: 14B24DB8
[13211.303] DiplomacyDOW: The Domain of Syagrius
[13211.303] DiplomacyDOW: 23
[13211.303] DiplomacyDOW: table: 14B290E8
[13211.303] DiplomacyDOW: Gwynedd
[13211.303] DiplomacyDOW: 24
[13211.303] DiplomacyDOW: table: 14B29318
[13211.319] DiplomacyDOW: Deheubarth
[13211.319] DiplomacyDOW: 25
[13211.319] DiplomacyDOW: table: 14B29638
[13211.319] DiplomacyDOW: West Frisia
[13211.319] DiplomacyDOW: 26
[13211.319] DiplomacyDOW: table: 14B2D968
[13211.319] DiplomacyDOW: East Anglia
[13211.334] DiplomacyDOW: 27
[13211.334] DiplomacyDOW: table: 14B2DC88
[13211.334] DiplomacyDOW: Kent
[13211.334] DiplomacyDOW: 28
[13211.334] DiplomacyDOW: table: 14B2DFF8
[13211.334] DiplomacyDOW: Essex
[13211.334] DiplomacyDOW: 29
[13211.334] DiplomacyDOW: table: 14B260F0
[13211.350] DiplomacyDOW: Sussex
[13211.350] DiplomacyDOW: 30
[13211.350] DiplomacyDOW: table: 14B263C0
[13211.350] DiplomacyDOW: Meath
[13211.350] DiplomacyDOW: 31
[13211.350] DiplomacyDOW: table: 14B26730
[13211.350] DiplomacyDOW: Ulster
[13211.350] DiplomacyDOW: 32
[13211.365] DiplomacyDOW: table: 14B2C2E8
[13211.365] DiplomacyDOW: Hordaland
[13211.365] DiplomacyDOW: 33
[13211.365] DiplomacyDOW: table: 14B2C5E0
[13211.365] DiplomacyDOW: Jutes
[13211.365] DiplomacyDOW: 34
[13211.365] DiplomacyDOW: table: 14B29ED0
[13211.365] DiplomacyDOW: Angles
[13211.381] DiplomacyDOW: 35
[13211.381] DiplomacyDOW: table: 14B26CF8
[13211.381] DiplomacyDOW: East Frisia
[13211.381] DiplomacyDOW: 36
[13211.381] DiplomacyDOW: table: 14B2F150
[13211.381] DiplomacyDOW: Leinster
[13211.381] DiplomacyDOW: 37
[13211.381] DiplomacyDOW: table: 14B2FFD8
[13211.397] DiplomacyDOW: Hamburg
[13211.397] DiplomacyDOW: 38
[13211.397] DiplomacyDOW: table: 14B2A4C0
[13211.397] DiplomacyDOW: Slav
[13211.397] DiplomacyDOW: 39
[13211.397] DiplomacyDOW: table: 14B2ADA8
[13211.397] DiplomacyDOW: London
[13211.412] DiplomacyDOW: 40
[13211.412] DiplomacyDOW: table: 14B2B780
[13211.412] DiplomacyDOW: Irish Scots
[13211.412] DiplomacyDOW: 41
[13211.412] DiplomacyDOW: table: 14B21FC8
[13211.412] DiplomacyDOW: South Pictland
[13211.412] DiplomacyDOW: 42
[13211.412] DiplomacyDOW: table: 14B299D0
[13211.428] DiplomacyDOW: Pengwern
[13211.428] DiplomacyDOW: 43
[13211.428] DiplomacyDOW: table: 14B278D8
[13211.428] DiplomacyDOW: Gloucester
[13211.428] DiplomacyDOW: 44
[13211.428] DiplomacyDOW: table: 14B23D00
[13211.428] DiplomacyDOW: Winchester
[13211.428] DiplomacyDOW: 45
[13211.443] DiplomacyDOW: table: 14B281E8
[13211.443] DiplomacyDOW: Rheged
[13211.443] DiplomacyDOW: 46
[13211.443] DiplomacyDOW: table: 14B2A150
[13211.443] DiplomacyDOW: York
[13211.443] DiplomacyDOW: 47
[13211.443] DiplomacyDOW: table: 14B2E458
[13211.443] DiplomacyDOW: Glastonbury
[13211.459] DiplomacyDOW: 48
[13211.459] DiplomacyDOW: table: 14B2F8F8
[13211.459] DiplomacyDOW: Silchester
[13211.459] DiplomacyDOW: 49
[13211.459] DiplomacyDOW: table: 14B220B8
[13211.459] DiplomacyDOW: Middle Briton
[13211.459] DiplomacyDOW: 50
[13211.459] DiplomacyDOW: table: 14B23F58
[13211.475] DiplomacyDOW: Lindisware
[13211.475] DiplomacyDOW: 51
[13211.475] DiplomacyDOW: table: 14B27518
[13211.475] DiplomacyDOW: Bernicia
[13211.475] DiplomacyDOW: 52
[13211.475] DiplomacyDOW: table: 14B298E0
[13211.475] DiplomacyDOW: Elmet
[13211.490] DiplomacyDOW: 53
[13211.490] DiplomacyDOW: table: 14B2B410
[13211.490] DiplomacyDOW: Deira
[13211.490] DiplomacyDOW: 54
[13211.490] DiplomacyDOW: table: 14B2EF20
[13211.490] DiplomacyDOW: Gododdin
[13211.490] DiplomacyDOW: 55
[13211.490] DiplomacyDOW: table: 14B30668
[13211.506] DiplomacyDOW: Burgundy
[13211.506] DiplomacyDOW: 56
[13211.506] DiplomacyDOW: table: 14B25A38
[13211.506] DiplomacyDOW: Denmark is at war with the Angles


Here is the code:

Code:
function DenmarkWar()
	if Game.GetGameTurn() == 0 then

	print(">>>> DeclareWar");
local DenmarkTeam
for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

local iDenmark = Players[iPlayer]

    if (iDenmark:IsAlive()) then
		if (GameInfoTypes["CIVILIZATION_DENMARK"] == GameInfo.Civilizations.CIVILIZATION_DENMARK.ID) then
		
	DenmarkTeam = Teams[iDenmark:GetTeam()];
	
	print(iDenmark:GetName())
	print(iDenmark:GetTeam())
	print (DenmarkTeam)
		
	else
end
end
end

local AnglesTeam
for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do 

local iAngles = Players[iPlayer]

    if (iAngles:IsAlive()) then
		if (GameInfoTypes["MINOR_CIV_ANGLES"] == GameInfo.MinorCivilizations.MINOR_CIV_ANGLES.ID) then
		
	AnglesTeam = Teams[iAngles:GetTeam()];
	
	print(iAngles:GetName())
	print(iAngles:GetTeam())
	print (AnglesTeam)
		
	else
end
end
end

DenmarkTeam:DeclareWar( AnglesTeam, true );
DenmarkTeam:SetPermanentWarPeace(AnglesTeam, true);

if (DenmarkTeam:IsAtWar(AnglesTeam)) then

print ("Denmark is at war with the Angles");

end
end
end

Events.ActivePlayerTurnEnd.Add(DenmarkWar)

I feel that I have almost got it... I've no errors and the final print is okay. But something is screwed up about how the Teams are comprised. I have a feeling that it is choosing the last major civ (Visigoths) because for some reason it does not stop iterating at Denmark. Then for the other Team, Angles, 0 is the first iteration and that's Denmark. It is stopping at any minor either.

Somehow, I've got to figure out how to get the program to stop reiterating at the appropriate civs.

This is something I do not know how to do, and is likely a simple command.

I hope someone can advise me where to go from here. I've got rid of all the errors and have a result of a dow, but I don't know how to get the right teams to dow.
 
Code:
local DenmarkTeam
for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

local pDenmark = Players[iPlayer]

    if (pDenmark:IsAlive()) then
		if (GameInfo.Civilizations.CIVILIZATION_DENMARK.ID == GameInfoTypes["CIVILIZATION_DENMARK"]) then
		
	[COLOR="Red"]local DenmarkTeam = Teams[pDenmark:GetTeam()];[/COLOR]
	
	print(pDenmark:GetTeam())
	--print(pDenmark:GetName())
	
	else
end
The reason you're most recent code is (sort of) working is because you changed the red line to "DenmarkTeam = ..." instead of "local DenmarkTeam = ...".

Code:
local DenmarkTeam
for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

local iDenmark = Players[iPlayer]

    if (iDenmark:IsAlive()) then
		[COLOR="Red"]if (GameInfoTypes["CIVILIZATION_DENMARK"] == GameInfo.Civilizations.CIVILIZATION_DENMARK.ID)[/COLOR] then
		
	DenmarkTeam = Teams[iDenmark:GetTeam()];
	
	print(iDenmark:GetName())
	print(iDenmark:GetTeam())
	print (DenmarkTeam)
		
	else
end
end
end
Conceptually what you are trying to do is find out the team of Denmark. You're going to do that through a couple of steps:

1) Look at each player (this is what the for loop is doing)
2) Determine if the player you're looking at is Denmark (this is the red line, which isn't correct)
3) If and only if they are Denmark, assign their team to the DenmarkTeam variable. (this is sort of the problem you were previously having)

The line:
local iDenmark = Players[iPlayer]
is the player you are looking at. Calling them "iDenmark" is misleading (but not "incorrect", variable names can be whatever you want) because you don't know they are Denmark (they could be but they could also not be). To determine if they are Denmark you need to compare "iDenmark" to something but in the red line above "iDenmark" does not show up on either side of the == test.

If you really want I can just show you what the code should be but I think you'll learn more when you solve this for yourself since you are almost there.
 
More progress, Denmark is declaring war... but it is on himself :) .


Here is the relevant part of the log... now, you can see that the print for "isAtWar" is not working, so that is one problem.

The good news is that I think that Denmark is declaring war, at least when the human is playing. I can't tell otherwise, because my print for "IsAtWar" is not outputting, but that depends upon who is at war.

Spoiler :

DiplomacyDOW: >>>> DeclareWar
DiplomacyDOW: Harald Bluetooth
DiplomacyDOW: 0
DiplomacyDOW: table: 14674EF0
DiplomacyDOW: Angles
DiplomacyDOW: 35
DiplomacyDOW: table: 1467A828
Advisors: Marking SIEGE_UNIT as seen


This is my new code.

Code:
function DenmarkWar()
	if Game.GetGameTurn() == 0 then

	print(">>>> DeclareWar");
local DenmarkTeam
for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

local pDenmark = Players[iPlayer]

    if (pDenmark:IsAlive()) then
		[COLOR="red"]if (pDenmark:GetCivilizationType() == GameInfo.Civilizations.CIVILIZATION_DENMARK.ID) then
		--if (GameInfoTypes["CIVILIZATION_DENMARK"] == GameInfo.Civilizations.CIVILIZATION_DENMARK.ID) then[/COLOR]
		
	DenmarkTeam = Teams[pDenmark:GetTeam()];
	
	print(pDenmark:GetName())
	print(pDenmark:GetTeam())
	print (DenmarkTeam)
	
	else
end
end
end

local AnglesTeam
for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do 

local pAngles = Players[iPlayer]

    if (pAngles:IsAlive()) then
		[COLOR="Red"]if (pAngles:GetMinorCivType() == GameInfo.MinorCivilizations.MINOR_CIV_ANGLES.ID) then
		--if (GameInfoTypes["MINOR_CIV_ANGLES"] == GameInfo.MinorCivilizations.MINOR_CIV_ANGLES.ID) then[/COLOR]
		
	AnglesTeam = Teams[pAngles:GetTeam()];
	
	print(pAngles:GetName())
	print(pAngles:GetTeam())
	print (AnglesTeam)
	
	else
end
end
end

DenmarkTeam:DeclareWar( AnglesTeam, true );
DenmarkTeam:SetPermanentWarPeace(AnglesTeam, true);

if (DenmarkTeam:IsAtWar(AnglesTeam)) then

print ("Denmark is at war with the Angles");

end
end
end

Events.ActivePlayerTurnEnd.Add(DenmarkWar)

I've tried multiple variations in the red areas= equated with iPlayer, pDenmark and pDenmark:GetCivilizationType() in all sorts of ways, but have not moved closer.

The only thing I haven't tried is some sort of pDenmark:GetCivilizationID(), mostly because I don't know the how that function is spelled. I've looked, but haven't found it yet.

Way things go, that's probably what I need :). I'll continue looking at various scenarios for more clues.

Thanks for the advice.
 
I'm stumped...

I've looked at many scenarios and mods for examples... I've tried countless permutations and variants. I understand what is necessary, in theory, but can't seem to put things together to implement the theory.

This is my latest try, but it is not necessarily the best one... just the latest on endless variations:

Code:
function DenmarkWar()
	if Game.GetGameTurn() == 0 then

	print(">>>> DeclareWar");
local DenmarkTeam
for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

local pDenmark = Players[iPlayer]

    if (pDenmark:IsAlive()) then
		if (pDenmark:GetCivilizationType() == GameInfo.Civilizations.CIVILIZATION_DENMARK.ID) then
		--if (GameInfoTypes["CIVILIZATION_DENMARK"] == GameInfo.Civilizations.CIVILIZATION_DENMARK.ID) then
	
	DenmarkPlayer = pDenmark	
	DenmarkTeam = Teams[DenmarkPlayer:GetTeam()];
	
	print(pDenmark:GetName())
	print(pDenmark:GetTeam())
	print (DenmarkTeam)
	
	else
end
end
end

local AnglesTeam
for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do 

local pAngles = Players[iPlayer]

    if (pAngles:IsAlive()) then
		if (pAngles:GetMinorCivType() == GameInfo.MinorCivilizations.MINOR_CIV_ANGLES.ID) then
		--if (GameInfoTypes["MINOR_CIV_ANGLES"] == GameInfo.MinorCivilizations.MINOR_CIV_ANGLES.ID) then
	
	AnglesPlayer = pAngles	
	AnglesTeam = Teams[AnglesPlayer:GetTeam()];
	
	print(pAngles:GetName())
	print(pAngles:GetTeam())
	print (AnglesTeam)
	
	else
end
end
end

DenmarkTeam:DeclareWar( AnglesTeam, true );
DenmarkTeam:SetPermanentWarPeace(AnglesTeam, true);

if (DenmarkTeam:IsAtWar(AnglesTeam)) then

print ("Denmark is at war with the Angles");

end
end
end

Events.ActivePlayerTurnEnd.Add(DenmarkWar)

And the log:
Spoiler :

[25939.752] DiplomacyDOW: >>>> DeclareWar
[25939.768] DiplomacyDOW: Harald Bluetooth
[25939.768] DiplomacyDOW: 0
[25939.768] DiplomacyDOW: table: 14758C18
[25939.768] DiplomacyDOW: Angles
[25939.768] DiplomacyDOW: 35
[25939.768] DiplomacyDOW: table: 147578B8


I'm still looking but am losing hope and getting frustrated.
 
I am completely flabbergasted over this coding. I've tried every way I can think of... the following code is my best effort.

Code:
function DenmarkWar()
	if Game.GetGameTurn() == 0 then

	print(">>>> DeclareWar");
local DenmarkTeam
for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

local pDenmark = Players[iPlayer]

    if (pDenmark:IsAlive()) then
		if (GameInfo.Civilizations.CIVILIZATION_DENMARK.ID == pDenmark:GetCivilizationType()) then
		--if (GameInfoTypes["CIVILIZATION_DENMARK"] == GameInfo.Civilizations.CIVILIZATION_DENMARK.ID) then
	
	DenmarkCiv = iPlayer;
	eDenmark = Players[DenmarkCiv];
	Denmarkteam = Teams[eDenmark:GetTeam()];
	
	print(eDenmark:GetName());
	print(eDenmark:GetTeam());
	print (Teams[eDenmark:GetTeam()]);
		
	else
end
end
end

local AnglesTeam
for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do 

local pAngles = Players[iPlayer]

    if (pAngles:IsAlive()) then
		if (GameInfo.MinorCivilizations.MINOR_CIV_ANGLES.ID == pAngles:GetMinorCivType()) then
		--if (GameInfoTypes["MINOR_CIV_ANGLES"] == GameInfo.MinorCivilizations.MINOR_CIV_ANGLES.ID) then
	
	AnglesCiv = iPlayer;
	eAngles = Players[AnglesCiv];
	Anglesteam = Teams[eAngles:GetTeam()];
	
	print(eAngles:GetName());
	print(eAngles:GetTeam());
	print (Teams[eAngles:GetTeam()]);
	
	else
end
end
end

DenmarkTeam:DeclareWar( AnglesTeam, true );
DenmarkTeam:SetPermanentWarPeace(AnglesTeam, true);

if (DenmarkTeam:IsAtWar(AnglesTeam)) then

print ("Denmark is at war with the Angles");

end
end
end

Events.ActivePlayerTurnEnd.Add(DenmarkWar)

And here is the error log:
Spoiler :

[15646.900] DiplomacyDOW: >>>> DeclareWar
[15646.900] DiplomacyDOW: Harald Bluetooth
[15646.900] DiplomacyDOW: 0
[15646.900] DiplomacyDOW: table: 1465E638
[15646.915] DiplomacyDOW: Angles
[15646.915] DiplomacyDOW: 35
[15646.915] DiplomacyDOW: table: 1465C2C0
[15646.915] Runtime Error: [string "C:\Users\Craig and Nancy\Documents\My Games..."]:66: attempt to index local 'DenmarkTeam' (a nil value)


I think the print code shows that I am getting the information I need to do the DoW. The fact it is printing means that all my for and if statements are working somehow.

For some reason, the DenmarkTeam and AnglesTeam are not being accepted into the DoW part of the function. I'm not certain whether they are not the proper form, be it text or integer; or if the problem is that DenmarkTeam and AnglesTeam are nil because they are generated, but not being remembered.

To that end, I did try Return DenmarkTeam and Return AnglesTeam, thinking that would retain their values, but that ended in failure.

I need some advice because right now, I'm just spinning my tires.
 
one error here:

Code:
local Denmark[COLOR="Red"]T[/COLOR]eam

Code:
Denmark[COLOR="Red"]t[/COLOR]eam = Teams[eDenmark:GetTeam()]

variable names are case sensitive, so if you've defined DenmarkTeam, use

Code:
Denmark[COLOR="Red"]T[/COLOR]eam = Teams[eDenmark:GetTeam()]
 
Thank you Gedemon... that error crept in while I was doing all of my rejigging of the code.

I now get this error:

Spoiler :

DiplomacyDOW: >>>> DeclareWar
DiplomacyDOW: Harald Bluetooth
DiplomacyDOW: 0
DiplomacyDOW: table: 157C8550
DiplomacyDOW: Angles
DiplomacyDOW: 35
DiplomacyDOW: table: 157560D0


on my scenario map, Denmark is player 1 on Team 1. The Angles are player 36 on Team 36... When I play as Denmark, naturally, it moves to Team 0 and all other players move up a notch... my print commands show this. My final isatwar print is not working, though.

In game, though, I get "You have declared war on HaroldBluetooth" or something like that... so Player 0 (Denmark) is not declaring on Player 35 (Angles) but for some reason, on himself, Player 0.

I just thought of something... perhaps where I define local = AnglesTeam should be next to where I define local = DenmarkTeam. I'll try that next.

Again, thank-you for spotting that error. Advice, as always, is welcome.
 
here is another problem:

Code:
DenmarkTeam:DeclareWar( AnglesTeam, true );
DenmarkTeam:SetPermanentWarPeace(AnglesTeam, true);

those will not work, DeclareWar() and SetPermanentWarPeace() need the team ID, the one you get with player:GetTeam(), not the team object.

also, on a side note, for true permanent war you'll have to set it both way (Denmark to Angles then Angles to Denmark), but even using that the CS menu will still allow a human player to make peace, so you may have to edit that screen too.
 
I did it!

The log:

Spoiler :

[5505.634] DiplomacyDOW: >>>> DeclareWar
[5505.649] DiplomacyDOW: Harald Bluetooth
[5505.649] DiplomacyDOW: 0
[5505.649] DiplomacyDOW: Angles
[5505.649] DiplomacyDOW: 35
[5505.649] DiplomacyDOW: Denmark is at war with the Angles


The code:

Code:
-- Lua Script2
-- Author: Craig and Nancy
-- DateCreated: 8/4/2012 8:10:05 AM
--------------------------------------------------------------

--At the end of the first turn, Denmark declares war on the Angles.  We want TeamIDs, not PlayerIDs.
--First, set to do this in the first turn.
 
--Then, get Denmark Player ID
--Then, get Denmark Team ID

--Then,get Angles Player ID
--Then, get Angles Team ID

--Then DenmarkTeam dow on AnglesTeam
--Then set permanent war.

function DenmarkWar()
	if Game.GetGameTurn() == 0 then

	print(">>>> DeclareWar");
local DenmarkTeam
local AnglesTeam

for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

local pDenmark = Players[iPlayer]

    if (pDenmark:IsAlive()) then
		if (GameInfo.Civilizations.CIVILIZATION_DENMARK.ID == pDenmark:GetCivilizationType()) then
		--if (GameInfoTypes["CIVILIZATION_DENMARK"] == GameInfo.Civilizations.CIVILIZATION_DENMARK.ID) then
	
	DenmarkTeam= Teams[ pDenmark:GetTeam() ]

	print(pDenmark:GetName());
	print(pDenmark:GetTeam());
		
	else
end
end
end

--local AnglesTeam
for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do 

local pAngles = Players[iPlayer]

    if (pAngles:IsAlive()) then
		if (GameInfo.MinorCivilizations.MINOR_CIV_ANGLES.ID == pAngles:GetMinorCivType()) then
		--if (GameInfoTypes["MINOR_CIV_ANGLES"] == GameInfo.MinorCivilizations.MINOR_CIV_ANGLES.ID) then
	
	AnglesTeam = pAngles:GetTeam();
	
	print(pAngles:GetName());
	print(pAngles:GetTeam());
	
	else
end
end
end

DenmarkTeam:DeclareWar( AnglesTeam, true );
DenmarkTeam:SetPermanentWarPeace(AnglesTeam, true);

if (DenmarkTeam:IsAtWar(AnglesTeam)) then

print ("Denmark is at war with the Angles");

end
end
end

Events.ActivePlayerTurnEnd.Add(DenmarkWar)

Here is what I was doing wrong at the end...

In: DenmarkTeam:DeclareWar( AnglesTeam, true ); I assumed an equivalency that was not true... I called both

DenmarkTeam= Teams[ pDenmark:GetTeam() ]
and
AnglesTeam= Teams[ pAngles:GetTeam() ]

but AnglesTeam should be AnglesTeam = pAngles:GetTeam()

I will likely rename AnglesTeam to AnglesTeam_ID later to reflect the difference.

Thank you Machiavelli24 and Gedemon for your assistance.
:)
 
Back
Top Bottom