LUA peace with barbs

ps solved

its possible

Code:
	local barbs, human;
	for n, player in pairs(Players) do
		print(n);
		if IsValid(player) then
			print(GetPlayerName(player));
			if player:GetCivilizationType() == GameInfoTypes.CIVILIZATION_BARBARIAN then
				barbs = player;
				print("barbs found");
			end
			if player:IsHuman() then
				human = player;
				print("human found");
			end
		end
	end
	local bteam = barbs:GetTeam();
	print("barb team = " .. bteam);
	Teams[human:GetTeam()]:MakePeace(bteam);
 
By definition, the barbs are always the last player, so

Code:
local iBarbPlayer = GameDefines.MAX_PLAYERS-1

also, as you're only looking for one human player, that will always be

Code:
local iHumanPlayer = Game.GetActivePlayer()
local iHumanTeam = Game.GetActiveTeam()

so you just need

Code:
Teams[Game.GetActiveTeam()]:MakePeace(Players[GameDefines.MAX_MAJOR_CIVS-1]:GetTeam())

EDIT: To correct MAX_PLAYERS
 
I tied this once - it resulted in very little (it didn't work). But I could have done it wrong. The problem seemed to be that the internal code (which I haven't tracked down) was treating barbs differently than regular teams.

maybe its because barbs have id = 63 (in my test game it is so)
while max_major_civs -1 is 31 i believe

will test more to see how peaceful barbs will behave
i want to use this effect for a wonder

thanks for the Game.GetActivePlayer() :)
 

Attachments

  • 2013-05-16_00001.jpg
    2013-05-16_00001.jpg
    151.7 KB · Views: 85
Could be noon where he is I suppose :)

And the moral of that is, don't type off the top of your head, left handed, with a sandwich in the other ;)
 
Somewhat related question:

Has anyone tried making multiple barb factions? FFH had this with barbs, animals, pirates & demons, or something like that (or maybe I'm remembering FFH modmods). Then you can have certain civs at peace with certain factions.

I guess these could be assigned to playerIDs 60-63. I'm not sure if this is possible via xml/Lua. You would probably want your own spawning functions anyway and that is easy to do in Lua (I'm assuming the dll functions for that are hard coded to id 63). But I'm not sure how or if it is possible to get them in the game in the first place.
 
Unfortunately the test for "is this a barbarian player" is harded coded as (GetID() == BARBARIAN_PLAYER), so ids 60 to 62 would just appear as minor civs, and their units tend to huddle around the capital
 
Can a minor civ be made to live on without a city? It would be easy enough to keep them at war and keep their units spawning. I don't know how these units would behave in such a situation though.

But I can't remember if the "require complete kills" is only a game option or if it can be applied to a particular civ...
 
You can spawn units for a CS without city, and set them at war with everybody, no problem.

I never paid much attention to their behavior in that case, but IIRC they are able to attack enemy units/cities.
 
You can spawn units for a CS without city, and set them at war with everybody, no problem.

Seems like these "barb" factions would be pretty easy to add then. It is just a minor civ added during setup but never given a starting plot, so player:IsEverAlive()=true and player:IsAlive()=false (I guess the latter goes true when a unit is added).
  • Do you have to set Require Complete Kills for this to work?
  • Do they show up in diplo list UI if they have units but not a city? (easy to fix if yes)
 
Cannot be killed off completely should just be an xml leader UA.

Minor Civs (City States) don't have a Leader (so hence no UA)
 
Minor civs do have a leader according to xml: LEADER_BARBARIAN.

But LEADER_BARBARIAN has no traits given by xml. Is the "cannot be killed" trait hardcoded to that leader, I wonder? Another way they resemble barbs is that meeting them does not trigger a leader screen.
 
Seems like these "barb" factions would be pretty easy to add then. It is just a minor civ added during setup but never given a starting plot, so player:IsEverAlive()=true and player:IsAlive()=false (I guess the latter goes true when a unit is added).
  • Do you have to set Require Complete Kills for this to work?
  • Do they show up in diplo list UI if they have units but not a city? (easy to fix if yes)
I think you need the "complete kills" only if you want to have the human player to survive after losing it last city, for AI you can resurrect them at will.

They are in the diplo list.

But minor civs do have a leader according to xml: LEADER_BARBARIAN.

But LEADER_BARBARIAN has no traits given by xml. Is the "cannot be killed" trait hardcoded to that leader, I wonder? Another way they resemble barbs is that meeting them does not trigger a leader screen.

give the barbarian a city, click the city flag and meet the barbarian leader "empty gray screen"

Long time I haven't tried that, I don't know if it's still working, but I think you may be able to set a scene for the barbarian leader...

I've already prepared a Conan background just in case ;)
 
Must not type while eating/cooking!

What I meant ... individual CSes do not have leaders, so if you gave the leader of players 60 to 62 a trait, all the CSes would get it IIRC

Anyway, if you add 40 CSes to a tiny map, you will find lots of CS settlers standing around as they can't build cities, so I'm guessing CSes always have that trait anyway (or perhaps it only triggers if you lose your last city, and if you never have a city you never lose it ... if that makes sense)
 
Back
Top Bottom