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}

实战 · 配合 · 坑

实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。

实战用法

当玩家或 AI 的某个采购合同因触发条件不再满足(例如买方阵营改变、资源协议破裂)时,可在 contract 遍历块中调用此 effect 强制终止该合同。常见于"动态贸易管理"类 mod,用来在特定事件发生后清除旧合同、避免合同僵尸化堆积。

# 在某事件的 immediate 块中取消买方所有合同示例
country_event = {
    id = my_trade_mod.1
    immediate = {
        # 遍历该国参与的采购合同
        every_purchase_contract = {
            limit = {
                buyer = { tag = ENG }
            }
            cancel_purchase_contract = yes
        }
    }
}

配合关系

  • [buyer](/wiki/trigger/buyer) — 用于在执行前判断合同的买方是否为目标国家,防止误取消其他国家的合同。
  • [seller](/wiki/trigger/seller) — 配合卖方身份筛选,确保只取消与特定供应国签订的合同。
  • [contract_contains_equipment](/wiki/trigger/contract_contains_equipment) — 先检查合同所含装备类型,仅对包含特定装备的合同执行取消,实现精细化控制。
  • [deal_completion](/wiki/trigger/deal_completion) — 在合同已完成交割的条件下跳过取消,避免对已结束合同重复操作引发逻辑错误。

常见坑

  1. Scope 混用错误:此 effect 必须在 PURCHASE_CONTRACT scope 下调用(通常通过 every_purchase_contract / random_purchase_contract 等进入),直接写在 country scope 下会导致脚本报错或静默失效,新手最容易忘记先切换 scope。
  2. 未加 limit 过滤导致批量误删:在遍历所有合同时若不搭配 buyer/seller/contract_contains_equipment 等 trigger 做限制,会将该国所有采购合同一次性取消,产生意料之外的游戏状态破坏。

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.