Events are written in a form procedure EVENT_NAME(EVENT_PARAMETERS); like so:
procedure OnHouseBuilt(aHouseID: Integer);
begin
// code
end;
Sometimes we want to make it possible to handle some event in the different procedures. It could be usefull, when we want to make script, which could be easily included into some other script with minimum efforts, as much simple as possible.
Let's say in our includable script we want to do some stuff, when house is built, then we must have OnHouseBuild
procedure. But then there could be an error, if main script (where our script is included) will have same OnHouseBuild
procedure.
That is why we want to have some other procedure, that will be invoked in our script. That could be archived with custom directive {$EVENT}
{$EVENT event_name:event_handler_procedure_name}
where
- event_name - name of the event, made with
evt
prefix, f.e.evtHouseBuilt
- event_handler_procedure_name - name of the procedure, which will be invoked on that event
For example:
{$EVENT evtHouseBuilt:MyCustomOnHouseBuilt}
procedure MyCustomOnHouseBuilt(aHouseID: Integer);
begin
// code
end;
When event happens all event handlers are invoked one after another. Default event handler (f.e. OnHouseBuilt
) is always invoked first. Other custom event handlers invoked in order of declaration by {$EVENT}
directive.
Other scripts functions:
Dynamic scripts usefull info:
- OnBeacon
- OnFieldBuilt
- OnGameSpeedChanged
- OnGroupBeforeOrderSplit
- OnGroupHungry
- OnGroupOrderAttackHouse
- OnGroupOrderAttackUnit
- OnGroupOrderLink
- OnGroupOrderMove
- OnGroupOrderSplit
- OnHouseAfterDestroyed
- OnHouseAfterDestroyedEx
- OnHouseBuilt
- OnHouseDamaged
- OnHouseDestroyed
- OnHousePlanDigged
- OnHousePlanPlaced
- OnHousePlanPlacedEx
- OnHousePlanRemoved
- OnHousePlanRemovedEx
- OnHouseRepaired
- OnHouseWareCountChanged
- OnMarketTrade
- OnMarketTradeEx
- OnMissionStart
- OnPeacetimeEnd
- OnPlanFieldPlaced
- OnPlanFieldRemoved
- OnPlanRoadDigged
- OnPlanRoadPlaced
- OnPlanRoadRemoved
- OnPlanWinefieldDigged
- OnPlanWinefieldPlaced
- OnPlanWinefieldRemoved
- OnPlayerDefeated
- OnPlayerVictory
- OnRoadBuilt
- OnTick
- OnUnitAfterDied
- OnUnitAfterDiedEx
- OnUnitAttacked
- OnUnitDied
- OnUnitTrained
- OnUnitWounded
- OnWareProduced
- OnWarriorEquipped
- OnWarriorWalked
- OnWinefieldBuilt
Ver sion |
Event description | Parameters and types |
---|---|---|
6570 | OnBeacon Occurs when a player places a beacon on the map. |
aPlayer: Integer; aX: Integer; aY: Integer; |
7000+ | OnFieldBuilt Occurs when player built a field. |
aPlayer: Integer; aX: Integer; aY: Integer; |
11000 | OnGameSpeedChanged Occurs when game speed was changed |
aSpeed: Single; |
11200 | OnGroupBeforeOrderSplit Occurs right before the group gets order to split. Split parameters could be altered by script and returned to the game to be used there aNewType: new group leader unit type aNewCnt: new group members count aMixed: is new group can have the only unit type or it can have any unit type from original group |
aGroup: Integer; //group ID, which got split order var aNewType: TKMUnitType; var aNewCnt: Integer; var aMixed: Boolean; |
6220 | OnGroupHungry Occurs when the player would be shown a message about a group being hungry (when they first get hungry, then every 4 minutes after that if there are still hungry group members). Occurs regardless of whether the group has hunger messages enabled or not. |
aGroup: Integer; |
7000+ | OnGroupOrderAttackHouse Occurs when the group gets order to attack house |
aGroup: Integer; //attackers group ID aHouse: Integer; //target house ID |
7000+ | OnGroupOrderAttackUnit Occurs when the group gets order to attack unit |
aGroup: Integer; //attackers group ID aUnit: Integer; //target unit ID |
7000+ | OnGroupOrderLink Occurs when the group1 gets order to link to group2 |
aGroup1: Integer; //link group ID aGroup2: Integer; //link target group ID |
7000+ | OnGroupOrderMove Occurs when the group gets order to move to some point |
aGroup: Integer; //group ID aX: Integer; //Point coordinates aY: Integer; |
7000+ | OnGroupOrderSplit Occurs when the group gets order to split |
aGroup: Integer; //group ID aNewGroup: Integer; //splitted group ID |
6114 | OnHouseAfterDestroyed Occurs after a house is destroyed and has been completely removed from the game, meaning the area it previously occupied can be used. If you need more information about the house use the OnHouseDestroyed event. |
aHouseType: Integer; //HouseType as Integer from Lookup table aOwner: Integer; aX: Integer; aY: Integer; |
14000 | OnHouseAfterDestroyedEx Occurs after a house is destroyed and has been completely removed from the game, meaning the area it previously occupied can be used. If you need more information about the house use the OnHouseDestroyed event. |
aHouseType: TKMHouseType; //HouseType as TKMHouseType aOwner: Integer; aX: Integer; aY: Integer; |
5057 | OnHouseBuilt Occurs when player has built a house. |
aHouse: Integer; |
5882 | OnHouseDamaged Occurs when a house gets damaged (e.g. by the enemy soldier). Attacker is -1 the house was damaged some other way, such as from Actions.HouseAddDamage. |
aHouse: Integer; aAttacker: Integer; |
5407 | OnHouseDestroyed Occurs when a house is destroyed. If DestroyerIndex is -1 the house was destroyed some other way, such as from Actions.HouseDestroy. If DestroyerIndex is the same as the house owner (States.HouseOwner), the house was demolished by the player who owns it. Otherwise it was destroyed by an enemy. Called just before the house is destroyed so HouseID is usable only during this event, and the area occupied by the house is still unusable. |
aHouse: Integer; aDestroyerIndex: Integer; //Index of player who destroyed it |
7000+ | OnHousePlanDigged Occurs when house plan is digged. |
aHouse: Integer; |
5871 | OnHousePlanPlaced Occurs when player has placed a house plan. |
aPlayer: Integer; aX: Integer; aY: Integer; aHouseType: Integer; //HouseType as Integer from Lookup table |
14000 | OnHousePlanPlacedEx Occurs when player has placed a house plan. |
aPlayer: Integer; aX: Integer; aY: Integer; aHouseType: TKMHouseType; //HouseType as TKMHouseType |
6298 | OnHousePlanRemoved Occurs when player has removed a house plan. |
aPlayer: Integer; aX: Integer; aY: Integer; aHouseType: Integer; //HouseType as Integer from Lookup table |
14000 | OnHousePlanRemovedEx Occurs when player has removed a house plan. |
aPlayer: Integer; aX: Integer; aY: Integer; aHouseType: TKMHouseType; //HouseType as TKMHouseType |
13700 | OnHouseRepaired Occurs when a house gets repaired. The event gets fired for each repair action |
aHouse: Integer; //House ID aRepairAmount: Integer; //how much house was repaired aDamage: Integer; //house damage after repairement |
10750 | OnHouseWareCountChanged Occurs when ware count is changed in house |
aHouse: Integer; aWare: TKMWareType; aCnt: Integer; //current ware count in house (after change) aChangeCnt: Integer; //ware change count. if aChangeCnt > 0 count increased, if aChangeCnt < 0 count decreased |
6216 | OnMarketTrade Occurs when a trade happens in a market (at the moment when resources are exchanged by serfs). |
aMarket: Integer; aFrom: Integer; //From, aTo as Integer from Lookup table aTo: Integer; |
14000 | OnMarketTradeEx Occurs when a trade happens in a market (at the moment when resources are exchanged by serfs). |
aMarket: Integer; aFrom: TKMWareType; //From, aTo as TKMWareType aTo: TKMWareType; |
5057 | OnMissionStart Occurs immediately after the mission is loaded. |
|
11000 | OnPeacetimeEnd Occurs immediately after the end of peacetime |
|
5964 | OnPlanFieldPlaced Occurs when player has placed a field plan. |
aPlayer: Integer; aX: Integer; aY: Integer; |
6301 | OnPlanFieldRemoved Occurs when player has removed a field plan. |
aPlayer: Integer; aX: Integer; aY: Integer; |
7000+ | OnPlanRoadDigged Occurs when road plan is digged. |
aPlayer: Integer; aX: Integer; aY: Integer; |
5964 | OnPlanRoadPlaced Occurs when player has placed a road plan. |
aPlayer: Integer; aX: Integer; aY: Integer; |
6301 | OnPlanRoadRemoved Occurs when player has removed a road plan. |
aPlayer: Integer; aX: Integer; aY: Integer; |
7000+ | OnPlanWinefieldDigged Occurs when winefield is digged |
aPlayer: Integer; aX: Integer; aY: Integer; |
5964 | OnPlanWinefieldPlaced Occurs when player has placed a wine field plan. |
aPlayer: Integer; aX: Integer; aY: Integer; |
6301 | OnPlanWinefieldRemoved Occurs when player has removed a wine field plan. |
aPlayer: Integer; aX: Integer; aY: Integer; |
5057 | OnPlayerDefeated Occurs when certain player has been defeated. Defeat conditions are checked separately by Player AI. |
aPlayer: Integer; |
5057 | OnPlayerVictory Occurs when certain player is declared victorious. Victory conditions are checked separately by Player AI. |
aPlayer: Integer; |
7000+ | OnRoadBuilt Occurs when player built a road. |
aPlayer: Integer; aX: Integer; aY: Integer; |
5057 | OnTick Occurs every game logic update. |
|
6114 | OnUnitAfterDied Occurs after a unit has died and has been completely removed from the game, meaning the tile it previously occupied can be used. If you need more information about the unit use the OnUnitDied event. Note: Because units have a death animation there is a delay of several ticks between OnUnitDied and OnUnitAfterDied. |
aUnitType: Integer; //UnitType as Integer from Lookup table aOwner: Integer; aX: Integer; aY: Integer; |
14000 | OnUnitAfterDiedEx Occurs after a unit has died and has been completely removed from the game, meaning the tile it previously occupied can be used. If you need more information about the unit use the OnUnitDied event. Note: Because units have a death animation there is a delay of several ticks between OnUnitDied and OnUnitAfterDied. |
aUnitType: TKMUnitType; //UnitType as TKMHouseType aOwner: Integer; aX: Integer; aY: Integer; |
6587 | OnUnitAttacked Happens when a unit is attacked (shot at by archers or hit in melee). Attacker is always a warrior (could be archer or melee). This event will occur very frequently during battles. |
aUnit: Integer; aAttacker: Integer; //Warrior who attacked the unit |
5407 | OnUnitDied Occurs when a unit dies. If KillerIndex is -1 the unit died from another cause such as hunger or Actions.UnitKill. Called just before the unit is killed so UnitID is usable only during this event, and the tile occupied by the unit is still taken. |
aUnit: Integer; aKillerOwner: Integer; //Index of player who killed it |
5057 | OnUnitTrained Occurs when player trains a unit. |
aUnit: Integer; |
5884 | OnUnitWounded Happens when unit is wounded. Attacker can be a warrior, recruit in tower or unknown (-1). |
aUnit: Integer; aAttacker: Integer; //Unit who attacked the unit |
14000 | OnWareProduced Occurs when resource is produced for specified house. |
aHouse: Integer; aWareType: TKMWareType; aCount: Integer; |
5057 | OnWarriorEquipped Occurs when player equips a warrior. |
aUnit: Integer; aGroup: Integer; |
7000+ | OnWarriorWalked Occurs when warrior walk |
aUnit: Integer; aToX: Integer; aToY: Integer; |
7000+ | OnWinefieldBuilt Occurs when player built a winefield. |
aPlayer: Integer; aX: Integer; aY: Integer; |