adaneslavo / More-Unique-Components-for-VP

Adds 3rd and 4th unique component to each civilization.
1 stars 6 forks source link

Agora change help #127

Closed pineappledan closed 6 years ago

pineappledan commented 6 years ago

Need help as to whether this is correct. the promotion is supposed to change the BaseGold value of the unit with the 'PROXENOS' promotion to 3 (all diplomatic units have a BaseGold value of 1).

GameEvents.CombatEnded.Add(Philhellenism)

function ProxenosGold(iPlayer, iUnit, iUnitType, iX, iY) local pPlayer = Players[iPlayer] local pUnit = pPlayer:GetUnitByID(iUnit)

if pUnit:IsHasPromotion(GameInfoTypes.PROMOTION_GREECE_PROXENOS) then
    pUnit:BaseGold == 3
end

end

GameEvents.UnitCreated.Add(ProxenosGold)

Infixo commented 6 years ago

And what is this BaseGold doing or supposed to do?

pineappledan commented 6 years ago

On completing a diplomatic mission, influence with the target city state is increased AND gold income of the empire is increased by (BaseGold)

In effect, every diplomatic unit expended increases gold per turn on empire by 1 (all diplo units have BaseGold=1 by default). This promotion increases that amount to 3.

pineappledan commented 6 years ago

Confirmed that Proxenos promotion is being added to units correctly, but the BaseGold value of the unit is not being updated by the lua script. I don't know what the right syntax is to have the lua update the a value in the Unit table based on if the unit has a promotion

UPDATE Units SET BaseGold = '3' WHERE pUnit:IsHasPromotion(GameInfoTypes.PROMOTION_GREECE_PROXENOS)

anopther possibility is to simply have the gold added onto a dummy building, but then it wouldn't show up in the UI, so doing it the original way is preferable

Infixo commented 6 years ago

There's no function in the DLL (and thus in Lua) that would set this parameter for a specific unit. This field is used very rarely and uses the value from DB.

pineappledan commented 6 years ago

Okie dokie. So it needs to be added via dummybuilding

The problem then becomes how to trigger the event. There is no lua hook for expending on a non-Great person unit. I think the best workaround is to use the hook for unitkilled, then check if it has proxenos promotion, then check if it died in minor civ territory.

There would be the fringe case of an enemy capturing your diplo unit inside a city-state's territory, but that is unlikely, and all that would happen is you would get 2 GPT

pineappledan commented 6 years ago

Second attempt:

    function ProxenosGold(iPlayer, iUnit, iUnitType, iX, iY)
        local pPlayer = Players[iPlayer]
        local pUnit = pPlayer:GetUnitByID(iUnit)

        if pUnit:IsHasPromotion(GameInfoTypes.PROMOTION_GREECE_PROXENOS) then
            local pPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY())
            local pCiv = pPlot:GetOwner()
            local pCapital = pPlayer:GetCapitalCity()
            local pGold = GameInfoTypes.BUILDING_DUMMYGOLD

            if pCiv:IsMinorCiv() then 
                pCapital:SetNumRealBuilding(pGold, (pCapital:GetNumRealBuilding(pGold) + 2))
            end
        end
    end

    GameEvents.UnitPrekill.Add(ProxenosGold)

When unit is killed - checks if unit has proxenos promotion, then checks if unit died in minor civ territory. Then adds 2 gold per turn via dummy buildings in capital

Edit: it didn't work

pineappledan commented 6 years ago

Tried running a version of this lua with no conditions except for the IsHasPromotion(). Still didn't work.

Something is wrong with how I have used the lua hook, perhaps?

Can someone help debug? I think this is the only thing holding back a final release at this point

Infixo commented 6 years ago

Add to Settings.sql:

UPDATE CustomModOptions SET Value = 1 WHERE Name = 'EVENTS_UNIT_PREKILL';

pineappledan commented 6 years ago

That got the trigger working when the diplo unit only checked for the promotion.

The gold ceased to work when the check for pCiv:IsMinorCiv() was added.

Also the prekill lua hook fires twice when the unit is expended, so you set twice the amount of gold defined in the lua... super weird it works like that

Infixo commented 6 years ago

