Retrieving Improvement Info?

daviiadams

Prince
Joined
Jul 7, 2011
Messages
369
Location
London
Is there a quick, easy way to check if a player has built an improvement?

Having scanned through Don's Lua Wiki (very good btw Don :) ) I can see GetImprovementType for Plot, but don't have a clue as to how to make use of that.

I did get GetImprovementCount to do something, but that's just returning zeros at the moment, at least in the way I'd been playing with the code:

Code:
for iImprovement in GameInfo.Improvements() do

   local iImprovementType = iImprovement.Type;
   local pImprovementCount = pPlayer:GetImprovementCount(iImprovementType);

   print(iImprovementType .. " | " .. pImprovementCount);

end

Not that I'm expecting that small bit of Lua to do anything as it stands, just that it happens to be the only bit I've had any luck with - was rather hoping there'd be something along the lines of IsHasImprovement etc lurking somewhere :confused:
 
GetImprovementCount() expects an ID not a Type

Code:
local pPlayer = Players[Game.GetActivePlayer()]

for imp in GameInfo.Improvements() do
  local count = pPlayer:GetImprovementCount(imp.ID)

  if (count > 0) then
    print(string.format("Player %i has %i improvements of type %s", pPlayer:GetID(), count, imp.Type))
  end
end
 
GetImprovementCount() expects an ID not a Type

Code:
local pPlayer = Players[Game.GetActivePlayer()]

for imp in GameInfo.Improvements() do
  local count = pPlayer:GetImprovementCount(imp.ID)

  if (count > 0) then
    print(string.format("Player %i has %i improvements of type %s", pPlayer:GetID(), count, imp.Type))
  end
end

I did try ID, but quite possibly incorrectly in the first place. Will give the code you've put there a go and work it in to what I'm doing.

You'll probably have a fit if/when you see the other 17,000 odd lines of dodgy code I've got on the go atm :p
 
Back
Top Bottom