動態模組創作

本頁面部分全部內容上次核對於3.0版本


This page is about the abstract but super flexible modding features, namely effects and conditions as well as scripted localization and scripted variables.

Effects[編輯 | 編輯原始碼]

Effects are statements to be executed and affect game status. Many game objects and event modding use this for dynamic effects. Head to effects for full list of effect statements.

Effects must be executed under a scope. Head to scopes for details.

Scripted effects[編輯 | 編輯原始碼]

There are more than singular statements of effects to be used for an effect. Scripted effects are moddable blocks of effect statements to be used as an effect. They are defined at "common/scripted_effects/xxx.txt".

How to use[編輯 | 編輯原始碼]

A scripted effect consists a block of effect statements and/or other scripted effects. That's it.

example_scripted_effect = {
	shift_ethic = ethic_materialist
	…
}

Defined scripted effects can be used as though they were effects. For instance, "example_scripted_effect" can be called with example_scripted_effect = yes.

Parameters[編輯 | 編輯原始碼]

Scripted effects can have parameters. All parameters are strings and will be dynamically inserted into the scripted effects.

For example, a scripted effect can be like this, so the empire will have their ethic shifted to materialist:

# definition
example_scripted_effect = {
	shift_ethic = ethic_$ETHIC$
}
# calling
example_scripted_effect = { ETHIC = materialist }

Or even like this, so the empire will have their ethic shifted to materialist twice:

# definition
example_scripted_effect = {
	while = {
		count = $COUNT$
		shift_ethic = ethic_$ETHIC$
	}
}
# calling
example_scripted_effect = { ETHIC = materialist COUNT = 2 }

Parameter conditions[編輯 | 編輯原始碼]

You can also write a condition block for parameters with "double" square brackets, making the stuff within it only called if the parameter (here $homeworld$) is passed through in the effect call.

[[homeworld] <<<STUFF HERE>>>]

Example:

 	last_created_species = {
 		save_global_event_target_as = vaadwaurSpecies
 		[[homeworld]set_species_homeworld = event_target:tempHomeworld]
 	}

You can also declare a fallback value in the parameter itself using the pipe symbol, e.g.:

	has_global_flag = crisis_stage_$STAGE|1$

The vanilla game (2.6) does not yet use much of this scripted syntax feature (introduced in 2.3). Only few examples can be found in:

common/scripted_effects/archaeology_event_effects.txt
common/scripted_triggers/00_scripted_triggers.txt

Instead, Star Trek mods like "New Civilisations" use this feature a little more often.

Inline math[編輯 | 編輯原始碼]

Scripted effects and scripted triggers can also have @\[ ... ], a simple inline math statement.

 inline_math_example = {
 	add_monthly_resource_mult = {
 		resource = unity
 		value = $COUNT|1$
 		min = @\[ $COUNT|1$ * 10 ]
 		max = 99999999
 	}
 }

This scripted effect will give the scoped empire X times their monthly unity income (up to 99,999,999 and down to X * 10), where X is the parameter given as COUNT.

For example, inline_math_example = { COUNT = 10 } gives the scoped empire 10 times their monthly unity income (up to 99,999,999 and down to 100).

Inline math has a drawback. Only the FIRST @\[ ... ] statement in a scripted effect / trigger is correctly recognized and evaluated. If multiple inline math statements is needed anyway, create multiple scripted effects that call each other.

To the authoring of this entry there are 4 known functional operators for inline math statements:

「+」
Adds the number on the right to the number on the left.
「-」
Subtracts the number on the right from the number on the left.
「*」
Multiplies the number on the left by the number on the right.
「/」
Divides the number on the left by the number on the right.

