[Help] Citadel improvement gives xp

XK9Wolfe

Chieftain
Joined
Oct 15, 2015
Messages
12
Hey guys, I've haven't been on this forum in almost 3 years! I've since gone to school for computer science and mathematics and I wanted something fun to code during the winter break, and I tried playing Civ again and remembered everything I wanted to code but didn't have the experience to do. That's changed. :scan:

Any case, I have a simple function I'm trying to code and the only issues I'm running into are syntactical, not logical. Have a look...
Code:
--[[
--  Get player
--  If player is alive then...
--      for each unit in player's units...
--         If this is a combat unit...
--              get the plot the unit is standing on
--              if that unit is on a plot with a citadel improvement
--                  give that unit 3 xp
-- ]]

function CitadelXP(playerID)
    print("CitadelXP is running...")
    local player = Player[playerID]
    if player:IsAlive() then -- If the player is alive...
        for unit in player:Units() do -- for each unit in player's units...
            if unit:GetBaseCombatStrength() > 1 then -- If this is a combat unit...
                local plot = unit:GetPlot() -- get the plot the unit is standing on

            end
        end
    end
end -- of the function

GameEvents.PlayerDoTurn.Add(CitadelXP)

I know the code should be something like this...

Code:
--[[
--  Get player
--  If player is alive then...
--      for each unit in player's units...
--         If this is a combat unit...
--              get the plot the unit is standing on
--              if that unit is on a plot with a citadel improvement
--                  give that unit 3 xp
-- ]]

function CitadelXP(playerID)
    print("CitadelXP is running...")
    local player = Player[playerID]
    if player:IsAlive() then -- If the player is alive...
        for unit in player:Units() do -- for each unit in player's units...
            if unit:GetBaseCombatStrength() > 1 then -- If this is a combat unit...
                local plot = unit:GetPlot() -- get the plot the unit is standing on
                    if plot:GetPlotType() == ImprovementTypes["IMPROVEMENT_CITADEL"] then -- if that unit is on a plot with a citadel improvement
                        unit:ChangeExperience(3) -- give that unit xp
                    end
            end
        end
    end
end -- of the function

GameEvents.PlayerDoTurn.Add(CitadelXP)

but I know this couldn't be right syntactically. Calling "ImprovementTypes" probably isn't a thing, but I'm not sure what is.

If anyone knows how I could amend this, and (more importantly) knows where I can look up Civ V's method calls, I would be very grateful.

Thanks guys, and Happy New Year! :D

EDIT: Perhaps "plot:GetPlot():IsHasImprovementType["IMPROVEMENT_CITADEL"]?"
 
Last edited:
Back
Top Bottom