Player¶
A Player is one player slot: 0 is Gaia, 1 to 8 are players. Get one
with GetAssignedPlayer(), GetPlayerById(id) or object:GetOwningPlayer().
local me = GetAssignedPlayer()
local villagers = me:GetObjectsByClass(UnitClass.VILLAGER)
LogInfo(me:GetPlayerName(), #villagers)
Rules for every method. Calling a method on something that is not a
Player, or with an argument of the wrong type, raises a Lua error. A nil
result means the value could not be read. Some methods return a default such
as 0 or false instead; the tables say which.
a == b is true when two Player values are the same slot, but they are
different table keys: key tables by GetId(). tostring(player) and
LogInfo(player) show Player#2 Name, or Player#? (unreadable).
GetPlayerCount() leaves Gaia out, so a 1v1 reads 2. Loop over 1..count.
About the player¶
Stances are one-way: A can be allied to B while B is enemy to A.
Resources and technology¶
| Method | Returns |
|---|---|
GetAttribute(attribute) |
A stockpile, population or other per-player value; use PlayerAttribute or ResourceType, such as PlayerAttribute.FOOD. |
GetFact(factId[, parameter = 0]) |
A PER fact for this player; use a Fact value. |
CanAfford(objectType) |
true when the player has the resources for one of that type. A second argument is accepted and ignored. |
GetObjectCost(objectType[, multiplier = 1]) |
costs, available; see costs. |
GetTechCost(technology) |
costs, available; see costs. |
CanAffordResearch(technology) |
true when the player has the resources for the technology. |
CanResearch(technology) |
true when the technology is researchable, affordable, and a building that researches it exists. |
GetResearchState(technology) |
A ResearchState value. 0 (LOCKED) if unreadable. |
IsTechnologyResearched(technology) |
true once researched. false if unreadable. |
IsObjectTypeAvailable(objectType) |
true when civilization and age allow the type. false if unreadable. |
Costs¶
GetObjectCost and GetTechCost return two values. The first is an array of
{ resourceId, amount } entries for each resource with a cost, in food, wood,
stone, gold order; each entry also has resourceId and amount fields. The
second is false when the cost could not be read: ignore the array then. An
empty array with true means free.
local costs, available = me:GetObjectCost(UnitObjectType.ARCHER)
if available then
for _, cost in ipairs(costs) do LogInfo(cost.resourceId, cost.amount) end
end
Counting and finding objects¶
Lists are empty when nothing matches or the list cannot be read. The global
GetUnitTypeCount and friends do the same for the assigned player but also
return an availability flag; prefer them when a wrong 0 would matter.
Local screen¶
These read the screen of the person at this computer, not the player you call them on.
GetCivilizationName and GetMouseHoveredObject exist but are
not implemented.