Any other attempted operator such as a = or ^ will result in the joining of the two sides. For example, if the statement @\[ 4 = 2 ] is ran, the resultant will be 42 to the effect.

 # If <condition A> is true, give the scoped empire twice the monthly unity income, otherwise once the monthly unity income.
 # If <condition B> is true, unity gained this way is reduced by -25%.
 inline_math_drawback = {
 	if = {
 		limit = { <condition A> }
 		inline_math_drawback_step_2 = { COUNT = 2 }
 	}
 	else = {
 		inline_math_drawback_step_2 = { COUNT = 1 }
 	}
 }

 inline_math_drawback_step_2 = {
 	if = {
 		limit = { <condition B> }
 		inline_math_drawback_step_3 = { COUNT = $COUNT$  MULT = 0.75 }
 	}
 	else = {
 		inline_math_drawback_step_3 = { COUNT = $COUNT$  MULT = 1.0 }
 	}
 }

 inline_math_drawback_step_3 = {
 	inline_math_drawback_step_4 = {
 		RESOURCE = unity
 		COUNT = @\[ $COUNT$ * $MULT$ ]
 	}
 }

 inline_math_drawback_step_4 = {
 	add_monthly_resource_mult = {
 		resource = $RESOURCE$
 		value = $COUNT$
 		min = @\[ $COUNT$ * 100 ]
 		max = 100000000
 	}
 }

It should be noted however that if multiple inline math statements are required for your code you will have to execute them in a manner of one per scripted effect call. It is however possible to send an inline math statement as a parameter by wrapping it in a pair of quotations "@\[ ... ]". Wrapping an inline math statement will allow for a scripted event to use multiple inline statements so long as the statements are a parameter to another effect, although it cannot send more than one statement as a parameter to an effect.

 # If <condition A> is true, give the scoped empire twice the unity income, otherwise once a static unity income.
 # If <condition B> is true, unity gained this way is reduced by -25%.
 inline_math_effect = {
 	if = {
 		limit = { <condition A> }
 		inline_math_drawback_step_2 = { COUNT = 2 }
 	}
 	else = {
 		inline_math_drawback_step_2 = { COUNT = 1 }
 	}
 }
 inline_math_drawback_step_2 = {
# These inline statements won't run here allowing us to pick and chose which one we want, but it will autofill the $COUNT$ parameter in this statement.
 	if = {
 		limit = { <condition B> }
 		inline_math_drawback_step_3 = { Resource = unity Value = "@\[ $COUNT$ * 0.75 * 500]" }
 	}
 	else = {
 		inline_math_drawback_step_3 = { Resource = unity Value = "@\[ $COUNT$ * 500]" }
 	}
 }
 inline_math_drawback_step_3 = {
 	add_resource = {
 		$Resource$ = $Value$
 	}
 }

Conditions[編輯 | 編輯原始碼]

Conditions are statements to be evaluated for a yes or no. Many game objects and event modding use this for dynamic conditions. Head to conditions for full list of condition statements.

Conditions must be checked on a scope. Head to scopes for details.

Scripted triggers[編輯 | 編輯原始碼]

Similarly, there are more than singular statements of xonditions to be used for a condition. Scripted triggers are moddable blocks of condition statements to be used as a condition. They are defined at "common/scripted_triggers/xxx.txt".

How to use[編輯 | 編輯原始碼]

Like scripted effects, a scripted trigger is a block of condition statements and/or other scripted triggers.

example_scripted_trigger = {
	has_ethic = ethic_materialist
	has_ethic = ethic_fanatic_materialist
	…
}

Defined scripted triggers can be used as though they were Conditions. For instance, "example_scripted_trigger" can be called with example_scripted_trigger = yes/no.

Parameters[編輯 | 編輯原始碼]

Scripted triggers do also have parameters.

# definition
example_scripted_trigger = {
	has_ethic = ethic_$ETHIC$
	has_ethic = ethic_fanatic_$ETHIC$
}
# calling
example_scripted_trigger = { ETHIC = materialist }

A scripted trigger with parameters can't be called in xxx = no form, but can be called in NOT = { … } block.

Scripted localization[編輯 | 編輯原始碼]

Scripted localizations are defined at "common/scripted_loc/xxx.txt".

How to use[編輯 | 編輯原始碼]

First, define an instance.

