Scenario editor : How to set creation limit for units

In the campaign Battle for Greece, some scenarios allow you to create special units in the castle and have a creation limit.

Example, in this scenario we can creating 18 units max, even when we delete or lose this kind of units the cap reset each times to 18 :

Does anyone have any idea how to do this ?

PS : I don’t want using a custom data mod for this.

Hey!
I asked this in the UCG forums and user Kramb answered. First, you need to add a cost to the unit you want to limit. Say, to archers (and crosbowmen and arbalesters), add unused resource 8. It’s resource id is 8

Now, you need to add an script call like this

const int cArcher = 4;
const int cArcherLimit = 10;
const int limitResource = 8;

rule limitArcher highFrequency {
    for (player = 1; <= xsGetNumPlayers()) {
        int count = xsGetObjectCountTotal(player, cArcher);
        int resourceValue = cArcherLimit - count;
        if (resourceValue >= 0) {
           xsSetPlayerAttribute(player, limitResource, resourceValue);
        } else {
           xsSetPlayerAttribute(player, limitResource, 0);
        }
    }
}

This will make all players limit their archers to 10.

1 Like