Wiki

effect · cancel_purchase_contract

Definition

  • Supported scope:PURCHASE_CONTRACT
  • Supported target:none

Description

Cancels the scoped purchase contract.
Example:
contract =  {cancel_purchase_contract = yes}

Hands-On Notes

Hands-on notes are AI-generated and checked against the vanilla command vocabulary — treat them as a starting point, not authoritative reference. The definition above is the game's own documentation.

Hands-On Usage

When a player or AI's purchase contract no longer meets its trigger conditions (for example, the buyer's faction changes or a resource agreement breaks down), you can call this effect within a contract iteration block to forcibly terminate that contract. This is commonly used in "dynamic trade management" mods to clear old contracts after specific events occur and prevent contract zombie accumulation.

# Example of canceling all contracts for the buyer in an event's immediate block
country_event = {
    id = my_trade_mod.1
    immediate = {
        # Iterate through purchase contracts involving this country
        every_purchase_contract = {
            limit = {
                buyer = { tag = ENG }
            }
            cancel_purchase_contract = yes
        }
    }
}

Synergy

  • [buyer](/wiki/trigger/buyer) — Use to verify before execution whether the contract's buyer is the target country, preventing accidental cancellation of other countries' contracts.
  • [seller](/wiki/trigger/seller) — Combine with seller identity filtering to ensure only contracts with specific suppliers are canceled.
  • [contract_contains_equipment](/wiki/trigger/contract_contains_equipment) — Check the equipment type contained in the contract first, executing cancellation only for contracts containing specific equipment to achieve fine-grained control.
  • [deal_completion](/wiki/trigger/deal_completion) — Skip cancellation when a contract has already completed its transaction, avoiding logic errors from redundant operations on concluded contracts.

Common Pitfalls

  1. Scope Mixing Errors: This effect must be called within a PURCHASE_CONTRACT scope (typically entered via every_purchase_contract / random_purchase_contract, etc.). Writing it directly under a country scope will cause script errors or silent failures—beginners most often forget to switch scope first.
  2. Unfiltered limit Causing Bulk Deletion: When iterating through all contracts without restricting with buyer/seller/contract_contains_equipment and other triggers, all purchase contracts for that country will be canceled at once, resulting in unexpected game state corruption.