defined_text = {
	name = GetAuthorityName
	text = {
		trigger = { has_authority = auth_democratic }
		localization_key = auth_democratic
	}
	text = {
		trigger = { has_authority = auth_oligarchic }
		localization_key = auth_oligarchic
	}
	…
}

Then go to the localisation files and just use [<scope>.GetAuthorityName] to call this scripted loc. This instance of scripted loc is designated to be called from country scopes, but there is actually no scope type limitations on scripted loc itself.

Scripted variables[編輯 | 編輯原始碼]

Scripted variables are defined at "common/scripted_variables/xxx.txt".

How to use[編輯 | 編輯原始碼]

Scripted variables are no game objects. They are only "@" variables to be used from other game files. A game file can have its own "@" variables defined but those variables can't be used by other game files. However, scripted variables are shared through all game files.

For example, we can define a scripted variable like this:

@example = 2

And use it like this:

example_scripted_effect = {
	while = {
		count = @example
		shift_ethic = ethic_$ETHIC$
	}
}

Or this:

example_scripted_effect = {
	while = {
		count = $COUNT$
		shift_ethic = ethic_$ETHIC$
	}
}
example_scripted_effect = { ETHIC = materialist COUNT = @example }

Modifiers can also have "@" variables for their numeric values.

Modifiers[編輯 | 編輯原始碼]

Since patch 3.0[1] there is a modifiers multiplier parameter for add_modifier, were you can multiply numeric values.

effect = {
		add_modifier = {
		modifier = soul_diet1
		multiplier = 6
		days = 360
	}
}

Flags[編輯 | 編輯原始碼]

Flags are boolean values (flag is either present or not), which can be attached to the following scopes: leader, planet, country (first_contact), fleet, ship, species, pop (pop_faction), federation, galactic_object (ambient_object), megastructure, espionage_operation or global.

The command to set or clear a flag are:

  • set_<scope>_flag = <flag_name>
  • set_timed_<scope>_flag = { flag = <flag_name> days = <int> }
  • remove_<scope>_flag = <flag_name>

Flags can be checked via conditions, for the flag presence or the duration since the flag has been set (not yet implemented):

  • has_<scope>_flag = <flag_name>
  • had_<scope>_flag = { flag = <flag_name> days = <duration> }

Note that modifiers are somewhat similar to flags, but in addition they alter the statistics of the scope they are attached to.

Dynamic flags[編輯 | 編輯原始碼]

The flag name may be dynamic, by appending @ and a scope (leader, country or title):[2]

It only affects how the actual flag name is created, but doesn't change how the flag is checked.

FROM = { set_leader_flag = is_friend_of_@ROOT }

How to use[編輯 | 編輯原始碼]

For example, if a leader has a leader ID of 140, the saved leader flag will be is_friend_of_140.

They can also be used in triggers: has_leader_flag = is_friend_of_@FROM

Use of dynamic flags is currently only supported for set|remove_scope_flag commands and has_scope_flag conditions. They cannot be used in the flag line of the create_leader command (flags used in instances other than those listed previously must be static).[3]

Note that scopes saved as variables in event targets can be used in dynamic flags as well.[4]

帝國 帝國思潮政府 • 國民理念 • 起源承諾議程傳統 • 飛升天賦法令政策遺珍科技自定義帝國
人口 崗位派系
領袖 領袖領袖特質
物種 物種物種特質
行星 行星行星特徵 • 軌道礦藏建築 • 區劃行星決議
星系 星系恆星基地巨型結構蟲洞 • 星門地圖
艦隊 艦隊艦船 • 部件
地面戰 陸軍轟炸姿態
外交 外交 • 聯邦 • 星海共同體評價修正宣戰理由 • 戰爭目標
事件 事件異常現象特殊項目考古遺址
遊玩 遊玩定義研究 • 經濟遊戲開局
動態修改 動態指令效果觸發條件作用域修正變量AI
媒體/本地化 Maya 導出器圖形肖像旗幟事件圖片界面圖標音樂本地化
Other 控制台命令存檔編輯Steam 創意工坊模組製作教程