New COLLECTION, EFFECT, REQUIREMENT Types in Recent Patch & new LUA

Gleb Bazov

Warlord
Joined
Feb 13, 2017
Messages
176
The following are the new types included with the most recent patch in GameEffects.xml:

COLLECTIONS

<Row Type="COLLECTION_ALL_CAPTURED_CITIES" Kind="KIND_COLLECTION"/>
<Row Type="COLLECTION_PLAYER_CAPTURED_CITIES" Kind="KIND_COLLECTION"/>
<Row Type="COLLECTION_TEAM_CAPTURED_CITIES" Kind="KIND_COLLECTION"/>

EFFECTS

<Row Type="EFFECT_ADD_DIPLOMATIC_MOVEMENT_MODIFIER" Kind="KIND_EFFECT"/>
<Row Type="EFFECT_ADJUST_PLAYER_IMPROVED_ROUTE_LEVEL" Kind="KIND_EFFECT"/>
<Row Type="EFFECT_ADJUST_PLAYER_MAX_WARMONGER_PERCENT" Kind="KIND_EFFECT"/>
<Row Type="EFFECT_ADJUST_PLAYER_NO_OCCUPATION_PENALTIES" Kind="KIND_EFFECT"/>
<Row Type="EFFECT_ADJUST_UNIT_DAMAGE" Kind="KIND_EFFECT"/>
<Row Type="EFFECT_DIPLOMACY_AGENDA_OPPORTUNIST" Kind="KIND_EFFECT"/>
<Row Type="EFFECT_DIPLOMACY_AGENDA_SHORT_LIFE_GLORY" Kind="KIND_EFFECT"/>

REQUIREMENTS

<Row Type="REQUIREMENT_PLAYER_HAS_GREAT_PERSON" Kind="KIND_REQUIREMENT"/>
<Row Type="REQUIREMENT_PLAYER_HAS_CIVIC" Kind="KIND_REQUIREMENT"/>
<Row Type="REQUIREMENT_UNIT_HAS_ABILITY" Kind="KIND_REQUIREMENT"/>

And some interesting new event hooks and functions included in AlexaderScenario.lua

LUA

Event Hooks

GameEvents.CityConquered.Add(OnCityConquered);
Arguments: (UnitOwner, unitID)

GameEvents.OnUnitRetreated.Add(OnUnitRetreated);
Arguments: (capturerID, ownerID, cityID , cityX, cityY)

Declare War on Player function

Players[]:GetDiplomacy(); DeclareWarOn();
DeclareWarOn(X) calls for -- local X = Players[PlayerID]

Grant Great Person function

Game.GetGreatPeople():GrantPerson(individual, class, era, cost, 0, false)

local individual = GameInfo.GreatPersonIndividuals["GREAT_PERSON_INDIVIDUAL_ALEXANDER"].Hash;
local class = GameInfo.GreatPersonClasses["GREAT_PERSON_CLASS_GENERAL"].Hash;
local era = GameInfo.Eras["ERA_CLASSICAL"].Hash;
local cost = 0;

Grant Units in a Valid Adjacent Hex

UnitManager.InitUnitValidAdjacentHex(PlayerID, "UNIT_X", cityX, cityY, numberUnits);

ID Great Person

Unit:GetGreatPerson():GetIndividualHash();
(apparently valid in InScript Context)

Kill Function elaborated

local unit = player:GetUnits():FindID(unitID);
UnitManager.Kill(unit,false);
 
Last edited:
Hi guys,

Has anyone gotten the UnitManager methods working in a mod? I've tried everything I can think of and all cause a crash to desktop, ie:

UnitManager.InitUnitValidAdjacentHex(playerId, unitIndex, startPlot:GetX(), startPlot:GetY(), 2);

and

local placedUnit = UnitManager.InitUnit(playerId, unitIndex, availablePlot:GetX(), availablePlot:GetY());

A few of the new DLC use these and the only thing I can glean from that is that they have an include (include "SupportFunctions.lua" or include("SupportFunctions"); depending on the dev(s) who created them) in the relevant lua, but I've tried those both and still the crash; and that the methods invoking them are defined as local, I haven't yet converted my test mod to try that. The modinfo files do not contain any base dependencies either as far as I can tell that would be required.

I know how to use the traditional methods to accomplish what these do so the question is academic, just be nice to be rid of a lot of laborious code.


Thank you.
 
are you calling InitUnit and InitUnitValidAdjacentHex in gameplay script or UI context ?

AFAIK they are not available in UI context.
 
to create a settler at a given plot
Code:
local iSettler = GameInfo.Units["UNIT_SETTLER"].Index
local pPlayer = Players[iPlayer]
local pPlayerUnits = pPlayer:GetUnits()
pPlayerUnits:Create(iSettler, iX, iY)
to kill a unit defined as "pUnit" from within the set of unitmembers within pPlayerUnits:
Code:
pPlayerUnits:Destroy(pUnit)
When you create a combat unit you cannot set its promotion level, however, all you can do is give it XP or specific promotions. But if the XP exceeds that needed for the 1st level this excess is wasted, and you still can only get one promotion through the usual game-mechanics for promoting a unit.

----------------------------------------

I don't use the UnitManager for anything in my GameplayScripts and have never had trouble. If I am concerned the plot I want to use is already occupied (by a friendly or enemy unit) I run a check on the targetted plot to see if there are any units there:
Code:
function PlotHasUnits(pPlot)
	local unitList:table = Units.GetUnitsInPlotLayerID( pPlot:GetX(), pPlot:GetY(), MapLayers.ANY );
	if unitList ~= nil then
		--print("table unitList for the plot is not nil")
		for i, pUnit in ipairs(unitList) do
			local tUnitDetails = GameInfo.Units[pUnit:GetType()]
			if tUnitDetails ~= nil then
				return true
			end
		end
	end
	return false
end
If there are units then I run a scan on adjacent plots for a safe place to stick the unit, but I don't have a pre-packaged routine for that.

(hmm. it's been a while since I looked at that scan for a unit in a plot. It could probably use a little rework. I was planning to expand it to account for whether the unit was combat, Air, Sea, whatever, but never got around to it. That's why I was grabbing the tUnitDetails)
 
Last edited:
Yes doing a similar thing (see mod files above), I had planned to update to allow stackable units (ie builders) to override the
GetUnitsInPlotLayerID test, but the new methods UnitManager.InitUnitValidAdjacentHex (and UnitManager.InitUnit) seem to handle that and make our lives easier, in a single line of code. Just can't get them working.
 
well one thing is that Firaxis is using the Unit Type name directly everywhere they use UnitManager.InitUnitValidAdjacentHex
Code:
UnitManager.InitUnitValidAdjacentHex(capturerID, "UNIT_GREEK_HOPLITE", cityX, cityY, 1);
It may be a case where the dll is not written to accept either a unit name directly or a unit index number and only accepts the unit name.
 
Is there a Requirementtype for ‘entering a new era’. For example each time I enter a new era I gain something.
 
Top Bottom