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

Hey! An easy solution with a trigger is shown in the following video about variables. If you start at 5:00 he explains it. It’s not as elegant as the solution above, but it works.

@CanineCrown7153 Do I understand this correct? I have to add the script above via the script trigger in the editor or elsewhere? Thanks for your answer in advance!

Copy and paste that in the Script trigger effect. It will work out.

I added something because rules alone will make your Effect red, even if they work. You need a dummy function for them to not be red, but green.

1 Like