How to get "notification" of yield gained for killing a unit?

g02703

Chieftain
Joined
Apr 2, 2016
Messages
33
After we get the Survivalism virtue in the Might tree, when we kill an alien, we see the research beaker icon pop up (scroll up) along with +n where n is science gained equal to a percentage of that killed alien's strength, on the tile that we killed the alien.

I have a similar script, but instead of science, I award culture for killing aliens. I'll show the code for this because I think you'll find it very useful:

Spoiler :

function OnAlienKilled(playerId, killedPlayerId, unitTypeKey)

local player = Players[playerId]

if (player:IsEverAlive() and player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_MY_SPONSOR"]) then

local unit = GameInfo["Units"][unitTypeKey]

if ((unit ~= nil) and unit.AlienLifeform) then
player:ChangeCulture((unit.Combat + unit.RangedCombat) * 0.5)
end
end
end

GameEvents.UnitKilledInCombat.Add(OnAlienKilled);


I assume that player:ChangeCulture(...) would automatically pop up the culture icon with the yield. The culture count does change as expected, which is great. But what, if it applies, script do I write to also get the on-tile "notification-animation" that, for example, I gained 56 culture (I don't remember the exact number) for killing a siege worm? I'm not talking about the notifications that show up on the lower-right hand side of the screen (like "city has grown" or "intruder alert").

Please feel free to use the above code in case you need to award yields based on the unit that you kill and/or the faction it belonged to, instead of a flat value (which is provided in modding a part of the XML).
 
There is actually an XML entry for that. It's culturefrombarbariankills, or something like that. I tested it yesterday and it does work, it just doesn't automatically update the policy help text, you have to do that manually. But it does do what you are describing.

For future reference, I've found quite a few entries in the policy tables do not update the policy description but do work, such as culturepertechresearched.
 
Is CultureFromBarbarianKills flat number (which would be the same for all killed aliens) or percent of alien's strength?

If I wanted to factor in (for example) my number of cities or whether I researched a particular tech or not, to determine how much culture to award per kill, I think I would need the script.
 
It's just the percentage of the alien's strength. You would need the script for that, but I'm not sure you would be able to get the culture to appear in the way you want. You may just have to be content with a normal notification.
 
Top Bottom