Creating a Kill Counter

Suppose you want to display the number of kills you have in the objectives, as seen below:

KillCounter

(Taken from my Douglas Gyasi: Golden Chancellor custom campaign)

To do this, create a trigger with the Change Variable effect and name that variable KillCount. Then, create another trigger with the following:

  • Trigger Name: KillCounterTrigger
  • Trigger Starting State: On
  • Trigger Looping: On
  • Condition: Accumulate Attribute. Set Tribute List to Kills by P1, Source Player to the enemy player and Quantity to 1.
  • Effect: Modify Resource. Set Tribute List of Kills by P1, Source Player to the enemy player, Operation to Subtract and Quantity to 1.
  • Effect: Change Variable. Set Variable to KillCount, Operation to Add and Quantity to 1.

You need to create separate triggers for each enemy player you want contributing to the total kill count. Everything in these triggers should be the same except for Source Player. In my scenario, I had 4 enemy players, so I had to create 4 kill count triggers total.

Now it’s time to display the kill counter in the objectives. Create a new trigger and add the following in the Trigger and Short descriptions: - Kill (<KillCount>/Number) enemy units. Then add whatever effects you want to trigger when you reach the kill threshold. If you just want to display kills for informational purposes, you can simply create a Player Defeated condition inside the trigger, setting source player to Gaia.

To explain what’s going on in KillCountTrigger, every time you (player 1) kill an enemy unit, the Kills by P1 attribute increases by 1, triggering KillCounterTrigger. During each loop of KillCounterTrigger, the Kills by P1 attribute is subtracted by 1, while 1 is added to the KillCount variable. The trigger keeps looping until Kills by P1 reaches 0. Without a Timer condition, looping triggers trigger every 1 game second. Obviously, you can kill more than 1 unit per second, hence the reason why we use the subtract operation instead of the set operation for the Modify Resource effect.

In other words, suppose we have an Onager that kills 6 units at once. Such an event causes the Kills by P1 attribute to increase to 6, activating the KillCounterTrigger trigger. With the subtract by 1 operation, KillCounterTrigger will add 1 to KillCount every time 1 is subtracted from Kills by P1. This will keep happening as long as Kills by P1 is greater than zero. After 6 game seconds, Kills by P1 will be zero and our kill counter should show 6 kills. However, if we use the set to 0 operation in the Modify Resource effect, Kills by P1 immediately changes from 6 to 0, disabling the loop and causing our kill counter to only show 1 kill.

H/t to this video for showing this loop method.

1 Like