How to detect key pressed

PawelS

Ancient Druid
Joined
Dec 11, 2003
Messages
2,811
Location
Poland
Sorry if I'm asking something obvious, but it's not obvious for me: how do I detect in Lua when a specific key (or key combination like ctrl + something) is pressed?

Bonus question: is the 'X' key used for anything in Civ5? If not, I'm going to use it for showing the city limits in my mod.
 
Wasn't the last time I looked, as that's what I use to bring up the pin-board

Code:
function InputHandler(uiMsg, wParam, lParam)
  if (uiMsg == KeyEvents.KeyDown) then
    if (wParam == Keys.X) then
      if (UIManager:GetControl()) then
        print("Control-X detected, activating the pin-board")

        return true
      elseif (UIManager:GetShift()) then
        print("Shift-X detected, toggling pin visibility")

        return true
      end
    end
  end
end
ContextPtr:SetInputHandler(InputHandler)
 
You saved my day as usual :) One more question: how to check if given Plot is eligible for founding a city on it? Is there a function that checks for all conditions (no water, no mountain, not too close to another city etc.), or I need to check them all using separate functions?

I know about the Unit:CanFound function, but I need one that works without a unit (for my "city planning" feature).
 
You saved my day as usual :) One more question: how to check if given Plot is eligible for founding a city on it? Is there a function that checks for all conditions (no water, no mountain, not too close to another city etc.), or I need to check them all using separate functions?

I know about the Unit:CanFound function, but I need one that works without a unit (for my "city planning" feature).
Player:CanFound(int x, int y)

But you'd either have to loop through all players or at least use the active player to determine whether a city can be founded on the tile. If the tile already belongs to a civ only that player would ever get 'true', though.

I don't remember seeing anything directly within Plot methods to answer whether a city can be founded there.
 
Player:CanFound is fine for me, it's an UI feature that helps the human player pick a place to found the next city, so I can use the active player. Thanks!
 
There is an internal canFound() for a plot (it's on the CvSiteEvaluationClasses class) which does all the terrain, etc checks for a plot. The bad news is that there's no direct pPlot Lua API for it, the good news is that it's called as part of pPlayer:CanFound() (you need a player as well as a plot in case of plot ownership).

For fine grain control, you can also use the PlayerCanFoundCity event (requires a modded DLL)
 
Back
Top Bottom