Dynamic modding

From Stellaris Wiki
Jump to navigation Jump to search

Version

Outliner top.png
Please help with verifying or updating older sections of this article. At least some were last verified for version 2.6.

This article is for the PC version of Stellaris only.

This page is about the abstract but super flexible modding features, namely Effects and Conditions as well as scripted_loc and scripted_variables.

Effects[edit]

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[edit]

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[edit]

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[edit]

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:

# defination
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:

# defination
example_scripted_effect = {
	while = {
		count = $COUNT$
		shift_ethic = ethic_$ETHIC$
	}
}

# calling
example_scripted_effect = { ETHIC = materialist COUNT = 2 }

Parameter Conditions[edit]

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 "Strange New Worlds" use this feature a little more often.

Inline Math[edit]

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.

 # 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
 	}
 }

Conditions[edit]

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[edit]

Similarly, there are more than singular statements of Conditions 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[edit]

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[edit]

Scripted triggers do also have parameters.

# defination
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 Loc[edit]

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

How to Use[edit]

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[edit]

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

How to Use[edit]

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.

Empire EmpireEthicsGovernments • Civics • OriginsMandatesAgendasTraditions • Ascension PerksEdictsPoliciesRelicsTechnologiesCustom Empires
Pops JobsFactions
Leaders LeadersLeader Traits
Species SpeciesSpecies Traits
Planets PlanetsPlanetary Feature • Orbital DepositBuildings • DistrictsPlanetary Decisions
Systems SystemsStarbasesMegastructuresBypassesMap
Fleets FleetsShips • Components
Land Warfare ArmiesBombardment Stance
Diplomacy Diplomacy • Federations • Galactic CommunityOpinion ModifiersCasus Belli • War Goals
Events EventsAnomaliesSpecial projectsArchaeological Sites
Gameplay GameplayDefinesResources • Economy
Dynamic modding Dynamic moddingEffectsConditionsScopesModifiersVariablesAI
Media/localisation Maya exporterGraphicsPortraitsFlagsEvent picturesInterfaceIconsMusicLocalisation
Other Console commandsSave-game editingSteam Workshop