Skip to content

Scripting dynamic states

kromster80 edited this page Jan 3, 2025 · 57 revisions

States

States are queried in a form States.STATE_NAME(STATE_PARAMETERS) like so:

    if States.StatPlayerCount > 5 then
      unitCnt := States.StatUnitCount(1);

Version column description:
"-" Means this state was added from the start.
"5678" Means this state was introduced in revision 5678.
"-5678" Means this state was removed in revision 5678.



Ver
sion
State description Parameters
and types
Returns
8721 CampaignMissionCount
Get total number of missions in the current campaign. Campaign-only action!
Integer
8723 CampaignMissionWon
See if the mission was won. Campaign-only action!
aMission: Integer; // mission index to check Boolean
7969 EntityType
Get the entity type by its UID (0 - unknown or none, 1 - Unit, 2 - House, 3 - UnitGroup, 4 - Stockpile)
aEntityID: Integer; Integer
-8743 FogRevealed
Removed
Method was removed, use PlayerFogRevealed instead
aPlayer: Integer;
aX, aY: Word;
Boolean
- GamePeaceTime
Get the peacetime duration (in game ticks)
Cardinal
- GroupAt
Return UID of a group at requested coordinates
aX, aY: Word; Integer
14898 GroupBannerDisplay
Returns state of the groups banner display. False if the group is already dead
aGroupID: Integer; Boolean
- GroupColumnCount aGroupID: Integer; Integer
- GroupDead
See if the group is dead (all members are dead)
aGroupID: Integer; Boolean
5632 GroupIsIdle
See if the group is idle (ready to take orders)
aGroupID: Integer; Boolean
- GroupMember
Get N-th group member
aGroupID: Integer;
aMemberIndex: Integer;
Integer
- GroupMemberCount
Returns how many member there are in this group
aGroupID: Integer; Integer
- GroupOwner
Returns to which Hand this group belongs
aGroupID: Integer; Integer
14509 GroupType
Returns group type
aGroupID: Integer; TKMGroupType
- HouseAt
Get the house at coordinates
aX, aY: Word; Integer
- HouseDamage
Check house damage
-1 if house does not exist
aHouseID: Integer; Integer
-7015 HouseDeliveryBlocked
Removed
Method was removed, use HouseWareBlock instead
aHouseID: Integer;
aWareType: TKMWareType;
Boolean
- HouseDestroyed aHouseID: Integer; Boolean
-6102 HouseHasOccupant
Removed
Method was removed, use HouseHasWorker instead
aHouseID: Integer;
6102 HouseHasWorker
Check if the house has a worker assigned to it
aHouseID: Integer; Boolean
- HouseIsComplete
Check if house is complete
aHouseID: Integer; Boolean
- HouseOwner
See to which player the house belongs
aHouseID: Integer; Integer
15016 HousePosition
Returns location of the house
X:-1, Y:-1 if house does not exist
aHouseID: Integer; TKMPoint
15016 HousePositionDoorstep
Returns location of the tile in front of the house main entrance, taking house facing direction into account
X:-1, Y:-1 if house does not exist
aHouseID: Integer; TKMPoint
- HousePositionX
-1 if house does not exist
aHouseID: Integer; Integer
- HousePositionY
-1 if house does not exist
aHouseID: Integer; Integer
- HouseRepair
Check if house repair is enabled
aHouseID: Integer; Boolean
13134 HouseSheepyardHasPasture
Check if the sheepyard has a pasture built (fenced area by the back door)
aHouseID: Integer; Boolean
4820 HouseTrainQueuePeek
Get the unit type in the houses training queue (School/Fort/Barracks)
aHouseID: Integer;
QueueIndex: Integer;
TKMUnitType
- HouseType
Get the house type
aHouseID: Integer; TKMHouseType
7021 HouseWareBlock
Lookup spacious house ware delivery policy. Works only for spacious houses (Camp, Fort, Store, Barracks)
aHouseID: Integer;
aWareType: TKMWareType;
Integer // 0 - allow, 1 - block, 2 - evacuate
- HouseWareInside
See the total amount of wares (input and output) in a house
-1 if house does not exist or ware can not be in that house
aHouseID: Integer;
aWareType: TKMWareType;
Integer
15065 HouseWareInType
Get the ware type in the house input
For spacious houses ware types are listed both for input and output
Returns wtNone in case of an error
aHouseType: TKMHouseType;
aIndex: Integer;
TKMWareType
15065 HouseWareInTypeCount
Get the number of ware types in the house input
For spacious houses ware types are listed both for input and output
Returns -1 in case of an error
aHouseType: TKMHouseType; Integer
15065 HouseWareOutType
Get the ware type in the house output
For spacious houses ware types are listed both for input and output
Returns wtNone in case of an error
aHouseType: TKMHouseType;
aIndex: Integer;
TKMWareType
15065 HouseWareOutTypeCount
Get the number of ware types in the house output
For spacious houses ware types are listed both for input and output
Returns -1 in case of an error
aHouseType: TKMHouseType; Integer
10399 HouseWaresBlock
Lookup common ware delivery policy. Works only for common houses
aHouseID: Integer; Integer // 0 - allow, 1 - block
- HouseWeaponsOrdered
Get the amount of weapons ordered in the house
aHouseID: Integer;
aWareType: TKMWareType;
Integer
-15056 HouseWoodcutterChopOnly
Removed
Method was removed, use HouseWoodcutterMode instead
aHouseID: Integer; Boolean
15057 HouseWoodcutterMode
Modes are: -1 for error, 0 - cut and plant, 1 - chop only, 2 - plant only
aHouseID: Integer; Integer
- IsFieldAt
Check if there is a field owned by player at coordinates
aPlayer: Integer; // player to whom field must belong. -1 stands for any player
aX, aY: Word;
Boolean
- IsOrchardAt
Check if there is a orchard owned by player at coordinates
aPlayer: Integer; // player to whom orchard must belong. -1 stands for any player
aX, aY: Word;
Boolean
- IsRoadAt
Check if there is a road owned by player at coordinates
aPlayer: Integer; // player to whom road must belong. -1 stands for any player
aX, aY: Word;
Boolean
14370 PlayerAIDispositionCount
Return how many dispositions AI has
-1 if the player does not exist or is not AI
aPlayer: Integer; Integer
15082 PlayerAIDispositionGet
Returns disposition details
All returned values will be zero if the player does not exist or is not AI, or Index is wrong
aPlayer: Integer;
aIndex: Integer;
out aUID: Integer;
out aX, aY: Integer;
out aDir: Integer;
out aGroupType: TKMGroupType;
out aNumUnits: Integer;
out aUnitsPerRow: Integer;
out aGuardRadius: Integer;
14405 PlayerAIDispositionGroup
Returns group currently assigned to the disposition
Returns zero if the player does not exist or is not AI, or Index is wrong
aPlayer: Integer;
aIndex: Integer;
Integer
15082 PlayerAIDispositionUIDGet
Returns disposition details
All returned values will be zero if the player does not exist or is not AI, or aDispositionUID is unknown
aPlayer: Integer;
aDispositionUID: Integer;
out aX, aY: Integer;
out aDir: Integer;
out aGroupType: TKMGroupType;
out aNumUnits: Integer;
out aUnitsPerRow: Integer;
out aGuardRadius: Integer;
15082 PlayerAIDispositionUIDGroup
Returns group currently assigned to the disposition
Returns zero if the player does not exist or is not AI, or aDispositionUID is unknown
aPlayer: Integer;
aDispositionUID: Integer;
Integer
- PlayerAllianceCheck
Checking alliances with Neutral will always return True (despite some animals being agressive)
aPlayer1: Integer;
aPlayer2: Integer;
Boolean
- PlayerColorText
Get the string with color code of the player (adjusted brighter for text display)
aPlayer: Integer; string
- PlayerDefeated aPlayer: Integer; Boolean
- PlayerEnabled
Check if hand is enabled (chosen to be played by anyone on mission start)
aPlayer: Integer; Boolean
8743 PlayerFogRevealed
See if tile is revealed to the player (known or live)
aPlayer: Integer;
aX, aY: Word;
Boolean
- PlayerGetAllGroups
Get list of all players groups
aPlayer: Integer; TKMIntegerArray
14495 PlayerGetAllGroupsFilter
Get list of all players groups
aPlayer: Integer;
aGroupType: TKMGroupTypeSet;
TKMIntegerArray
- PlayerGetAllHouses
Return all players houses that are not destroyed
aPlayer: Integer; TKMIntegerArray
14892 PlayerGetAllObjectives
Return all players objectives
aPlayer: Integer; TKMIntegerArray
- PlayerGetAllRoads
Get list of all players roads
aPlayer: Integer; // player to whom roads must belong. 0..N-1 TKMPointArray
- PlayerGetAllUnits
Return all players units that are not dead and not in training
aPlayer: Integer; TKMIntegerArray
14495 PlayerGetAllUnitsFilter
Return all players units that are not dead and not in training
aPlayer: Integer;
aUnitTypes: TKMUnitTypeSet;
TKMIntegerArray
12942 PlayerGetHouses
Return all players houses of certain type that are not destroyed
aPlayer: Integer;
aHouseType: TKMHouseType; // house type to return. htAny for all houses
aOnlyCompleted: Boolean; // return only completed houses
TKMIntegerArray
10697 PlayerHouseBlocked
Check if Player has the house type explicitly blocked from being built
aPlayer: Integer;
aHouseType: TKMHouseType;
Boolean
- PlayerHouseCanBuild
Check if Player can build certain house type
aPlayer: Integer;
aHouseType: TKMHouseType;
Boolean
10697 PlayerHouseGranted
Check if Player has the house explicitly granted (allowed to be built
If house is both granted and blocked - it will be blocked
aPlayer: Integer;
aHouseType: TKMHouseType;
Boolean
10470 PlayerIsNeutral
Check if the player is neutral (animals)
aPlayer: Integer; Boolean
- PlayerName
Get the players full name
aPlayer: Integer; string
14892 PlayerObjectiveStatus
Get the objective status
Returns osHidden in case of fail
aPlayer: Integer;
aObjectiveId: Integer;
TKMObjectiveStatus
14892 PlayerObjectiveType
Get the objective type
Returns otMain in case of fail
aPlayer: Integer;
aObjectiveId: Integer;
TKMObjectiveType
- PlayerVictorious aPlayer: Integer; Boolean
- PlayerWareDistribution aPlayer: Integer;
aWareType: TKMWareType;
aHouseType: TKMHouseType;
Byte
- StatArmyCount aPlayer: Integer; Integer
- StatCitizenCount aPlayer: Integer; Integer
- StatHouseTypeCount
Return number of completed houses of specified type that player has at this moment
aPlayer: Integer;
aHouseType: TKMHouseType;
Integer
- StatPlayerCount
See how many enabled players there are in the mission (chosen to be played by anyone on mission start)
Integer
- StatUnitCount
See how many units player has alive
aPlayer: Integer; Integer
- StatUnitKilledCount
See how many units player has killed
aPlayer: Integer;
aUnitType: TKMUnitType;
Integer
- StatUnitLostCount
See how many units player has lost
aPlayer: Integer;
aUnitType: TKMUnitType;
Integer
- StatUnitTypeCount
See how many units of certain type player has alive
aPlayer: Integer;
aUnitType: TKMUnitType;
Integer
5606 StatWaresBalance
See how many wares player has at the moment
aPlayer: Integer;
aWareType: TKMWareType;
Integer
5606 StatWaresProduced
See how many wares were produced by the player
aPlayer: Integer;
aWareType: TKMWareType;
Integer
8785 StatWaresProducedValue
Get total value of all wares produced by player
aPlayer: Integer; Integer
-6683 SysRandom
Removed
Method was removed, use Utils.Random instead
Single
-6683 SysRandomI
Removed
Method was removed, use Utils.RandomI instead
aMax: Integer; Integer
14250 TerrainObjectState
Get the state of the terrain object
If there's no object - default state of 0 is returned
aX, aY: Integer;
aCoord: Byte;
Byte
- UnitAt
Return UID of the unit on requested coordinates
aX, aY: Word; Integer
- UnitCarryCount
See how many wares that unit (porter or wagon) is carrying
aUnitID: Integer;
aWareType: TKMWareType;
Integer
- UnitCarryType
See ware type that unit (porter or wagon) is carrying
aUnitID: Integer; TKMWareType
15556 UnitDamageMax
Returns maximum damage of a unit. 0 if unit can not deal damage. -1 if there's no such unit
aUnitID: Integer; Integer
15556 UnitDamageMin
Returns minimum damage of a unit. 0 if unit can not deal damage. -1 if there's no such unit
aUnitID: Integer; Integer
- UnitDead
Check if unit is dead
aUnitID: Integer; Boolean
- UnitDirection
See unit facing direction (0 .. 7)
-1 if direction is uninitialized
aUnitID: Integer; Integer
4829 UnitGroup
Return UID of a group to which requested Unit belongs
aUnitID: Integer; Integer
14497 UnitHitpoints
See current unit hitpoints
aUnitID: Integer; Integer
14497 UnitHitpointsMax
See maximum unit hitpoints
aUnitID: Integer; Integer
6692 UnitHunger
See unit hunger condition in seconds remaining till death
Result within 0 and 2700 (45min)
aUnitID: Integer; Integer
6692 UnitHungerLow
Return fullness level of a unit when it becomes hungry, in seconds
Integer
6692 UnitHungerMax
Return maximum fullness level of a unit, in seconds
Integer
14492 UnitInHouse
Returns HouseID in which the Unit is now,
-1 if Unit not found
0 if Unit is not in any house
aUnitID: Integer; Integer
- UnitOwner
See unit owner hand
aUnitID: Integer; Integer
- UnitPositionX
Get rounded unit position X
-1 if unit does not exist
aUnitID: Integer; Integer
- UnitPositionY
Get rounded unit position Y
-1 if unit does not exist
aUnitID: Integer; Integer
12430 UnitsAt
Return UIDs of the units within requested coordinates
For convenience, bounds can exceed map coordinates without generating an error
aX1: Integer;
aY1: Integer;
aX2: Integer;
aY2: Integer;
TKMIntegerArray
- UnitType
See unit type
aUnitID: Integer; TKMUnitType