Say you want to allow people to create no more than 4 Panthers throughout the entire game.
We have already implemented something like this for Lieutenant/Captain/Major in the Revamp mod, to make their squad shield visible while you tech:
-
https://github.com/xxpatch/consmod
Basically, what we did (and you have to copy by substituting Lieutenant with Panther) is:
- the lieutenant_first squad is an invisible squad captures the cost of the lieutenant tier
- When the lieutenant_first squad is built, the squad orders the main building to call-in a real lieutenant squad, and the fake lieutenant squad suicides
In your case you want to extend this as follows:
- Create a panthers_built player upgrade that can stack up to at least 4 times (local_limit >= 4)
- your panther_fake squad also adds a player_target_action -> add upgrade (panthers_built) for each Panther built
- Add a requirement for panther_fake for fewer-than 3 panthers_built slot items
- Keep the squad_requirement for panther_first for 1; that way players can't building 3 panthers, and then queue 3 panthers to cheat the limit
PS: Make sure you test your mod against what happens if you have multiple T4 buildings laid down. Our workaround works for USF because you can only ever have one of each building as USF.
PS2: if you want to allow players to queue panther-built commands, there is still away to implement this and be secure, but it's a bit more complicated:
have a look at bren_lmg_governor_upgrade. This upgrade controls that sapper squads can't get more than 1 Bren at the same time. if somebody queued multiple buy commands, the squad still gets one bren, and the rest are refunded (so that you don't pay munition for nothing). You can copy the requirement_action structure and remove the panther_fake squad requirement.