SargontheGreat2
Modder
Does anyone know a tag that would allow me to see if a Great Person had been used? Thanks if you can help!
The previous BNW patch (before the current "MP fix" patch) included a number of new Lua hooks, including:
(Hook) GameEvents.GreatPersonExpended(playerId, eGreatPersonType);
if (eGreatPersonType == GameInfoTypes.UNIT_ENGINEER) then
-- A Great Engineer has been used
end
eGreatPersonType will match GameInfoTypes.UNIT_{something}, eg
Code:if (eGreatPersonType == GameInfoTypes.UNIT_ENGINEER) then -- A Great Engineer has been used end
function PreKillListener(iOwner, iUnit, iUnitType, iX, iY, bDelay, iKiller)
print("prekillListener: Dumping data..")
print("iOwner: " .. iOwner)
print("iUnit: " .. iUnit)
print("iUnitType: " .. iUnitType .. " (" .. GameInfo.Units[iUnitType].Type .. ")")
print("iX: " .. iX)
print("iY: " .. iY)
print("bDelay: " .. tostring(bDelay))
-- bDelay returns true before unit is killed (before UnitKilledInCombat) and only has one unit on the plot
-- bDelay returns false after the unit is killed (after UnitKilledInCombat) and an enemy melee unit may be on the same plot at this point
print("iKiller: " .. iKiller)
end
GameEvents.UnitPrekill.Add(PreKillListener)
is there any way to make the GameEvents.UnitPrekill fire just once when a unit is killed
Check bDelay=false, see post #12 here
If you use the CanHaveUpgrade hook to store the id (player+unit) of units that are asking to upgrade you should be able to determine that a unit was "killed" as part of an upgrade process. Clear the store at the start of every players turn. There is a slight risk that you'll run into the use case "unit can upgrade, unit does not upgrade, unit is killed" in the same turn
function DJSH_TagmaRebirth(iOwner, iUnit, iUnitType, iX, iY, bDelay, iKiller)
local player = Players[iOwner]
local otherPlayer = Players[iKiller]
local killedUnit = player:GetUnitByID(iUnit)
local plot = Map.GetPlot(iX, iY)
if killedUnit:IsHasPromotion(GameInfoTypes["PROMOTION_DJSH_TAGMA"]) then
local capCity = player:GetCapitalCity()
local killedUnitExperience = killedUnit:GetExperience()
local killedUnitStrength = killedUnit:GetBaseCombatStrength()
if JFD_GetRandom(1,100) <= 50 then
if bDelay == false then
respawnedUnit = player:InitUnit(iUnitType, capCity:GetX(), capCity:GetY())
respawnedUnit:JumpToNearestValidPlot()
respawnedUnit:ChangeExperience(killedUnitExperience)
respawnedUnit:SetBaseCombatStrength(math.floor(killedUnitStrength + 1))
end
end
end
end
GameEvents.UnitPrekill.Add(DJSH_TagmaRebirth)