群星
ParaWikis
Notice
: Undefined index: HTTP_ACCEPT_LANGUAGE in
/data/wwwroot/www.parawikis.com/skins/Liberty/LibertyTemplate.php
on line
185
最新百科
都市天际线2百科
英雄无敌3百科
维多利亚3百科
奇妙探险队2百科
罪恶帝国百科
英白拉多:罗马百科
热门百科
群星百科
欧陆风云4百科
十字军之王2百科
十字军之王3百科
钢铁雄心4百科
维多利亚2百科
ParaWikis
申请建站
ParaWikis
ParaCommons
最近更改
随机页面
加入QQ群
工具
链入页面
相关更改
特殊页面
页面信息
页面值
阅读
编辑
编辑源代码
查看历史
讨论
编辑“
模组创作教程
”(章节)
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
== Writing a first mod == === \common\governments\civics === ==== Example civic ==== {{See also|Government modding}} We will begin by creating a new civic. Civics and origins are stored in <code>\common\governments\civics\</code>. Origins are civics with a few changes. An example civic code (<code>\common\governments\civics\00_civics.txt</code>): <syntaxhighlight lang="Haskell"> civic_beacon_of_liberty = { potential = { ethics = { NOT = { value = ethic_gestalt_consciousness } } authority = { NOT = { value = auth_corporate } } } possible = { authority = { value = auth_democratic } ethics = { OR = { text = civic_tooltip_egalitarian value = ethic_egalitarian value = ethic_fanatic_egalitarian } NOR = { text = civic_tooltip_not_xenophobe value = ethic_xenophobe value = ethic_fanatic_xenophobe } } } random_weight = { base = 5 } modifier = { country_unity_produces_mult = 0.15 } } </syntaxhighlight> Let us breakdown the civic: {| class="wikitable" |- | civic_beacon_of_liberty || civic key, used to reference it in the code, including localisations |- | potential || conditions for civic to be available for choice |- | possible || conditions for civic to be a valid choice |- | random_weight || determines likelihood of appearing for a randomly generated empire. If two civics exist and both have a weight of 5 then chances are 50:50. |- | modifier || direct effects of a civic on an empire. More complex way is to use events checking for a civic and executing effects. |} This specific civic has localisation key '''civic_beacon_of_liberty''', is a '''potential''' choice only for empires which a) ethics are '''NOT''' gestalt and b) do '''NOT''' have authority corporate. Any empire which meets the above criteria will have the civic as a choice, but it is '''possible''' to take the civic only if a) authority '''EQUALS''' democratic and b) ethics are '''EQUAL''' to egalitarian OR '''EQUAL''' to fanatic egalitarian, and '''NEITHER''' are equal to xenophobe or fanatic xenophobe. Note how '''text =''' function is used to invoke a custom tooltip instead of automatically generated one. This is usually not needed but can be useful. This civic has an absolute '''weight of 5''' for the purpose of galaxy generation. If there are two other civics of weight 45 and 50, then the civic in question would have only 5% chance of appearing on a randomly generated empire, in principle (45 + 50 = 95 vs 5). The civic gives the country a '''modifier''' of +15% Unity production. Civic definitions [[Government modding|do not support complex conditions]] but it is worth to familiarise yourself with [[Conditions|how logical operators work]]. ==== Custom civic ==== {| class="wikitable" style="margin:auto" |- ! Folder !! File !! Content |- | [[File:VSCode new mod 1.png|thumb|right|Open VSCode, File > Open root folder of our tutorial mod (will contain descriptor.mod) and create a folder for common, governments, and then civic folder. Folder structure has to match that of a Stellaris installation: \common\governments\civics\ .]] || [[File:VSCode new mod 2.png|thumb|right|Create a new civics file named tutmod_civics.txt .]] || [[File:VSCode new mod 3.png|thumb|right|Write the first line containing key name of the new civic: tutmod_civic = {} . If CWTools work you should see an error tooltip indicating lack of localisation for that key (will be fixed later).]] |} {| class="wikitable" style="margin:auto" |- ! CWTools suggestion !! TAB !! Repeat |- | [[File:VSCode new mod 4.png|thumb|right|Click between two '''{}''' brackets and start writing content of the block. Start a new line by pressing enter and try to write '''potential'''. Correctly installed CWTools will give you suggestions you can shuffle with arrow keys. Press TAB or click with mouse when you find '''potential'''.]] || [[File:VSCode new mod 5.png|thumb|right|CWTools will fill and format selected suggestion for you.]] || [[File:VSCode new mod 6.png|thumb|right|Start a new condition inside '''potential''' named '''ethics'''. Use CWTools suggestions as often as possible. It will save you a lot of time.]] |} Let us write a code of the new civic using <kbd>civic_beacon_of_liberty</kbd> as a reference. [[File:VSCode CWTools writing.gif|center]] ===== Code formatting ===== Note how you can comment out a part of code using '''#''' sign. Anything after '''#''' in a specific line will not be read by the game. We will now make our own code by swapping out parts we do not like and inject our own. First, let us remove <code>auth_corporate</code> exclusion and add a comment on <code>ethic_gestalt_consciousness</code> exclusion. <syntaxhighlight lang="py"> # civic_beacon_of_liberty = { tutmod_civic = { potential = { ethics = { NOT = { value = ethic_gestalt_consciousness } } # authority = { # NOT = { # value = auth_corporate # } # } } possible = { authority = { value = auth_democratic } ethics = { OR = { text = civic_tooltip_egalitarian value = ethic_egalitarian value = ethic_fanatic_egalitarian } NOR = { text = civic_tooltip_not_xenophobe value = ethic_xenophobe value = ethic_fanatic_xenophobe } } } random_weight = { base = 5 } modifier = { country_unity_produces_mult = 0.15 } } </syntaxhighlight> [[File:VSCode CWTools formatting.gif|center|Formatting with VSCode and CWTools.]]<!-- GIF is too wide for right --> ===== Adding content ===== We are adding an additional condition for ethics. OR = { text = civic_tooltip_materialist value = ethic_materialist value = ethic_fanatic_materialist } The code should now look like below: <syntaxhighlight lang="Ruby"> # civic_beacon_of_liberty = { tutmod_civic = { potential = { ethics = { NOT = { value = ethic_gestalt_consciousness # No gestalt. } } # authority = { # NOT = { # value = auth_corporate # } # } } possible = { authority = { value = auth_democratic } ethics = { OR = { text = civic_tooltip_materialist value = ethic_materialist value = ethic_fanatic_materialist } OR = { text = civic_tooltip_egalitarian value = ethic_egalitarian value = ethic_fanatic_egalitarian } NOR = { text = civic_tooltip_not_xenophobe value = ethic_xenophobe value = ethic_fanatic_xenophobe } } } random_weight = { base = 5 } modifier = { country_unity_produces_mult = 0.15 } } </syntaxhighlight> To be a valid choice an empire has to be to some degree materialist, to some degree egalitarian, and neither xenophobe nor fanatic xenophobe. We did not have to worry about creating <code>civic_tooltip_materialist</code> localisation because it already exists in the game files. === Localisations === ==== Localisation files ==== [[File:VSCode CWTools localisations.gif|right|Generating missing localisation keys with CWTools.]] {{Main|Localisation modding}} Useful console commands: reload text – reloads localisation table. switchlanguage english – switches used language and reloads localisation table. CWTools highlights keys which are missing localisations, you can see full list of potential issues at the bottom of VSCode window: Localisation key tutmod_civic is not defined for English Localisation key tutmod_civic_desc is not defined for English We need to create a localisation folder structure. Create <code>\localisation\english\</code> folders inside root mod folder first, and then create <code>tutmod_l_english.yml</code>. VSCode will automatically encode file in UTF8 with BOM which Stellaris localisation files need. Both VSCode and Notepad++ are able to easily change file encoding if needed. Localisation files require language declaration in the first line. Simply write: l_english: Supported language declarations are: braz_por english french german polish russian simp_chinese spanish We have file prepared. Switch back to <code>tutmod_civics.txt</code> tab, '''right mouse click > Command Palette > Generate missing loc for all files'''. Copy generated strings into loc file. We will fill the placeholders with the following information: <syntaxhighlight lang="yaml"> l_english: tutmod_civic: "Semper Exploro" tutmod_civic_desc: "This society prioritised scientific exploration over military expansion in the early space age." tutmod_civic_effects: "Start with a $science$ and assigned $scientist$ instead of $OUTLINER_FLEETS$."</syntaxhighlight> Note the '''$''' signs which can be used to refer to other localisation key, be it existing in game or modded one. You can view vanilla keys directly in <code>SteamLibrary\steamapps\common\Stellaris\localisation\english\</code> . Due to the way Stellaris localisations work, there is no way to set up a fallback localisation for other languages to use. If you generate localisations for English only, users playing the game in other language will see a raw key name, ie. <code>tutmod_civic</code>. We have to copy the localisation file <code>\localisation\english\tutmod_l_english.yml</code> to the corresponding language folders, change file name, and adjust language declaration at the beginning of the file: \localisation\english\tutmod_l_braz_por.yml \localisation\english\tutmod_l_english.yml \localisation\english\tutmod_l_french.yml \localisation\english\tutmod_l_german.yml \localisation\english\tutmod_l_polish.yml \localisation\english\tutmod_l_russian.yml \localisation\english\tutmod_l_simp_chinese.yml \localisation\english\tutmod_l_spanish.yml With an example tutmod_l_braz_por.yml containing: <pre>l_braz_por: tutmod_civic:0 "Semper Exploro" tutmod_civic_desc:0 "This society prioritised scientific exploration over military expansion in the early space age." tutmod_civic_effects:0 "Start with a $science$ and assigned $scientist$ instead of $OUTLINER_FLEETS$."</pre> Advantage of using '''$''' signs to reference other keys is that we do not have to translate string multiple times, game will automatically pull the content for the language user plays on. This might not always result in a grammatically correct sentence, it usually works best with the key being used in nominative case. ==== Custom tooltips ==== Game automatically generates localisations for things like tooltips based on effects in the game. For civics it means we do not have to write what effect civic has, as the game will pull all modifiers we wrote and generate sentences, ie. having below in civic definition: <pre>modifier = { country_unity_produces_mult = 0.15 }</pre> will result in the following in the effects tooltip: Monthly Unity: +15% Sometimes we want to add a text for more effects. We will reference <code>tutmod_civic_effects</code> in the <code>tutmod_civics.txt</code> file for <code>tutmod_civic</code> and swap modifier while we are at it. <pre># modifier = { # country_unity_produces_mult = 0.15 # } description = "tutmod_civic_effects" modifier = { ship_science_cost_mult = -0.25 }</pre> Tutorial civics file should now look as below: [[File:Tutmod civic tooltip no gfx.png|thumb|right|Tutorial civic tooltip without icon.]] <syntaxhighlight lang="Ruby"> # civic_beacon_of_liberty = { tutmod_civic = { potential = { ethics = { NOT = { value = ethic_gestalt_consciousness # No gestalt. } } # authority = { # NOT = { # value = auth_corporate # } # } } possible = { authority = { value = auth_democratic } ethics = { OR = { text = civic_tooltip_materialist value = ethic_materialist value = ethic_fanatic_materialist } OR = { text = civic_tooltip_egalitarian value = ethic_egalitarian value = ethic_fanatic_egalitarian } NOR = { text = civic_tooltip_not_xenophobe value = ethic_xenophobe value = ethic_fanatic_xenophobe } } } random_weight = { base = 5 } description = "tutmod_civic_effects" modifier = { ship_science_cost_mult = -0.25 } # modifier = { # country_unity_produces_mult = 0.15 # } } </syntaxhighlight> === Logs === ==== game.log ==== We can use the following effect to output any string into the game.log: <pre>log - Prints a message to game.log for debugging purposes log = <string> Supported Scopes: all</pre> This is where most modders output data if they want to check how their mod works, it is especially useful for debugging event scripts. Note: it has been observed that individual instance of log effect in a code executes and writes to game.log only once per day, this is most likely to prevent log spam. ==== error.log ==== Game logs are stored in <code>\Documents\Paradox Interactive\Stellaris\logs\</code>. Modders use mostly <code>error.log</code> and <code>game.log</code> to debug the game. Start the game with the tutmod loaded and open <code>error.log</code>. You will find one line which references to tutmod (search mod prefix to quickly find relevant information): <syntaxhighlight lang="yaml">[18:22:15][government_civic_type.cpp:185]: Did not find an icon for civic: tutmod_civic</syntaxhighlight> We can use the following effect to output any string into the error.log (also see notes about game.log): <pre>log_error - Prints a message to error.log for debugging purposes. Supported Scopes: all</pre> For now all we need to know that there is an icon missing for <kbd>tutmod_civic</kbd>. Note: Game stops logging before the crash, error.log is therefore almost always useless in finding the crash cause. Crash data is stored in <code>\Documents\Paradox Interactive\Stellaris\crashes\</code> and is useful only to the Stellaris developers. ==== EXE parameters ==== There are some special [[wikipedia:Command-line interface#SwitChar|options]] for the <kbd>stellaris.exe</kbd> you can input to improve your logging/debugging: <syntaxhighlight lang="apache"> -script_debug - (Can ignore) -debug_mode - Extra logging -debugtooltip - Starts first game you enter with debugtooltip -logprefix - Modifies each log file with the set prefix -logpostfix - Modifies each log file name with the set postfix -logall - Logs no longer fail to log duplicate string values </syntaxhighlight> === Events === ==== fire_only_once ==== : ''See also: [[Event modding]], [https://github.com/OldEnt/stellaris-triggers-modifiers-effects-list List of Stellaris triggers, modifiers and effects]'' [[Events|Event]] is a script which changes state of the game by using [[effects]], provided [[triggers]] are met and event was called. Create a new <code>\events\tutmod_events.txt</code> file. Every events file has to have at least one namespace declared at the beginning. We use: namespace = tutmod It is a good practice for any mod which affects gameplay (changes [[checksum]]) to notify its presence to other mods. The commonly accepted way is to set up a <kbd>global_flag</kbd> other mods can check if it exists via effect: <pre>set_global_flag - Sets an arbitrarily-named global flag set_global_flag = <key> Supported Scopes: all</pre> Example file would look like the following: <pre> namespace = tutmod country_event = { id = tutmod.1 hide_window = yes fire_only_once = yes trigger = { NOT = { has_global_flag = tutmod_installed } } immediate = { set_global_flag = tutmod_installed } }</pre> * '''<code>namespace = tutmod</code>''' – declares namespace * '''<code>country_event = {}</code>''' – declares event of country [[scopes|scope]], it is also name of an effect used to call an event. * '''<code>id = tutmod.1</code>''' – declares unique id of the event. Consists of namespace and number, separated by a stop. * '''<code>hide_window = yes</code>''' – a popup window for player will not be created. This is how most events in the game work. * '''<code>fire_only_once = yes</code>''' – successfully fired event (called and met trigger [[conditions]]) will be added to blocklist and will never be used again in current game. * '''<code>trigger = {}</code>''' – contains list of conditions ([[triggers]]) which have to be met in order for called event to fire. Default this/root scope is defined by name of event scope (country_event here). * '''<code>immediate = {}</code>''' – contains list of [[effects]] which change the state of the game when event fires. This event does not contain the <code>is_triggered_only = yes</code> declaration. This means event will be checked DAILY for EVERY country. If the event was of different scope, ie. pop_event, it would check for EVERY pop in the game DAILY. With a galaxy of 5000 pops it would mean 5000 checks every day. It is a very resource intensive way of scripting and therefore you should always add <code>is_triggered_only = yes</code>, unless there is a good reason not to. <code>is_triggered_only = yes</code> blocks event from checking itself and will require it to be called from elsewhere (more on that below). We can limit checking of the event by using the aforementioned <code>fire_only_once = yes</code>. Event still checks daily for every country, but as soon as the first country fires the event it will be blocklisted and no longer checked. Since the conditions of the event are simple (<code>NOT = { has_global_flag = tutmod_installed }</code>) event will fire as soon as game starts. Specific trigger used in trigger section is: <pre>has_global_flag - Checks if a Global Flag has been set has_global_flag = <flag> Supported Scopes: all</pre> Immediate section is self-explanatory. It contains a single effect: <pre>set_global_flag - Sets an arbitrarily-named global flag set_global_flag = <key> Supported Scopes: all</pre> This country event is read as the following by the game: '''Every country must check daily conditions of tutmod.1 event which are "global_flag tutmod_installed has NOT been set". If true set_global_flag = tutmod_installed, then add event to blocklist. ''' ==== is_triggered_only ==== As a general rule every event should have <code>is_triggered_only = yes</code> declared. This makes game not checking the event until it is specifically called by an effect or on_action. Below is a code for the second tutmod event (should be written in <code>\events\tutmod_events.txt</code>): <syntaxhighlight lang="py"> # Removes military fleets, grants science ship and scientist. # Scopes: # Scope: root: country this: country country_event = { id = tutmod.2 hide_window = yes is_triggered_only = yes # Fire only when called from elsewhere. trigger = { has_civic = tutmod_civic # Must have tutmod_civic civic. } immediate = { every_owned_fleet = { # Iterate through every owned fleet of THIS country. limit = { is_ship_class = shipclass_military # only fleets meeting shipclass_military criteria } delete_fleet = { target = this # Delete THIS fleet. kill_leader = no # Do not delete leader of THIS fleet (unassigns). } } create_leader = { # Create leader for THIS country. class = scientist # Specified scientist class. species = this # Where THIS is the scope of where effect was written in (country, therefore species will be main country species). } create_fleet = { # Create fleet for THIS country. effect = { # Execute list of effects for THIS fleet. set_owner = prev # Set owner of THIS fleet to PREV (PREV/previous scope being country we in previous brackets refered to as THIS). create_ship = { # Create ship for THIS fleet. random_existing_design = science # of random design which is science ship. graphical_culture = owner # Visual style of the ship is the same as OWNER of the fleet (can use PREV here). } set_location = { target = owner.capital_scope.solar_system.starbase # Set location of the fleet to owner's capital_scope's solar_system's starbase. # distance = 0 # angle = random # direction = out_system } assign_leader = last_created_leader # Assigns last created leader to the fleet. } } } } </syntaxhighlight> Code is more readable in VSCode. This event has only one trigger which checks if the country <code>has_civic = tutmod_civic</code>. There are several effects in the immediate section. Most of them are self-explanatory. All of them are listed on [https://github.com/OldEnt/stellaris-triggers-modifiers-effects-list the effects list] and it is worth reviewing them. === Scopes === {{Main|Scopes}} Let us analyse scope operators used. <pre>create_fleet = { effect = { set_owner = prev create_ship = { random_existing_design = science graphical_culture = owner } set_location = { target = owner.capital_scope.solar_system.starbase } assign_leader = last_created_leader } }</pre> In the code <code>create_fleet</code> is called directly in <code>country_event = { immediate = {</code>. This means <code>THIS</code> scope of the effect will refer to the country event was fired for. root = country this = country Inside <code>create_fleet</code> effect we call a series of effects using '''<code>effect block</code>'''. Now, inside effect block, <code>THIS</code> scope operator will refer to this fleet (because it was called inside THIS fleet). root = country this = fleet prev = country Note how we can switch back to previous scope by using <code>PREV</code> scope operator. <pre>effect = { set_owner = prev</pre> Effect <code>set_owner</code> is called inside <code>THIS</code> fleet and targets <code>PREV</code>, which is country. === Common === ==== on_actions ==== {{See also|Event modding#On Actions}} We mentioned how events can be called from effects and on_actions. We can call events on_game_start to assure proper set up for the empire with <code>tutmod_civic</code>. Simply create <code>\common\on_actions\tutmod_on_actions.txt</code> file and declare events which should fire. <pre>on_game_start_country = { events = { tutmod.1 tutmod.2 } }</pre> === GFX === [[File:Tutmod civic tooltip with gfx.png|thumb|right|Tutorial civic tooltip with blank icon. Source: [https://discord.gg/WpeXm2h Stellaris Modding Den Discord Server], #shared-art channel.]] All graphical assets are stored inside <kbd>/gfx/</kbd> folder. Civics icons should be placed specifically in <code>\gfx\interface\icons\governments\civics\</code> . We need to create a <code>tutmod_civic.dds</code> which is 28x28 (resolution for civics icon). For the purpose of this tutorial we will use a blank template gratuitously donated to and available on [https://discord.gg/WpeXm2h Stellaris Modding Den Discord Server] in the #shared-art channel. \gfx\interface\icons\governments\civics\tutmod_civic.dds [https://www.gimp.org/ GIMP] and [https://www.getpaint.net/ Paint.net] are two very good tools commonly used to create Stellaris assets.
摘要:
请注意您对群星百科的所有贡献都被认为是在知识共享署名-非商业性使用-相同方式共享下发布,请查看在
群星百科:版权
的细节。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源。
未经许可,请勿提交受版权保护的作品!
为防止机器编辑,请完成下方验证
取消
编辑帮助
(在新窗口中打开)
该页面属于1个隐藏分类:
Category:含有受损文件链接的页面
×
登录
密码
记住登录
加入群星百科
忘记密码?
其他方式登录