I use William Howard's BNW lua API presented as if it were xml-code. He has it in the civ5 references and tutorials. It is up to date with all the BNW API for units, cities, players, teams, etc., as well as all the BNW hooks for the GameEvents stuff, and what arguments are passed.
He dumped all this info into a "mod" as it were with xml files for each of the object-types: one for Player methods, one for Unit methods, etc. You can use Notepad or Notepad++ to search through these files, or simply to browse through them.
The PlayerDoTurn hook, for example, only passes one argument from the gamecore to functions "hooked" to it:
Code:
<event name="PlayerDoTurn" type="Hook">
<arg pos="1" type="PlayerTypes" name="ePlayer"/>
</event>
"e" in the name fields signifies that Firaxis is passing an integer value that will conform to a Player ID# from the lua "Players" table, an Improvement ID # from the database, etc.
Just remember that Player ID# as used in Civ5 lua does not equal the <Civilizations> table ID # for any given civilization registered within the game's SQL/XML database.
-----------------------------------
In your code you never defined
pPlayer within your function, so you would get runtime errors from attempting to "index" a nil value. Otherwise you would be more or less on the right track with the last bit of code you posted, however I would also define the promotion variables outside the function, since you are going to be referring to the same info multiple times per turn and per game
Code:
local tupamarosID = GameInfoTypes["UNIT_TUPAMAROS"]
local TupamaroShock1 = GameInfoTypes["PROMOTION_SHOCK_1"]
local TupamaroShock2 = GameInfoTypes["PROMOTION_SHOCK_2"]
local TupamaroShock3 = GameInfoTypes["PROMOTION_SHOCK_3"]
function TupamarosBoosts(iPlayer)
local pPlayer = Players[iPlayer]
if (pPlayer:GetLateGamePolicyTree() ~= -1) then
for pUnit in pPlayer:Units() do
if pUnit:GetUnitType() == tupamarosID then
if (pPlayer:GetLateGamePolicyTree() == pPlayer:GetPublicOpinionPreferredIdeology() ) then
-- Tupamaros boost Shock 1
pUnit:SetHasPromotion(TupamaroShock1, true)
pUnit:SetHasPromotion(TupamaroShock2, false)
pUnit:SetHasPromotion(TupamaroShock3, false)
else
-- Tupamaros boost Shock 3
pUnit:SetHasPromotion(TupamaroShock1, true)
pUnit:SetHasPromotion(TupamaroShock2, true)
pUnit:SetHasPromotion(TupamaroShock3, true)
end
end
end
end
end
GameEvents.PlayerDoTurn.Add(TupamarosBoosts)
I would also add a check in there right after defining "pPlayer" for whether or not
pPlayer:GetCivilizationType() matches up to
GameInfoTypes["CIVILIZATION_WHATEVERS"] before even doing anything else.
----------------------------------------
The problem I see with using the Shock series of promotions is that these are standard selectable promotions, and you most likely in many cases be punishing the player by taking away earned and selected promotions form these units. When lua removes a promotion from a unit, this does not affect the unit's accumulated experience points or experience "level", so you can theorectically end up with units that had previousy "earned" their way to having Shock 3, and now must gain an inordinate number of additional XP points in order to select another promotion as compared to a unit that did not have Shock 2 and Shock 3 taken away from it.