### Define Starting Technology Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/6.テクノロジー.md Example of a tier 0 technology assigned at the start of the game, restricted by origin. ```pdx tech_basic_science_lab_1 = { cost = @tier0cost1 area = physics tier = 0 category = { computing } start_tech = yes # 開始技術フラグ weight_modifier = { factor = 1000 } ai_weight = { weight = 10000 } # 特定起源では開始技術にしない starting_potential = { is_low_tech_start = no } } ``` -------------------------------- ### Define Project Requirements Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/16.スペシャルプロジェクト.md Example of defining specific conditions required to start a project. Note that standard AND/OR logic blocks are not supported here. ```pdx requirements = { shipclass_science_ship = 1 leader = scientist skill > 2 } ``` -------------------------------- ### Vanilla On Actions: Game Start & Pulse Events Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/7.オンアクション.md Lists common vanilla On Actions related to game start and periodic pulses, along with their scope and description. ```APIDOC ## Vanilla On Actions: Game Start & Pulse Events Here are some key vanilla On Actions related to game start and periodic pulses: | On Action | Scope | Description | | ----------------------------- | --------------------- | --------------------------------------------------------------------------- | | `on_game_start` | (No scope) | Triggers once when a new game starts. | | `on_game_start_country` | `this` = Country | Triggers for each country at the start of a new game. | | `on_single_player_save_game_load` | (No scope) | Triggers when a single-player save game is loaded. Does not trigger in MP. | | `on_monthly_pulse` | (No scope) | Triggers once every month. | | `on_yearly_pulse` | (No scope) | Triggers once every year. | | `on_bi_yearly_pulse` | (No scope) | Triggers once every two years. | | `on_five_year_pulse` | (No scope) | Triggers once every five years. | | `on_decade_pulse` | (No scope) | Triggers once every decade. | | `on_mid_game_pulse` | (No scope) | Triggers at the start of the mid-game. | | `on_late_game_pulse` | (No scope) | Triggers at the start of the late-game. | | `on_monthly_pulse_country` | `this` = Country | Triggers for each country every month. | | `on_yearly_pulse_country` | `this` = Country | Triggers for each country every year. | | `on_five_year_pulse_country` | `this` = Country | Triggers for each country every five years. | | `on_decade_pulse_country` | `this` = Country | Triggers for each country every decade. | | `on_mid_game_pulse_country` | `this` = Country | Triggers for each country at the start of the mid-game. | | `on_late_game_pulse_country` | `this` = Country | Triggers for each country at the start of the late-game. | ``` -------------------------------- ### Example: Zroni Digsite 1 Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/10.遺物・考古学サイト.md An example demonstrating the structure of an archaeological site definition, including multiple stages. ```APIDOC ## Example: Zroni Digsite 1 ### Description This example shows a complete definition for the 'Zroni Digsite 1' archaeological site, including its properties, conditions, and multiple stages with their respective difficulties, icons, and events. ### Request Example ```ruby zroni_digsite_1 = { desc = zroni_digsite_1_desc picture = GFX_evt_overgrown_city stages = 3 max_instances = 1 allow = { is_ship_class = shipclass_science_ship exists = leader } visible = { has_country_flag = zroni_intro default_site_visible_trigger = yes } stage = { difficulty = 1 icon = GFX_archaeology_runes_F1 event = ancrel.2 } stage = { difficulty = 1 icon = GFX_archaeology_runes_F2 event = ancrel.3 } stage = { difficulty = 2 icon = GFX_archaeology_runes_F3 event = ancrel.4 } on_roll_failed = { from = { standard_archaeological_site_on_roll_failed = { RANDOM_EVENTS = all_random_events } } } } ``` ### Note `standard_archaeological_site_on_roll_failed` is a scripted effect. ``` -------------------------------- ### Performance Optimized Example Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/7.オンアクション.md Provides an example of an event script optimized for performance, utilizing `pre_triggers` for efficient checks. ```APIDOC ## Performance Optimized Example ### Description This example showcases an event script designed for performance optimization. It utilizes `pre_triggers` to perform lightweight checks before evaluating more complex trigger conditions, which is especially useful for frequently occurring events. ### Code Example ```pdx # events/my_events.txt planet_event = { id = my_events.optimized is_triggered_only = yes # Lightweight pre-checks to improve performance pre_triggers = { has_owner = yes is_occupied = no } # Complex triggers are evaluated only after pre_triggers pass trigger = { owner = { is_ai = no has_technology = tech_example } any_owned_pop = { has_trait = trait_example } } # Effect immediate = { # ... effects go here ... } } ``` ``` -------------------------------- ### Search for Element Usage Examples (Bash) Source: https://context7.com/kongyo2/stellaris-skill/llms.txt Searches for examples of how a specific element is used within the CWTools data. It returns the count of usages and details about where they occur, including file and line number. ```bash python scripts/search_cwtools.py add_modifier --category effect --usage ``` -------------------------------- ### Practical Sample: Timelimit Project Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/16.スペシャルプロジェクト.md Example of a special project with a time limit, demonstrating `timelimit` and conditional `on_fail`. ```APIDOC ### タイムリミット付きプロジェクト ```pdx special_project = { key = "MUTANT_STALKER_PROJECT" cost = 5000 tech_department = society_technology timelimit = 720 icon = "gfx/interface/icons/situation_log/situation_log_combat.dds" picture = GFX_evt_colony_settlement event_scope = planet_event requirements = { assault_armies = 2 } on_success = { planet_event = { id = colony.110 } } on_fail = { random_list = { 50 = { FROM = { planet_event = { id = colony.111 } } } 50 = { FROM = { planet_event = { id = colony.112 } } } } } } ``` ``` -------------------------------- ### Basic On Action Registration Example Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/7.オンアクション.md Demonstrates how to register events to 'on_action' triggers, including monthly pulses and colonization events. ```APIDOC ## Basic On Action Registration ### Description This example shows how to register events to 'on_action' triggers in a basic manner. It covers registering events for monthly pulses and colonization completion. ### Code Example ```pdx # common/on_actions/my_on_actions.txt # Register an event to be triggered on the monthly pulse on_monthly_pulse = { events = { my_events.monthly_check } } # Register events for when a planet is colonized on_colonized = { events = { my_events.colony_celebration } random_events = { 80 = 0 20 = my_events.colony_surprise } } ``` ``` -------------------------------- ### Custom On Action Usage Example Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/7.オンアクション.md Illustrates how to define and fire custom 'on_action' events using the `fire_on_action` command. ```APIDOC ## Custom On Action Usage ### Description This example demonstrates how to define a custom 'on_action' and then trigger it from within an event using the `fire_on_action` command. This allows for modular event system design. ### Code Example ```pdx # common/on_actions/my_custom_on_actions.txt on_my_special_event = { events = { my_events.special_handler } } # Event that fires the custom on_action country_event = { id = my_events.trigger_special immediate = { fire_on_action = { on_action = on_my_special_event scopes = { from = root } } } } ``` ``` -------------------------------- ### Define a Custom Origin Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/9.政府.md Example of an origin definition, which requires the is_origin flag and specific starting parameters. ```pdx origin_my_origin = { is_origin = yes # 起源として機能 icon = "gfx/interface/icons/origins/origins_my_origin.dds" picture = GFX_origin_my_origin # 帝国作成画面の背景画像 # --- 開始惑星 --- starting_colony = pc_gaia # 開始惑星タイプの上書き habitability_preference = pc_gaia # 気候適性特性の上書き preferred_planet_class_neighbor = no # 保証された居住可能惑星のタイプを一致させない non_colonizable_planet_class_neighbor = no # 保証された居住可能惑星を無効化 # --- ゲーム開始 --- initializers = { my_system_init } # 使用する星系初期化子 flags = { my_country_flag } # 開始時に設定するフラグ advanced_start = yes # 先進スタートを許可 # --- 二次種族 --- has_secondary_species = { title = LOC_SECONDARY_SPECIES traits = { trait = trait_syncretic_proles } } } ``` -------------------------------- ### Practical Sample: Exclusive Option Group Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/16.スペシャルプロジェクト.md Example demonstrating how to create mutually exclusive project options using `same_option_group_as`. ```APIDOC ### 排他的選択グループ 複数のアプローチから1つを選択させる場合: ```pdx special_project = { key = "MIGRATING_FORESTS_1_PROJECT" event_chain = "migrating_forests_chain" cost = 3500 tech_department = society_technology picture = GFX_evt_alien_nature event_scope = planet_event on_success = { planet_event = { id = colony.2 } owner = { end_event_chain = "migrating_forests_chain" } } on_fail = { } } special_project = { key = "MIGRATING_FORESTS_2_PROJECT" event_chain = "migrating_forests_chain" cost = 3500 tech_department = engineering_technology picture = GFX_evt_alien_nature same_option_group_as = { MIGRATING_FORESTS_1_PROJECT } # 排他的グループ event_scope = planet_event on_success = { planet_event = { id = colony.3 } owner = { end_event_chain = "migrating_forests_chain" } } on_fail = { } } ``` ``` -------------------------------- ### Simple Technology Prerequisites Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/6.テクノロジー.md Example of defining a simple prerequisite for a technology, requiring a specific other technology to be researched first. ```pdx prerequisites = { "tech_basic_science_lab_2" } ``` -------------------------------- ### Event Inheritance Example Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/5.イベント.md Utilize event inheritance to reuse properties from a base event. This example shows how to inherit from 'my_event.base' and then override or clear specific properties like description and options. ```pdx # ベースとなるイベント country_event = { id = my_event.base title = "Generic Title" picture = GFX_evt_default option = { name = "OK" } } # 継承したイベント country_event = { id = my_event.inherited base = my_event.base # my_event.baseを継承 desc_clear = yes # descをクリア option_clear = yes # optionをクリア desc = "A new description." option = { name = "A new option" add_resource = { unity = 100 } } } ``` -------------------------------- ### Enable Special Project Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/16.スペシャルプロジェクト.md Activates a special project by its key, specifying its location and owner. This is used to start a project. ```pdx enable_special_project = { name = "MY_PROJECT_KEY" location = this # 場所(通常は惑星やシステム) owner = root # オーナー国家 } ``` -------------------------------- ### Practical Sample: Basic Anomaly Research Project Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/16.スペシャルプロジェクト.md Example of a special project for researching anomalies, including requirements and success callback. ```APIDOC ### 基本的なアノマリー調査プロジェクト ```pdx special_project = { key = "GAS_GIANT_BODIES_PROJECT" cost = 0 days_to_research = 180 tech_department = society_technology picture = GFX_evt_landing_ship event_scope = ship_event requirements = { shipclass_science_ship = 1 leader = scientist } on_success = { ship_event = { id = anomaly.2501 } } on_fail = { } } ``` ``` -------------------------------- ### Weight Multiplier Example Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/7.オンアクション.md Demonstrates how to use `weight_multiplier` within an event definition to dynamically adjust the selection weight for `random_events`. ```APIDOC ## Weight Multiplier Usage The `weight_multiplier` block within an event definition allows for dynamic adjustment of selection weights, particularly useful for `random_events`. ### Example ```pdx on_colonized = { random_events = { 100 = my_events.colony_followup 100 = my_events.colony_crisis } } country_event = { id = my_events.colony_crisis hide_window = yes is_triggered_only = yes trigger = { has_country_flag = frontier_sector } weight_multiplier = { factor = 1 modifier = { factor = 0 has_modifier = peace_festival } modifier = { factor = 3 is_at_war = yes } } immediate = { } } ``` ``` -------------------------------- ### Practical Sample: Project with Abort Condition Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/16.スペシャルプロジェクト.md Example of a project that automatically cancels if a specific condition is met, using `abort_trigger`. ```APIDOC ### 中断条件付きプロジェクト 対象が失われた場合に自動キャンセル: ```pdx special_project = { key = "SHUTTLE_INTERCEPTED" cost = 0 days_to_research = 180 tech_department = society_technology timelimit = 1080 picture = GFX_evt_big_landing_ship event_scope = ship_event requirements = { shipclass_science_ship = 1 leader = scientist } on_success = { ship_event = { id = observation.202 } } on_fail = { country_event = { id = observation.203 } } abort_trigger = { exists = event_target:pre_ftl_planet event_target:pre_ftl_planet = { OR = { NOT = { exists = event_target:pre_ftl_country } AND = { exists = owner owner = { NOT = { is_same_value = event_target:pre_ftl_country } } } } } } } ``` ``` -------------------------------- ### Trigger Event on Game Start Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/5.イベント.md Hooks into the 'on_game_start' action to trigger a specific event when a new game begins. Ensure the event ID is correctly listed. ```pdx # /common/on_actions/my_on_actions.txt on_game_start = { events = { my_event.1 } } ``` -------------------------------- ### Define an Archaeology Site Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/10.遺物・考古学サイト.md Example of a complete archaeology site definition including stages, visibility, and failure handling. ```ruby zroni_digsite_1 = { desc = zroni_digsite_1_desc picture = GFX_evt_overgrown_city stages = 3 max_instances = 1 allow = { is_ship_class = shipclass_science_ship exists = leader } visible = { has_country_flag = zroni_intro default_site_visible_trigger = yes } stage = { difficulty = 1 icon = GFX_archaeology_runes_F1 event = ancrel.2 } stage = { difficulty = 1 icon = GFX_archaeology_runes_F2 event = ancrel.3 } stage = { difficulty = 2 icon = GFX_archaeology_runes_F3 event = ancrel.4 } on_roll_failed = { from = { standard_archaeological_site_on_roll_failed = { RANDOM_EVENTS = all_random_events } } } } ``` -------------------------------- ### Optimized Event with Pre-Triggers Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/7.オンアクション.md An example of an event using `pre_triggers` for performance optimization. Complex triggers are only evaluated after passing the lightweight pre-checks. ```pdx # events/my_events.txt planet_event = { id = my_events.optimized is_triggered_only = yes #軽量な事前チェック pre_triggers = { has_owner = yes is_occupied = no } # 複雑なトリガーはpre_triggersを通過後のみ評価 trigger = { owner = { is_ai = no has_technology = tech_example } any_owned_pop = { has_trait = trait_example } } # 効果 immediate = { # ... } } ``` -------------------------------- ### Define Technology Tier Cost and Weight Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/6.テクノロジー.md Example of defining a technology tier in `00_tier.txt`. This sets the unlock condition based on previously researched tiers and applies weight modifiers. ```pdx # /common/technology/tier/00_tier.txt 2 = { previously_unlocked = 6 # ティア1の技術を6つ研究すると解放 weight_modifier = { base = 1 } } ``` -------------------------------- ### Creating a Fleet and Ships in Stellaris Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/8.エフェクト.md Illustrates the process of creating a new fleet and then adding ships to it. It also sets the fleet's owner, location, and saves the new fleet as an event target. ```pdx # 艦隊と艦船の生成 create_fleet = { name = "NAME_Exploration_Fleet" effect = { set_owner = root create_ship = { name = "NAME_Survey_Ship" design = "Explorer" } set_location = root.capital_scope save_event_target_as = new_fleet } } ``` -------------------------------- ### Define Decision for Uncolonized Planets Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/15.惑星ディシジョン.md Example of a decision for uncolonized planets, requiring the 'Consecrated Worlds' ascension perk. Ensure proper setup for potential and allow conditions. ```pdx decision_consecrated_worlds = { # owned_planets_only = yesを指定しない = デフォルトでno相当 resources = { category = decisions cost = { unity = 500 } } potential = { exists = from from = { has_ascension_perk = ap_consecrated_worlds } exists = space_owner space_owner = { is_same_value = from } is_star = no is_artificial = no NOT = { has_planet_flag = consecrated@from } } allow = { custom_tooltip = { from = { check_variable = { which = num_consecrated_worlds value < 3 } } fail_text = consecrated_worlds_too_many } custom_tooltip = { NOT = { exists = owner } fail_text = consecrated_worlds_planet_owned } } effect = { custom_tooltip = decision_consecrated_worlds_effects_custom hidden_effect = { set_planet_flag = consecrated@from # 惑星タイプに応じたModifier付与ロジック... } } } ``` -------------------------------- ### Complex Scripted Effect Example Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/8.エフェクト.md A practical example of a scripted effect involving conditional logic for planet modification. ```pdx # 惑星温度を上げる連鎖処理 increase_planet_temperature = { if = { limit = { is_planet_class = pc_frozen } change_pc = pc_arctic reroll_planet = yes clear_blockers = yes } else_if = { limit = { is_planet_class = pc_arctic } change_pc = pc_ocean reroll_planet = yes clear_blockers = yes } # ... 他の惑星タイプも同様 } ``` -------------------------------- ### Stellaris Triggered Pop Modifier Example Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/12.特性.md Example of a triggered pop modifier that applies a bonus to mineral production for miners. It requires a custom tooltip to be displayed to the player. ```pdx triggered_pop_modifier = { potential = { has_job = miner } planet_jobs_minerals_produces_mult = 0.10 } custom_tooltip = TRAIT_MINING_BONUS_TOOLTIP ``` -------------------------------- ### Creating a New Leader in Stellaris Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/8.エフェクト.md Shows how to create a new leader with a specific class, species, skill level, and traits. The example also includes an effect to save the created leader as an event target. ```pdx # リーダーの生成 create_leader = { class = scientist species = owner_main_species name = random skill = 5 traits = { trait = leader_trait_expertise_biology } effect = { save_event_target_as = new_scientist } } ``` -------------------------------- ### Queue Fleet Actions Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/5.イベント.md Demonstrates how to queue movement, waiting, and effects for a fleet within an event. ```pdx fleet_event = { id = my_event.fleet hide_window = yes is_triggered_only = yes immediate = { # 艦隊にアクションをキュー queue_actions = { move_to = event_target:destination_system wait = 50 # 50日待機 effect = { id = "my_effect_action" # エフェクトを実行 } } } } ``` -------------------------------- ### Define Planet Event Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/5.イベント.md An example of a planet-scoped event triggered by colonization. ```pdx planet_event = { id = advisor.17 title = advisor.17.name desc = advisor.17.desc show_sound = event_first_colony_advisor is_advisor_event = yes is_triggered_only = yes trigger = { owner = { NOT = { is_tutorial_level = 0 } NOT = { has_country_flag = advisor_colonization_begun } } } immediate = { owner = { set_country_flag = advisor_colonization_begun } } option = { name = UNDERSTOOD } } ``` -------------------------------- ### Common DLC Triggers Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/6.テクノロジー.md Standard triggers for checking installed DLCs. ```pdx host_has_dlc = "Utopia" host_has_dlc = "Megacorp" has_ancrel = yes # Ancient Relics has_overlord_dlc = yes # Overlord ``` -------------------------------- ### Define Ship Event Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/5.イベント.md An example of a ship-scoped event triggered by anomaly discovery. ```pdx namespace = advisor ship_event = { id = advisor.10 title = advisor.10.name desc = advisor.10.desc show_sound = event_first_discovery_advisor is_advisor_event = yes is_triggered_only = yes trigger = { owner = { is_ai = no NOT = { is_tutorial_level = 0 } NOT = { has_country_flag = advisor_discovery_found } } FROM = { has_anomaly = yes } } immediate = { owner = { set_country_flag = advisor_discovery_found } } option = { name = UNDERSTOOD } } ``` -------------------------------- ### AI Wait Days Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/16.スペシャルプロジェクト.md Defines the waiting period before an AI starts a project, with modifiers. ```APIDOC ## AI_wait_days AIがプロジェクトを開始するまでの待機日数を設定します。 ```pdx AI_wait_days = { weight = 80 modifier = { factor = 0.5 has_ethic = ethic_fanatic_militarist } } ``` ``` -------------------------------- ### Defining and Firing Custom On Action Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/7.オンアクション.md Define a custom on_action and demonstrate how to fire it from an event using `fire_on_action`. This allows for modular event systems. ```pdx # common/on_actions/my_custom_on_actions.txt on_my_special_event = { events = { my_events.special_handler } } # イベント内でカスタムオンアクションを発火 country_event = { id = my_events.trigger_special immediate = { fire_on_action = { on_action = on_my_special_event scopes = { from = root } } } } ``` -------------------------------- ### Define Global Event Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/5.イベント.md An example of a global event triggered by game state conditions. ```pdx namespace = drones event = { id = drones.100 hide_window = yes is_triggered_only = yes trigger = { end_game_years_passed < 0 exists = event_target:drone_country any_system = { NOT = { exists = starbase } is_valid_drone_expansion_destination_system = yes } } immediate = { # グローバルな処理を実行 } } ``` -------------------------------- ### Define Country Event Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/5.イベント.md A basic country event example using triggers and flags. ```pdx namespace = achievement country_event = { id = achievement.1 hide_window = yes is_triggered_only = yes trigger = { is_ai = no from = { OR = { is_country_type = fallen_empire is_country_type = awakened_fallen_empire } } NOT = { has_country_flag = clash_of_the_titans } } immediate = { set_country_flag = clash_of_the_titans } } ``` -------------------------------- ### Spawning a New Star System Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/8.エフェクト.md Shows how to generate a new star system within a specified distance range and assign an initializer for its contents. The new system is then saved as an event target. ```pdx # 星系の生成 spawn_system = { min_distance >= 20 max_distance <= 50 initializer = "special_event_system" effect = { save_event_target_as = new_system } } ``` -------------------------------- ### Origin Definition Example: Life Seeded Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/9.政府.md A full definition for the Life Seeded origin. ```pdx origin_life_seeded = { is_origin = yes icon = "gfx/interface/icons/origins/origins_life_seeded.dds" picture = GFX_origin_life_seeded starting_colony = pc_gaia habitability_preference = pc_gaia preferred_planet_class_neighbor = no playable = { host_has_dlc = "Apocalypse" } possible = { authority = { NOT = { value = auth_machine_intelligence } } } description = "civic_tooltip_life_seeded_effects" random_weight = { base = 5 } } ``` -------------------------------- ### Performance Best Practices: Pre-Triggers Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/7.オンアクション.md Recommends using `pre_triggers` for performance optimization in On Actions, especially for frequently triggered events. ```APIDOC ## Performance Best Practices: Pre-Triggers For On Actions that trigger frequently (e.g., on `planet`, `system`, `starbase`, `leader`, `pop` scopes), using `pre_triggers` is highly recommended for performance. `pre_triggers` are evaluated before the main `trigger` block. If `pre_triggers` evaluate to false, the heavier `trigger` block is skipped, improving overall game performance. ### Example ```pdx # events/my_planet_event.txt planet_event = { id = my_events.1 is_triggered_only = yes # Lightweight conditions evaluated first pre_triggers = { has_owner = yes owner = { is_ai = no } } # More complex trigger evaluated only if pre_triggers pass trigger = { # ... complex conditions ... } # ... effects ... } ``` ``` -------------------------------- ### War On Actions Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/7.オンアクション.md Triggers related to war events such as starting, winning, losing, and status quo. ```APIDOC ## War On Actions ### Description Triggers that fire during various stages of a war, including participation, victory, defeat, and status quo. ### Triggers - **on_entering_war** (this=Country, from=Enemy War Leader) - Triggered when joining a war. - **on_war_beginning** (root=Country, from=War) - Triggered for each country when a war starts. - **on_war_won** (root=Winner, from=Loser, fromfrom=War) - Triggered when winning a war. - **on_war_lost** (root=Loser, from=Winner, fromfrom=War) - Triggered when losing a war. - **on_war_ended** (root=Loser, from=Main Winner) - Triggered when a war ends. - **on_status_quo** (root=Actor, from=Recipient, fromfrom=Main Attacker, fromfromfrom=Main Defender) - Triggered when status quo is signed. - **on_status_quo_forced** (root=Recipient, from=Actor) - Triggered when status quo is forced. - **on_country_released_in_war** (root=New Country, from=Forcing Country, fromfrom=Original Country, fromfromfrom=War) - Triggered when a country is released via peace treaty. - **on_proxy_war_started** (root=Instigator, from=Victim) - Triggered when a proxy war starts. - **on_claim_system** (this=Country, from=System Owner) - Triggered when a claim is made on a system. ``` -------------------------------- ### Define Custom Technology in Stellaris Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/6.テクノロジー.md Example of defining a custom technology with all essential parameters, including cost, area, tier, category, prerequisites, effects, and AI weights. Use this as a template for creating new technologies. ```pdx # /common/technology/my_mod_tech.txt tech_my_custom_technology = { # --- 必須パラメータ --- cost = @tier2cost1 # 研究コスト area = physics # 研究エリア (physics/society/engineering) tier = 2 # ティア (0-5) category = { computing } # カテゴリ weight = @tier2weight1 # 出現ウェイト # --- 前提・条件 --- prerequisites = { "tech_basic_science_lab_2" } # 前提技術 potential = { # 出現条件 is_gestalt = no } # --- 研究完了時の効果 --- modifier = { planet_jobs_physics_research_produces_mult = 0.10 } # --- 出現確率調整 --- weight_modifier = { modifier = { factor = 1.5 research_leader = { area = physics has_trait = leader_trait_expertise_computing } } } # --- AI関連 --- ai_weight = { factor = 1.0 } ai_update_type = all # 研究完了時にAIの設計を更新 # --- オプションのタグ --- is_rare = no # レア技術(紫枠) is_dangerous = no # 危険技術(赤枠) is_reverse_engineerable = yes # デブリから取得可能 } ``` -------------------------------- ### Common Trigger Conditions Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/5.イベント.md Examples of frequently used trigger conditions for country and leader checks. ```pdx is_ai = no # プレイヤー操作か has_ethic = ethic_materialist # 志向チェック has_country_flag = some_flag # フラグチェック has_technology = tech_robotics # 技術チェック is_at_war = yes # 戦争中か num_owned_planets >= 5 # 所有惑星数 leader = { gender = female } leader = { has_trait = leader_trait_meticulous } leader = { has_skill_level >= 5 } ``` -------------------------------- ### Implementing 3-Input XOR (Odd Parity) in Stellaris Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/2.条件式と論理演算.md Shows how to implement a 3-input XOR logic, which evaluates to true if an odd number of the inputs are true, using a combination of OR and calc_true_if. ```pdx trigger = { OR = { calc_true_if = { amount = 1 A B C } calc_true_if = { amount = 3 A B C } } } ``` -------------------------------- ### Optimize Memory Usage Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/8.エフェクト.md Use optimize_memory at the start of heavy scripted effects to reduce memory overhead. ```pdx my_heavy_effect = { optimize_memory # 先頭に配置 every_country = { # 重い処理 } } ``` -------------------------------- ### Set Pre-calculation Shortcuts Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/11.POPと職業.md Use pre-calculation shortcuts to define common job tier prerequisites. ```pdx possible_precalc = can_fill_specialist_job possible_precalc = can_fill_worker_job possible_precalc = can_fill_drone_job ``` -------------------------------- ### Define DLC-Restricted Technology Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/6.テクノロジー.md Example of a high-tier technology requiring a specific DLC and unlocked via ascension perks. ```pdx tech_dyson_sphere = { area = physics cost = @tier5cost3 tier = 5 category = { field_manipulation } ai_update_type = all prerequisites = { "tech_mega_engineering" } weight = @tier5weight3 is_rare = yes potential = { host_has_dlc = "Utopia" # Utopia DLC必須 } weight_modifier = { factor = 0 # 通常は選択肢に出ない # アセンションパークでアンロック } ai_weight = { factor = @best_megastructure_ai_tech_factor } } ``` -------------------------------- ### Basic Effect Syntax in Stellaris Script Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/8.エフェクト.md Demonstrates the fundamental syntax for applying effects in Stellaris scripts, including simple assignments and conditional logic within if blocks. Use for direct game state modifications. ```pdx # 単純なエフェクト add_resource = { energy = 100 } ``` ```pdx # 条件付きエフェクト(ifブロック内) if = { limit = { has_ethic = ethic_militarist } add_resource = { alloys = 500 } } ``` ```pdx # スコープ切り替えとエフェクト every_owned_planet = { limit = { is_capital = no } add_modifier = { modifier = resource_bonus_modifier days = 360 } } ``` -------------------------------- ### Object Naming Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/8.エフェクト.md Set dynamic names for game objects using string localization keys. ```pdx # 動的な名前設定 set_name = "NAME_Conquered_[Root.GetName]" ``` -------------------------------- ### Implementing 2-Input XOR in Stellaris Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/2.条件式と論理演算.md Provides two methods to implement the XOR (exclusive OR) logic, as Stellaris does not have a built-in XOR operator. Method 1 uses OR and NAND, while Method 2 uses calc_true_if. ```pdx # 方法1: OR + NANDの組み合わせ trigger = { OR = { A B } NAND = { A B } } # 方法2: calc_true_if使用 trigger = { calc_true_if = { amount = 1 A B } } ``` -------------------------------- ### Define a Custom Civic Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/9.政府.md Example of a standard civic definition including cost, potential/possible conditions, and modification settings. ```pdx civic_my_civic = { # --- 基本設定 --- cost = 1 # 国是ポイントコスト(デフォルト1) # --- アイコン --- icon = "gfx/interface/icons/governments/civics/my_icon.dds" # --- 条件 --- playable = { # プレイヤー選択可能条件(グローバル) host_has_dlc = "Utopia" } potential = { # 表示条件(特殊構文) ethics = { NOT = { value = ethic_gestalt_consciousness } } authority = { NOT = { value = auth_corporate } } } possible = { # 選択可能条件(特殊構文) ethics = { OR = { text = civic_tooltip_spiritualist value = ethic_spiritualist value = ethic_fanatic_spiritualist } } civics = { NOT = { value = civic_incompatible } } } # --- 変更制限 --- modification = yes # ゲーム中に追加/削除可能 pickable_at_start = yes # 帝国作成時に選択可能 # --- AI --- random_weight = { base = 5 } ai_weight = { base = 100 modifier = { factor = 2 has_ai_personality = evangelising_zealots } } # --- 効果 --- description = "civic_my_tooltip" # カスタム説明文 modifier = { pop_ethic_spiritualist_attraction_mult = 0.15 } # --- 種族特性 --- traits = { trait = trait_cybernetic } # --- 条件付き名前変更 --- swap_type = { name = civic_my_civic_lithoid description = "civic_my_civic_lithoid_effects" trigger = { local_human_species_class = LITHOID } } } ``` -------------------------------- ### Creating a Colony on a Planet Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/8.エフェクト.md Demonstrates how to establish a new colony on a planet, specifying the owner and species for the colony. This effect is used to populate planets with player-controlled settlements. ```pdx # 入植地の生成 create_colony = { owner = root species = root.species ethos = owner } ``` -------------------------------- ### Stellaris Iterator Effects Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/8.エフェクト.md Examples of using iterators to perform actions on owned planets or leaders based on specific criteria. ```pdx # すべての所有惑星に実行 every_owned_planet = { limit = { is_capital = no num_pops >= 10 } add_modifier = { modifier = production_bonus days = 180 } } # ランダムな惑星を選択 random_owned_planet = { limit = { is_colonizable = yes } weights = { base = 1 modifier = { add = 10 has_modifier = lush_planet } } save_event_target_as = selected_planet } # ソートして上位を選択 ordered_owned_leader = { limit = { leader_class = scientist } order_by = trigger:skill_level position = 0 # 最高スキルのリーダー add_trait = leader_trait_expertise_field_manipulation } ``` -------------------------------- ### Define Prerequisite Descriptions Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/6.テクノロジー.md Configures how the technology appears in the UI as a prerequisite for other items. ```pdx tech_cruisers = { # ... prereqfor_desc = { ship = { title = "CRUISER_PREREQ_TITLE" # ローカライゼーションキー desc = "CRUISER_PREREQ_DESC" } } } tech_archaeo_detection_scrambler = { # ... prereqfor_desc = { hide_prereq_for_desc = component # 通常のコンポーネント表示を隠す custom = { title = "TECH_UNLOCK_SCRAMBLER_TITLE" desc = "TECH_UNLOCK_SCRAMBLER_DESC" } } } ``` -------------------------------- ### Important Notes on On Actions Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/7.オンアクション.md Key considerations and best practices for using 'on_action' triggers in Stellaris. ```APIDOC ## Important Notes on On Actions ### Performance When registering events to frequently triggered 'on_actions' (like `on_monthly_pulse`), use `pre_triggers` for performance optimization. ### File Order If multiple files register events to the same 'on_action', they are executed in ASCII order of their filenames. Prefix filenames with numbers (e.g., `00_`, `01_`) if execution order is critical. ### Scope Verification Each 'on_action' has specific scopes (`this`, `from`, `fromfrom`, etc.). Always verify what these scopes refer to before registering events. ### `is_triggered_only` Events registered to 'on_actions' should typically have `is_triggered_only = yes` to prevent them from firing based on Mean Time To Happen (MTTH). ### Custom On Actions Since script version 3.0, custom 'on_actions' can be triggered using `fire_on_action`, facilitating the creation of modular event systems. ``` -------------------------------- ### Define Advanced Technology Source: https://github.com/kongyo2/stellaris-skill/blob/main/stellaris-modding/references/6.テクノロジー.md Example of a rare society technology with specific prerequisites and weight modifiers based on researcher traits. ```pdx tech_advanced_cloning = { cost = 5000 area = society tier = 2 category = { biology } prerequisites = { "tech_genome_mapping" } weight = 80 potential = { NOT = { has_ethic = ethic_fanatic_spiritualist } } modifier = { pop_growth_speed = 0.10 } weight_modifier = { modifier = { factor = 1.5 research_leader = { area = society has_trait = leader_trait_expertise_biology } } modifier = { factor = 0.5 years_passed < 50 } } ai_weight = { factor = 1.2 modifier = { factor = 2 has_ethic = ethic_xenophile } } is_rare = yes } ```