Hands-On Usage
random_purchase_contract is well-suited for mods that need to randomly pick one of a country's active purchase contracts and apply bulk modifications or cancellations — for example, automatically clearing low-priority contracts during wartime, or adjusting contract status when a specific event fires. Pairing it with a limit block lets you precisely filter eligible contracts (such as targeting only a specific buyer or a specific equipment type), preventing unintended changes to all contracts.
GER = {
random_purchase_contract = {
limit = {
buyer = { tag = ITA }
contract_contains_equipment = { type = infantry_equipment }
}
tooltip = ger_cancel_ita_contract_tooltip
cancel_purchase_contract = yes
}
}
Synergy
- every_purchase_contract — Use this when you need to apply an effect to all matching contracts at once; it forms a complementary "all matching vs. one random" pair with
random_purchase_contract.
- cancel_purchase_contract — The most common child effect: cancels the randomly selected contract, making it the quintessential downstream operation for this effect.
- contract_contains_equipment — Used inside a
limit block to filter contracts by the equipment type they contain, ensuring only contracts with the target equipment are eligible for selection.
- buyer / seller — Used inside
limit to restrict contracts by their buyer or seller country, preventing accidental interference with unrelated nations' contracts.
Common Pitfalls
- Omitting
limit and accidentally selecting an unintended contract: Without a limit block, this effect picks randomly from all contracts belonging to the current scope country, making it very easy to inadvertently cancel an important contract. Always constrain the selection with triggers such as buyer, seller, and contract_contains_equipment.
- Calling the effect outside a COUNTRY scope:
random_purchase_contract can only execute within a country scope. If it is mistakenly placed inside a state scope or any other scope, the script will either throw a silent error or do nothing at all. When debugging, carefully verify that the enclosing scope is indeed a country.