• Civilization 7 has been announced. For more info please check the forum here .

Displaying yields from Unit Kills after the battle (should be simple *in theory)

The_Space_Cows

Chieftain
Joined
Mar 18, 2023
Messages
19
So I've successfully implemented a feature where a player gains Science from enemy unit kills equal to their combat strength, and it does indeed update the progress toward the next technology like I want it to. I want the amount of Science gained to display on the screen after the battle, exactly like it does after you adopt Honor with the amount of Culture or Gold or from Montezuma's unique ability.

I just want a little toast to pop up, "+8 *beakers*", above the tile where the enemy unit was just killed. The No Quitter's Balance Mod has this feature, but I don't know how to de-compile a DLL yet to look at their code.

In case it helps or someone wants to see it, here is my Lua Code:
Code:
function GiveScienceFromKills(iPlayer, iUnit, iUnitType, iX, iY, bDelay, iByPlayer)
    print("Called GiveScienceFromKills")
   
    if (iByPlayer == 63 or iByPlayer == -1) then
        return
    end
    print("Player was not Barbarians")

    local player = Players[iByPlayer]

    if (not player:HasPolicy(GameInfoTypes.POLICY_HONOR_FINISHER)) then
        return
    end
    print("Player has adopted all policies in the Honor tree")

    local research = Teams[player:GetTeam()]:GetTeamTechs()
    local unitCombatStrength = GameInfo.Units[iUnitType].Combat

    research:ChangeResearchProgressTimes100(player:GetCurrentResearch(), 100 * unitCombatStrength);
    print("Added beakers ", unitCombatStrength)

end
GameEvents.UnitPrekill.Add(GiveScienceFromKills)

print("Science from Kills.lua loaded successfully")

I have made use of an event hook from a modded DLL made by Whoward69 (DLL - Various Mod Components) for GameEvents.UnitPrekill

Can anyone help me out or point me in the right direction? This community has been very helpful and supportive, especially considering this game is over ten years old :)
 
Last edited:
As you're using my DLL, you already have

Code:
pPlot:AddPopupMessage(sMessage) -- No delay and default to the current player
pPlot:AddPopupMessage(sMessage, fDelay) -- Default to the current player
pPlot:AddPopupMessage(sMessage, fDelay, iForPlayer)
 
Last edited:
Thank you so much! I got it to work.

What is the parameter fDelay? I would like the popup to happen after the damage, xp, culture, and gold popups have already displayed.

I guess what I'm asking is where is good documentation for all of the methods and changes in your DLL mod? I have a couple forum posts, but I couldn't find those plot functions anywhere in them :/ I think I'm looking in the wrong place.
 
The definitive documentation is the source code. All added events can be found by searching for "gameeventinvoke_" and all added Lua API methods by searching for "luaapiextn"
 
Top Bottom