1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[BNW] [Help] Earning Science from Kills UA

Discussion in 'Civ5 - SDK / LUA' started by Harkodos, Aug 12, 2018.

  1. Harkodos

    Harkodos Warlord

    Feb 9, 2016
    Hello all, I'm currently working out a bug with a unique ability I'm programming for one of my Civs. Basically I've programmed an ability where they earn Science from killing enemy units, and the code works flawlessly, except with one key quirk: whenever the player or AI is not currently researching a technology and they trigger the ability, the game will crash. So what I need is to program a tag or something that tells the game when a player is not currently researching anything, to instead take the science yield that the player would receive and store it in memory until they actually do trigger the ability while they are researching.

    Here's the current state of my attempt to create a solution:
    function ScienceOnKill(iKiller, iKilled, iUnitType)
        local pPlayer = Players[iKiller]
        local iCombatValue = GameInfo.Units[iUnitType].Combat
        if pPlayer:GetCivilizationType() == iUniqueCiv then
            if iCombatValue and iCombatValue > 0 then
                iScienceYield = (math.ceil(iCombatValue * iKillValueYieldMod));
                local currentResearch = pPlayer:GetCurrentResearch();
                local researchCost = pPlayer:GetResearchCost();
                local researchProgress = pPlayer:GetResearchProgress();
                if currentResearch then
                    if researchCost > researchProgress then
                        print("Can add Science to Research Progress");
                        local teamTechs = Teams[pPlayer:GetTeam()]:GetTeamTechs();
                            iScienceYield = iScienceYield + iCarryOverYield;
                        if (researchProgress + iScienceYield) > researchCost then
                            researchProgress = researchCost;
                            iCarryOverYield = 0;
                            teamTechs:ChangeResearchProgress(currentResearch, iScienceYield, pPlayer);
                            iCarryOverYield = 0;
                        iCarryOverYield = iCarryOverYield + iScienceYield;
                    iCarryOverYield = iCarryOverYield + iScienceYield;
    So, there's my current situation (I know some of what I've programmed may be redundant, I'm just trying to find a solution that works).

    Any thoughts?

    Found a solution (it's a bit cumbersome and rigid, but it works). No more crashes as of right now.
    Last edited: Aug 12, 2018

Share This Page