pPlot:GetOwner() returns an ID, not an object. Use Players[] to get pCiv. Then you can call IsMinorCiv. Also, I highly recommend checking the lua.log. It would tell you that you are trying to index a number value.

Also, there is another hook active for CombatEnded.

pineappledan commented 6 years ago

So like this?

    local pPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY())
    local pCiv = Players[pPlot:GetOwner()]

    if pCiv:IsMinorCiv() then
            .....
Infixo commented 6 years ago

Yes, but make sure that GetOwner() returns >= 0. If the plot is unclaimed, it'd return -1, and you'd get an error from Players[-1].

pineappledan commented 6 years ago

Does getting an era even matter? If Players[-1] breaks the code then that is okay, since the code isn't supposed to continue in that case anyways

Otherwise, I'll do this then? local pCiv = Players[math.max(0, pPlot:GetOwner())]

Infixo commented 6 years ago

Getting an error is always bad. It’s not up to any discussion.

pineappledan commented 6 years ago

Still isn't working.... Latest version:

function ProxenosGold(unitOwnerId, unitId, iUnitType, unitX, unitY, bDelay, eKillingPlayer) local pPlayer = Players[unitOwnerId] local pUnit = pPlayer:GetUnitByID(unitId)

if pUnit:IsHasPromotion(GameInfoTypes.PROMOTION_GREECE_PROXENOS) then
    local pPlot = Map.GetPlot(unitX, unitY)
    local pOwner = Players[math.max(0, pPlot:GetOwner())]

    if pOwner:IsMinorCiv() then
        local pCapital = pPlayer:GetCapitalCity()
        local pGold = GameInfoTypes.BUILDING_DUMMYGOLD

        pCapital:SetNumRealBuilding(pGold, (pCapital:GetNumRealBuilding(pGold) + 1))
    end
end

end

GameEvents.UnitPrekill.Add(ProxenosGold)

The lua works if you take out the 'if pOwner:IsMinorCiv() then' check. I tested it with and without the math.max() check, but it doesn't work regardless.

Wasn't able to find anything in the lua.log related to the unit.prekill hook

I tried using 'if pPlot:GetOwner() =>22 then' as the check instead of pOwner:IsMinorCiv(), but that didn't work either. (playerIDs between 22 and 62 are for minor civs. 63 is barbarians)

An alternative for checking which plot is used would be if the code could check how many diplomatic mission actions the unit has left. Missionaries have the number of spreads left exposed to lua via GetSpreadsLeft(). That would be the holy grail, since there would be no way of cheating tricking the lua through unit deletion or unit capture. I'm guessing there isn't anything like that for diplo units though

Infixo commented 6 years ago

What is lua.log saying?

pineappledan commented 6 years ago

Lua.log not much really... (6a) Community Balance Overhaul creates a ton of the same error, but not much else

Is is possible that IsMinorCiv() has to be activated like UnitPrekill had to be?

Infixo commented 6 years ago

Are you using any other mods or just More Uniques? Because if only More Uniques, then you should fix this first: [315739.390] Runtime Error: Assets\DLC\Expansion2\UI\InGame\InGame.lua:1262: attempt to index local 'addinFile' (a nil value) [315739.390] Runtime Error: Error loading Assets\DLC\Expansion2\UI\InGame\InGame.lua.

pineappledan commented 6 years ago

Great Prophet Historical Names (BNW or GK) Version 31 Historical Religions Edit (BNW or GK) Version 45 (1) Community Patch Version 88 (2) Community Balance Overhaul Version 13 (3) City-State Diplomacy Mod for CBP Version 27 (4) C4DF - CBP Version 11 (5) More Luxuries - CBO Edition (5-14b) Version 155 (6a) Community Balance Overhaul - Compatibility Files (EUI) Version 1 Quick Turns Version 10 Reforestation Version 8 More Unique Components for VP Version 30

Infixo commented 6 years ago

Start a new game with just More Uniques and see if the error is still there.

pineappledan commented 6 years ago

Those two errors still occured

Infixo commented 6 years ago

Klepht.lua is added to the project without the VFS flag set. It should be true.

    <Content Include="Greece\Klepth\Klepht.lua">
      <SubType>Lua</SubType>
      <ImportIntoVFS>False</ImportIntoVFS>
    </Content>