Skip to content

MissionScriptsDynamicStates

Rey edited this page Oct 11, 2017 · 7 revisions

States

All states parameters are numeric and get mapped to unit/house types according to default tables used in DAT scripts.

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

    if States.PlayerCount > 5 then
      A := States.UnitCount(1);
Ver
sion
State Description Parameters
and types
Returns
6216 ClosestGroup
Returns the group of the specified player and group type that is closest to the specified coordinates, r -1 if no such group was found. If the group type is -1 any group type will be accepted
aPlayer: Integer;
X: Integer;
Y: Integer;
aGroupType: Integer;
Integer // Group ID
6216 ClosestGroupMultipleTypes
Returns the group of the specified player and group types that is closest to the specified coordinates, or -1 if no such group was found. The group types is a "set of Byte", for example [1,3]
aPlayer: Integer;
X: Integer;
Y: Integer;
aGroupTypes: set of Byte; // Set of group types
Integer // Group ID
6216 ClosestHouse
Returns the house of the specified player and house type that is closest to the specified coordinates, or -1 if no such house was found. If the house type is -1 any house type will be accepted
aPlayer: Integer;
X: Integer;
Y: Integer;
aHouseType: Integer;
Integer // House ID
6216 ClosestHouseMultipleTypes
Returns the house of the specified player and house types that is closest to the specified coordinates, or -1 if no such house was found. The house types is a "set of Byte", for example [11,13,21]
aPlayer: Integer;
X: Integer;
Y: Integer;
aHouseTypes: set of Byte; // Set of house types
Integer // House ID
6216 ClosestUnit
Returns the unit of the specified player and unit type that is closest to the specified coordinates, or -1 if no such unit was found. If the unit type is -1 any unit type will be accepted
aPlayer: Integer;
X: Integer;
Y: Integer;
aUnitType: Integer;
Integer // Unit ID
6216 ClosestUnitMultipleTypes
Returns the unit of the specified player and unit types that is closest to the specified coordinates, or -1 if no such unit was found. The unit types is a "set of Byte", for example [0,9]
aPlayer: Integer;
X: Integer;
Y: Integer;
aUnitTypes: set of Byte; // Set of unit types
Integer // Unit ID
6602 ConnectedByRoad
Check if two tiles are connected by walkable road
X1: Integer; // left coordinate
Y1: Integer; // top coordinate
X2: Integer; // right coordinate
Y2: Integer; // bottom coordinate
Boolean // Connected
6602 ConnectedByWalking
Check if two tiles are connected by a walkable route
X1: Integer; // Left coordinate
Y1: Integer; // Top coordinate
X2: Integer; // Right coordinate
Y2: Integer; // Bottom coordinate
Boolean // Connected
5097 FogRevealed
Check if a tile is revealed in fog of war for a player
aPlayer: Byte;
aX: Word;
aY: Word;
Boolean // Revealed
5057 GameTime
Get the number of game ticks since mission start
Cardinal // Ticks (~10 per second)
5057 GroupAt
Returns the ID of the group of the unit on the specified tile or -1 if no group exists there
aX: Word;
aY: Word;
Integer // Group ID
5272 GroupColumnCount
Returns the number of columns (units per row) of the specified group
aGroupID: Integer; Integer // Column count
5057 GroupDead
Returns true if the group is dead (all members dead or joined other groups)
aGroupID: Integer; Boolean // Dead
6523 GroupIdle
Returns true if specified group is idle (has no orders/action)
aGroupID: Integer; Boolean // Idle
5057 GroupMember
Returns the unit ID of the specified group member. Member 0 will be the flag holder, 1...!GroupMemberCount-1 will be the other members (0 <= !MemberIndex <= !GroupMemberCount-1)
aGroupID: Integer;
aMemberIndex: Integer;
Integer // Unit ID
5057 GroupMemberCount
Returns the total number of members of the specified group
aGroupID: Integer; Integer // Member count
5057 GroupOwner
Returns the owner of the specified group or -1 if Group ID invalid
aGroupID: Integer; Integer // Player ID
5932 GroupType
Returns the type of the specified group or -1 if Group ID invalid
aGroupID: Integer; Integer // Group type
5057 HouseAt
Returns the ID of the house at the specified location or -1 if no house exists there
aX: Word;
aY: Word;
Integer // House ID
6516 HouseBarracksRallyPointX
Returns X coordinate of Rally Point of specified barracks or 0 if BarracksID is invalid
aBarracks: Integer; Integer // X coordinate
6516 HouseBarracksRallyPointY
Returns Y coordinate of Rally Point of specified barracks or 0 if BarracksID is invalid
aBarracks: Integer; Integer // Y coordinate
6285 HouseBuildingProgress
Returns building progress of the specified house
aHouseID: Integer; Word // Building progress
5993 HouseCanReachResources
Returns true if the specified house can reach the resources that it mines (coal, stone, fish, etc.)
aHouseID: Integer; Boolean // Reachable
5057 HouseDamage
Returns the damage of the specified house or -1 if House ID invalid
aHouseID: Integer; Integer // House damage
5057 HouseDeliveryBlocked
Returns true if the specified house has delivery disabled
aHouseID: Integer; Boolean // Blocked
5057 HouseDestroyed
Returns true if the house is destroyed
aHouseID: Integer; Boolean // Destroyed
5057 HouseHasOccupant
Returns true if the specified house currently has an occupant
aHouseID: Integer; Boolean // Has occupant
5345 HouseIsComplete
Returns true if the specified house is fully built
aHouseID: Integer; Boolean
5057 HouseOwner
Returns the owner of the specified house or -1 if House ID invalid
aHouseID: Integer; Integer // Player ID
5057 HousePositionX
Returns the X coordinate of the specified house or -1 if House ID invalid
aHouseID: Integer; Integer // X coordinate
5057 HousePositionY
Returns the Y coordinate of the specified house or -1 if House ID invalid
aHouseID: Integer; Integer // Y coordinate
5057 HouseRepair
Returns true if the specified house has repair enabled
aHouseID: Integer; Boolean // Repair enabled
5057 HouseResourceAmount
Returns the amount of the specified resource in the specified house
aHouseID: Integer;
aResource: Integer;
Integer // Number of resources
5165 HouseSchoolQueue
Returns the unit type in the specified slot of the school queue. Slot 0 is the unit currently training, slots 1..5 are the queue.
aHouseID: Integer;
QueueIndex: Integer; // Queue index (0..5)
Integer // Unit type
6510 HouseSiteIsDigged
Returns true if specified WIP house area is digged
aHouseID: Integer; Boolean // Digged
5057 HouseType
Returns the type of the specified house
aHouseID: Integer; Integer // House type
6284 HouseTypeMaxHealth
Returns max health of the specified house type
aHouseType: Integer; Word // Max health
6001 HouseTypeName
Returns the the translated name of the specified house type. Note: To ensure multiplayer consistency the name is returned as a number encoded within a markup which is decoded on output, not the actual translated text. Therefore string operations like !LowerCase will not work.
aHouseType: Byte; AnsiString // House type name
5345 HouseTypeToOccupantType
Returns the type of unit that should occupy the specified type of house, or -1 if no unit should occupy it.
aHouseType: Integer; Integer // Unit type
6220 HouseUnlocked
Returns true if the specified player can build the specified house type (unlocked and allowed).
aPlayer: Word;
aHouseType: Word;
Boolean // House unlocked
5099 HouseWareBlocked
Returns true if the specified ware in the specified storehouse or barracks is blocked
aHouseID: Integer;
aWareType: Integer;
Boolean // Ware blocked
5165 HouseWeaponsOrdered
Returns the number of the specified weapon ordered to be produced in the specified house
aHouseID: Integer;
aWareType: Integer;
Integer // Number of ordered weapons
5099 HouseWoodcutterChopOnly
Returns true if the specified woodcutter's hut is on chop-only mode
aHouseID: Integer; Boolean // Chop-only
5345 IsFieldAt
Returns true if the specified player has a corn field at the specified location. If player index is -1 it will return true if any player has a corn field at the specified tile
aPlayer: Shortint;
X: Word;
Y: Word;
Boolean // Is field
5345 IsRoadAt
Returns true if the specified player has a road at the specified location. If player index is -1 it will return true if any player has a road at the specified tile
aPlayer: Shortint;
X: Word;
Y: Word;
Boolean // Is road
5345 IsWinefieldAt
Returns true if the specified player has a winefield at the specified location. If player index is -1 it will return true if any player has a winefield at the specified tile
aPlayer: Shortint;
X: Word;
Y: Word;
Boolean // Is winefield
6216 KaMRandom
Returns a random single (float) such that: 0 <= Number < 1.0
Single // Decimal number 0.0 to 1.0
6216 KaMRandomI
Returns a random integer such that: 0 <= Number
aMax:Integer: ; Integer // Number 0 to aMax
6611 LocationCount
Returns the number of player locations available on the map (including AIs), regardless of whether the location was taken in multiplayer (use !PlayerEnabled to check if a location is being used)
Integer // Number of locations
6613 MapHeight
Returns the height of the map
Integer // Height
6587 MapTileHeight
Returns the height of the terrain at the top left corner (vertex) of the tile at the specified XY coordinates.
X: Integer;
Y: Integer;
Integer // Height (0..100)
6587 MapTileObject
Returns the terrain object ID on the tile at the specified XY coordinates. Object IDs can be seen in the map editor on the objects tab. Object 61 is "block walking". If there is no object on the tile, the result will be 255.
X: Integer;
Y: Integer;
Integer // Object type (0..255)
6587 MapTileRotation
Returns the rotation of the tile at the specified XY coordinates.
X: Integer;
Y: Integer;
Integer // Rotation (0..3)
6587 MapTileType
Returns the tile type ID of the tile at the specified XY coordinates. Tile IDs can be seen by hovering over the tiles on the terrain tiles tab in the map editor.
X: Integer;
Y: Integer;
Integer // Tile type (0..255)
6613 MapWidth
Returns the width of the map
Integer // Width
6287 MarketFromWare
Returns type of !FromWare in specified market, or -1 if no ware is selected
aMarketID: Integer; Integer // Ware type
6217 MarketLossFactor
Returns the factor of resources lost during market trading, used to calculate the !TradeRatio (see explanation in MarketValue). This value is constant within one KaM Remake release, but may change in future KaM Remake releases
Single // Loss factor
6287 MarketOrderAmount
Returns trade order amount in specified market
aMarketID: Integer; Integer // Order amount
6287 MarketToWare
Returns type of !ToWare in specified market, or -1 if no ware is selected
aMarketID: Integer; Integer // Ware type
6216 MarketValue
Returns the relative market value of the specified resource type, which is a rough indication of the cost to produce that resource. These values are constant within one KaM Remake release, but may change in future KaM Remake releases. The !TradeRatio is calculated as: MarketLossFactor * MarketValue(To) / (MarketValue(From). If the !TradeRatio is >= 1, then the number of From resources required to receive 1 To resource is: Round(TradeRatio). If the trade ratio is < 1 then the number of To resources received for trading 1 From resource is: Round(1 / TradeRatio)
aRes: Integer; Single // Value
5057 PeaceTime
Length of peacetime in ticks (multiplayer)
Cardinal // Ticks (~10 per second)
5057 PlayerAllianceCheck
Check how player 1 feels towards player 2 (order matters). Returns true for ally, false for enemy
aPlayer1: Byte;
aPlayer2: Byte;
Boolean // Allied
4758 PlayerColorText
Get players color as text in hex format
aPlayer: Byte; AnsiString // Player color
5057 PlayerDefeated
See if player was defeated
aPlayer: Byte; Boolean // Defeated
5057 PlayerEnabled
Will be false if nobody selected that location in multiplayer
aPlayer: Byte; Boolean // Enabled
5209 PlayerGetAllGroups
Returns an array with IDs for all the groups of the specified player
aPlayer: Byte; array of Integer // Array of group IDs
5209 PlayerGetAllHouses
Returns an array with IDs for all the houses of the specified player
aPlayer: Byte; array of Integer // Array of house IDs
5165 PlayerGetAllUnits
Returns an array with IDs for all the units of the specified player
aPlayer: Byte; array of Integer // Array of unit IDs
5927 PlayerIsAI
Wherever player is controlled by AI
aPlayer: Byte; Boolean // Player is AI
5057 PlayerName
Get name of player as a string (for multiplayer)
aPlayer: Byte; AnsiString // Player name
4545 PlayerVictorious
See if player is victorious
aPlayer: Byte; Boolean // Victorious
5345 PlayerWareDistribution
Returns the ware distribution for the specified resource, house and player
aPlayer: Byte;
aWareType: Byte;
aHouseType: Byte;
Byte // Ware distribution [0..5]
6323 StatAIDefencePositionsCount
How many defence positions AI player has. Useful for scripts like "if not enough positions and too much groups then add a new position"
aPlayer: Byte; Integer // Defence position count
5057 StatArmyCount
How many military units player has
aPlayer: Byte; Integer // Army count
5057 StatCitizenCount
How many citizen player has
aPlayer: Byte; Integer // Citizen count
6328 StatHouseMultipleTypesCount
Returns number of specified house types for specified player.
aPlayer: Byte;
aTypes: set of Byte; // House types eg. [11, 13, 21]
Integer // Total number of houses
5057 StatHouseTypeCount
Returns the total number of the specified house type for the specified player.
aPlayer: Byte;
aHouseType: Byte;
Integer // Number of houses
6313 StatHouseTypePlansCount
Specified house type plans count
aPlayer: Byte;
aHouseType: Byte;
Integer // Number of plans
5057 StatPlayerCount
How many active players there are.
Integer // Number of players
5057 StatResourceProducedCount
Returns the number of the specified resource produced by the specified player
aPlayer: Byte;
aResType: Byte;
Integer // Number of produced resources
6331 StatResourceProducedMultipleTypesCount
Returns the number of the specified resource types produced by the specified player.
aPlayer: Byte;
aTypes: set of Byte; // Set of ware types eg. [8, 10, 13, 27] for food
Integer // Number of produced resources
4289 StatUnitCount
Returns the number of units of the specified player
aPlayer: Byte; Integer // Number of units
5057 StatUnitKilledCount
Returns the number of the specified unit killed by the specified player
aPlayer: Byte;
aUnitType: Byte;
Integer // Number of killed units
6331 StatUnitKilledMultipleTypesCount
Returns the number of the specified unit types killed by the specified player.
aPlayer: Byte;
aTypes: set of Byte;
Integer // Set of unit types eg. [0, 5, 13]
5057 StatUnitLostCount
Returns the number of the specified unit lost by the specified player
aPlayer: Byte;
aUnitType: Byte;
Integer // Number of lost units
6331 StatUnitLostMultipleTypesCount
Returns the number of the specified unit types lost by the specified player.
aPlayer: Byte;
aTypes: set of Byte; // Set of unit types eg. [0, 5, 13]
Integer // Number of lost units
6328 StatUnitMultipleTypesCount
Returns number of specified unit types for specified player.
aPlayer: Byte;
aTypes: set of Byte; // Set of unit types eg. [0, 5, 13]
Integer // Total number of units
5057 StatUnitTypeCount
Returns number of specified unit type for specified player
aPlayer: Byte;
aUnitType: Byte;
Integer // Number of units
5057 UnitAt
Returns the ID of the unit on the specified tile or -1 if no unit exists there
aX: Word;
aY: Word;
Integer // Unit ID
5057 UnitCarrying
Returns the ware a serf is carrying, or -1 if the unit is not a serf or is not carrying anything
aUnitID: Integer; Integer // Ware type
5057 UnitDead
Returns true if the unit is dead
aUnitID: Integer; Boolean // Dead
5165 UnitDirection
Returns the direction the specified unit is facing
aUnitID: Integer; Integer // Direction (0..7)
5997 UnitHome
Returns the ID of the house which is the home of the specified unit or -1 if the unit does not have a home
aUnitID: Integer; Integer // House ID
5057 UnitHunger
Returns the hunger level of the specified unit as number of ticks until death or -1 if Unit ID invalid
aUnitID: Integer; Integer // Hunger
6523 UnitIdle
Returns true if specified unit is idle (has no orders/action)
aUnitID: Integer; Boolean // Idle
5057 UnitLowHunger
Gives the hunger level when a unit will try to eat in ticks until death
Integer // Hunger in ticks
5057 UnitMaxHunger
Gives the maximum hunger level a unit can have in ticks until death
Integer // Hunger in ticks
5057 UnitOwner
Returns the owner of the specified unit or -1 if Unit ID invalid
aUnitID: Integer; Integer // Player ID
5057 UnitPositionX
Returns the X coordinate of the specified unit or -1 if Unit ID invalid
aUnitID: Integer; Integer // X coordinate
5057 UnitPositionY
Returns the Y coordinate of the specified unit or -1 if Unit ID invalid
aUnitID: Integer; Integer // Y coordinate
5057 UnitsGroup
Returns the group that the specified unit (warrior) belongs to or -1 if it does not belong to a group
aUnitID: Integer; Integer // Group ID
5057 UnitType
Returns the type of the specified unit
aUnitID: Integer; Integer // Unit type
6001 UnitTypeName
Returns the the translated name of the specified unit type. Note: To ensure multiplayer consistency the name is returned as a number encoded within a markup which is decoded on output, not the actual translated text. Therefore string operations like !LowerCase will not work.
aUnitType: Byte; AnsiString // Unit type name
6001 WareTypeName
Returns the the translated name of the specified ware type. Note: To ensure multiplayer consistency the name is returned as a number encoded within a markup which is decoded on output, not the actual translated text. Therefore string operations like !LowerCase will not work.
aWareType: Byte; AnsiString // Ware type name