[BNW] Need help with City Capture detection [Lua]

Realfail

Chieftain
Joined
Jun 16, 2017
Messages
4
I want to make a UA that forces the player's unhappiness to 20 unless they capture a city every 30 turns. My problem is that I don't know how to check is pPlayer has captured a city, can you help?

Code:
function Smash(PlayerID)
    print("UA")
    local pPlayer = Players[playerID]
    local Turn = Game.GetGameTurn()
    local Capture = false
        if (pPlayer:IsAlive() and (not pPlayer:IsMinorCiv()) and (not pPlayer:IsBarbarian())) then
        -- Check if a city has been captured by player --
        if (Turn == 30 and (not Capture) ) then
        pPlayer:SetHappiness(-20)
        else
        Turn = Turn - pPlayerCity.GetTurnAcquired
        Capture = false
    end
end
GameEvents.PlayerDoTurn.Add(Smash)
 
Use GameEvents.CityCaptureComplete rather than PlayerDoTurn.
E.g.
Code:
function GimmeYourLunchMoneyOrIGetSad(iOldPlayer,bCapital,iX,iY,iNewOwner,iOldPop,bConquest)
      --iOldPlayer: ID of the old owner of the city
      --bCapital: Whether the conquered city was a capital city
      --iX,iY: X and Y coordinates of the city
      --iNewOwner: ID of the new owner of the city
      --iOldPop: The population of the city prior to capturing it
      --bConquest: false if the city was acquired in something like a peace (or other trade) deal

      --Execute the code here;
end
GameEvents.cityCaptureComplete.Add(GimmeYourLunchMoneyOrIGetSad)

Keep in mind that pPlayer:SetHappiness(-20) might have weird results/might not work at all. E.g. Assuming it works, what happens if the player captures a city 31 turns in? Does he get his happiness back? If so, do you know how much he had? Just some thoughts :)
 
Back
Top Bottom