动态模组创作

本页面部分全部内容上次核对于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 创意工坊模组制作教程