Barotrauma

Barotrauma

40 ratings
DIY POSTERS - How to create a poster modification for Barotrauma
By Dan Murphy Jr.
Is the inside of your submarine getting a bit boring? Tired of seeing the same room over and over? Coalition decor got you feeling down? Here is a guide for making posters to stave off boredom and insanity.
2
   
Award
Favorite
Favorited
Unfavorite
Part 1: Images and textures
To start, you need to decide on what image or picture to put on your poster. A pet, a character, a funny joke from the internet, fine art, anything that would look clear at a low resolution will work. I don't recommend text or caption memes (except block letters) as it cannot be read when shrunken down to fit in a submarine.
Your poster idea might already be a mod on Steam Workshop, many posters have already been made. Steam Workshop posters.
I recommend you start by getting a single image working as a textured item in-game while reading this guide, then adding more images later, or you may need to fix many repeated bugs.

For this guide, I will use a picture of a cat.
Source of cat[www.flickr.com]
cat license[creativecommons.org]



Navigate to the 'LocalMods' folder of your Barotrauma installation. By default, this should be at
C:\Program Files (x86)\Steam\steamapps\common\Barotrauma\LocalMods

Create a new folder for your mod, and name it. If you upload your completed mod to the Workshop, any files inside this folder will be shared but the name of the folder will not. Just don't confuse yourself with names like 'New folder' or 'mymod' or 'mymod1'. This folder will be referred to as the 'ModDir'. I will use 'cat poster mod' in my demo.



To turn the cat picture into a poster, you must first turn the cat into a texture.
You should create a folder inside the ModDir to hold textures of the posters. I suggest a name like 'textures' or 'Art' or 'posters' or 'IMG', something short. It's not strictly necessary but it prevents a mess.



Now to make the texture from the original image. You should make a copy of the image first, in case you make a mistake.

Crop and resize the image until it is less than 150x150 pixels. The Windows 10 Photos App can crop and resize the image, you can use alternatives such as Microsoft Paint, or Paint dotNET[www.getpaint.net]. The crop icon is circled in green.



Click the three dots icon ('the crumbs') on the top right (circled pink) and you will see a drop down menu. Here is the resize option (circled yellow).



Further Details:
Anything larger than 150x150 pixels will be difficult to place inside the submarine, as most are cluttered with machines, objects and decor by default.

You can shrink the sprite down and increase the image dimensions, half scale sprite with double resolution texture works wonderfully for static sprites. This is what the developers appear to use, it's probably to avoid aliasing issues and visible pixels. Just don't go crazy with high resolution textures for a single tiny item, there will be performance impact.

Textures that aren't divisible by 4 will lead to annoying yellow warnings in the F3 Console. If the texture dimensions are not divisible by 4, it cannot be compressed, which might also degrade performance. It's easy if you stick to dimensions that are a multiple of 20. Examples of some satisfactory texture dimensions: 128x128, or 80x140, or 60x120. 200x200 is too large, but scale the item by '"0.5" and it will fit as if it is 100x100.



If the image was not a PNG beforehand (like the cat I found), save as a PNG. Your editing program may 'export' as a PNG instead. I don't think Barotrauma supports textures in any other file format.



This is the texture for the poster, I saved it to the 'textures' folder. Using a folder is not strictly necessary but if you have lots of textures, it can help you organise where they are meant to go.
Part 2: XML - the file list
Now that you have made the texture made, and you have sorted the folders, it's time to add scripts. Barotrauma mods use XML[regalis11.github.io] (apart from a few very complex exceptions). To edit XML, Windows Notepad is good enough for now.

For the first XML script, navigate to the ModDir. In my demonstration, I named it 'cat poster mod'. Then, right click, move mouse cursor over the new menu to the bottom right, cursor down to the box that says 'New". Click the box that says 'Text Document'.



Before you go further, you must make sure that file name extensions are not hidden. If you see "New Text Document" instead of "New Text Document.txt", you will need to change Windows File Explorer settings to 'Show File Name Extensions'.[www.howtogeek.com]

Rename the new text document to "filelist.xml". This XML script[regalis11.github.io] will tell Barotrauma that this a new mod, what the rest of the mod is, and where the rest of the mods files are located.

Next, copy and paste this template script into "filelist.xml". This script works with the texture and folders that I created beforehand, using the texture to draw a sprite and use the sprite with a virtual item.

<?xml version="1.0" encoding="utf-8"?> <contentpackage name="Cat Poster" corepackage="False"> <Item file="%ModDir%/catposteritem.xml" /> </contentpackage>

The first line tells the game that "filelist.xml" is valid XML. Don't worry about it, but don't make changes, just copy the whole first line for every file list you make.

The second line declares the mod's name is "Cat Poster" to the game. All Barotrauma game assets are sorted into a 'Content Package', and each 'Content Package' should have a somewhat unique name. There are already mods with almost identical names, so please add numbers, initials, your steam handle or even emojis if your 'Content Package' name is similar to another.
This tiny poster mod isn't a big complex 'Core Content Package', since it doesn't replace or override the original game assets. Don't worry about it unless you're heavy into modding.

The third line points to an XML file that will need to be created next, 'catposteritem.xml'. This file will attach the texture to a virtual item that can be placed on submarine and outpost walls like the Components[barotraumagame.com], it is an Item XML file.[regalis11.github.io] While the content-package-filelist must ALWAYS be named 'filelist.xml', the item XML can have any name, as long as the name is referenced in the file list and the file extension is correct.

Older versions of Barotrauma required each texture file path to be specified in this filelist.xml, but this is no longer the case. Don't bother, as it is a waste of time, and any mistakes will show up as an error in the console.

The fourth line ends the script, and mustn't be cut off. Be careful when copying and pasting scripts, it's easy to mistakenly forget or remove the last line.

Originally posted by A Wise Old Hermit using a quote box to get your attention:
When copying this text for your own mod, make sure to replace the name text and any filenames/folders that you changed.
Part 3: XML - Item template
Now we create another 'New Text Document'. Rename to the file name you used on line 3 of "filelist.xml". I named mine 'catposteritem.xml', as it is am 'Item[regalis11.github.io] Content Type[regalis11.github.io]' XML file.

Copy and paste this template into the second XML file.

<?xml version="1.0" encoding="utf-8"?> <Items> <Item name="Cat Poster" identifier="catposter" description="Description" category="Decorative" scale="0.5" maxstacksize="4" pickdistance="200" tags="mediumitem" isshootable="True" Indestructible="True" AllowRotatingInEditor="True" CanFlipX="False" CanFlipY="False" > <Body width="100" height="148" density="10"/> <Sprite texture="%ModDir%/textures/cat_texture.png" depth="0.845" sourcerect="00,00,100,148" origin="0.5,0.5"/> <Holdable selectkey="Select" pickkey="Use" slots="Any,RightHand,LeftHand" msg="ItemMsgDetach" PickingTime="1" aimpos="0,0" handle1="0,0" Attachable="True" AttachedByDefault="True" Aimable="True"/> <Price baseprice="60" soldeverywhere="false"> <Price storeidentifier="merchantoutpost" maxavailable="1" /> <Price storeidentifier="merchantcity" minavailable="1" maxavailable="2" multiplier="0.9"/> </Price> <Fabricate suitablefabricators="medicalfabricator" requiredtime="5" amount="1"> <RequiredItem identifier="organicfiber" /> </Fabricate> <Deconstruct time="1"> <Item identifier="organicfiber" /> </Deconstruct> <Fabricate suitablefabricators="vendingmachine" requiredtime="1" requiredmoney="65" fabricationlimitmin="1" fabricationlimitmax="1" /> <PreferredContainer primary="crewcab" /> <PreferredContainer secondary="wreckcrewcab,abandonedcrewcab,abandonedstoragecab,steelcabinetwrecked,mediumsteelcabinetwrecked" maxamount="1" spawnprobability="0.003" allowtransfershere="False" /> </Item> </Items>
Part 4: XML - Items explained
Just like before, the first line is necessary. This line and anything not mentioned in detail should be copied but untouched.
The second line says that we are declaring items in lines three and onward. Don't mix up 'Items' and 'Item'.

The third line names the item (this is the word that players will see when cursor is placed over item in inventory screen), gives the item an "identifier", and goes on to list attributes that change how the item behaves.
Every object in Barotrauma must have a unique identifier, even if it has the same name as another object. Identifiers are the "game name" used by vanilla Barotrauma and by mods/scripts, but you won't need to remember it unless you're using the console or making a mod. Please don't use simple IDs like '1' or 'poster4', as they will conflict with other mods that used the exact same identifiers, causing bugs and possibly crashes.
'maxstacksize' is how many of the item can stack into a container slot. Small items in Barotrauma usually stack to 8, but the posters are bulky, so I set it to 4. Not a big deal for this item.
The 'category' sorts how the item is displayed in the submarine editor.
I think 'pickdistance' is the maximum distance from the center of the item's sprite that players can pick (grab) the item. If a player is outside the 'pickdistance', they can't detach it without moving closer.

'scale' is very important, it is a decimal number that controls the item's size. The 'scale' attribute overrides the 'Body' tag in line four.
If you want to increase definition of a texture, you can set [scale="0.5"] and make a texture double the dimensions on both sides. This scale is used for most textures in vanilla Barotrauma. Be warned, larger resolution textures perform significantly worse. Don't bother with [scale="0.4"] or anything smaller for posters, because Barotrauma player crew can't zoom in to see the detail.
The 'description' can be read by the player when they mouse over the item when held/stored, it is also shown in the fabricator.
The 'tags' attribute is powerful. It's useful for mods, and bots use it to sort items. In this case we prevent the poster from being stored in small spaces, like a toolbelt or railgun shell. (If you want, you can use [tags="smallitem"] instead.)
'isshootable' allows you to place the poster by selecting it in your hotbar, then left clicking on a submarine wall. Otherwise, you would have to aim at the wall and press the Use key [E].
'Indestructible' prevents fire/water damaging an item. Doesn't prevent deconstruction.

Line four is important, it tells Barotrauma the virtual physical dimensions of the item. Just match the width and height of the texture. If done incorrectly, the texture won't look right as it will tile or stretch on the item. Density controls how fast an item sinks in water. We keep the density low here, because it's a thin light paper poster.

Line five turns the texture into a sprite, it is critical that there are no misspellings or mistakes on this line. Make sure the folder and image filename are correct. Don't mess with the depth unless you know what you're doing, 0.85 puts the poster sprite just in front of most of the background textures. The 'sourcerect' attribute has the four values of the texture that the sprite is from. (x begin coordinate, y begin coordinate, x length, y length). We don't need to change 'origin' since we want the sprite to stay on the center of the item.

Line six is what allows human characters [such as submarine crew] to pick and place the poster, unlike a static decoration that can only be placed in the submarine editor. "Select" is left mouseclick by default, so the poster is placed using a mouseclick. "Use" is the E key by default, so pressing E on your keyboard will detach a poster from the wall . Slots allow an item to be held with either hand in this case, but can be used force both hands to hold an item (for large items). [msg="ItemMsgDetach"] is the magic of this type of mod, it allows an item to be detached from a wall once placed.

The next few lines configure which merchants can buy and sell the item. This is optional.
Small outposts will not have all merchant types. 'minavailable' sets the minimum number of an item that the merchant will stock. 'multiplier' changes the price at a merchant type by multiplying the 'baseprice' by the provided decimal number. 0.5 is 50% discount (half price, good deal), 2.0 is double price (ripoff).

With the fabrication tags, a Medical Fabricator can turn a single organicfiber into a Cat Poster in 5 seconds. If you want, you can replace the "organicfiber" identifier with "redpaint" or "plastic" or "iron", whatever item you want. You can also choose between regular mechanic fabricator and medical fabricator if you wish.
If you have lots of modded craftable items (such as EK Weapons, Enhanced Armory), they will cause lag whenever the fabricator is opened due to all the recipes. Adding your recipes to the medical fabricator is a workaround until this is fixed. Perhaps it's not for the best to have craftable posters. You can omit these lines, and buy them at merchants, vending machines, add them in server settings or spawn them with console commands.

Optionally, the Deconstructor can turn the poster into "organicfiber" in 1 second, for emergency bandages, or making a new poster. Remove this line if your crew often recycle your precious posters.

As an alternative to merchants, the poster can also be bought at vending machines. Vending machines cannot buy items back, but they are better for performance reasons. Talking to merchants can cause lag spike, especially with lots of mods.

The PreferredContainer tag specifies where bots should place items when sorting. It also provides you the chance to spawn items in tagged containers. Probability is a decimal number, '1.0' means it should spawn every time a new campaign is started.

The second last line is the tag that ends the individual item, and final line is the tag ends the XML items document. If you want to add multiple posters, copy every line from [<Item name .../>] until [</Item>], and paste it just above the final line, making sure that everything is aligned. If the indentation is incorrect, the in-game console will pop up with an error.



To put it another way;
[<Items>] must be above the first poster item, it is the root tag
[<Item ...] must be at the beginning of each poster item, two spaces from the left margin,
[</Item>] must be at the end of each poster item, two spaces from the left margin,
and [</Items>] must be the final line in the XML, closing the root.
It's quite easy to cut off the closing statement, so don't forget it.
Part 5: Testing a local mod
You're done with XML. Boot up Barotrauma to the main menu. UI looks slightly different for 1.0 update, but it sill works the same.

If there is a mistake, the console in the top left corner of the screen will spit out a warning in yellow text or an error in red text. Quit Barotrauma, fix the script/texture and try again. If you're stuck, you might be able to ask for help in the official Undertow Discord[discord.gg] with some luck and excellent manners.



Even though we're only testing the mod locally, click 'STEAM WORKSHOP' in the main menu, under 'CUSTOMIZE'.



Under the 'INSTALLED MODS' tab, find the box with the pencil icon on it. It should be in the list on the right. That's your local mod! Double click on the name to enable it, now it's in the left list. Workshop mods have an arrow icon whereas local mods have a pencil icon. If you want, you can click the pencil to open the ModDir in Windows Explorer, it's a neat shortcut.



You can check if the poster works by using the submarine editor to load into a sub, dragging the poster into the submarine, then clicking the test button to run a test game. Alternatively, you can start a solo campaign and buy the poster from the outpost shops, or vending machines.



With the poster in your hotbar inventory, equip it in hands. Left click to attach the poster to the wall. Press E to take the poster from the wall and back into your hands. For extra precision, hold right click to show the component attachment grid, this guide will show you where the poster will stick to the submarine wall.



If your poster sprite is the wrong size or scale, you can enter the sub editor, spawn the poster item, select it, open the console with F3 key and type `spriteeditor`. Note that your character orientation can flip the poster along the vertical axis, unless you add [CanFlipX="False"] after the item tag.

You are now free to do what you want with your posters. You may want to upload to the steam workshop using the 'PUBLISH' top right tab of the 'STEAM WORKSHOP' submenu. If you don't want your mod to be public, you can set it as unlisted on Steam Workshop, or send the LocalMod to the host in a .zip file. Hosting with a LocalMod means that clients must redownload the mod every time they join the game. I will try to add any public poster mods into my Steam Workshop collection.



Thanks for reading my guide, criticism is welcome. Feel free to reupload or repost the text, as long as you remember the link to the cat you can share the screenshots too.
Part 6: Pro Tips
Pro Tip 1: If your mod has 4 or more posters you really should use a spritesheet. Every single time Barotrauma loads another PNG file, there is a performance impact. Remember to leave alpha space between poster sprites, since Barotrauma still has a strange rendering bug that affects the leftmost column of pixels.

Pro Tip 2: If you ever expect to add more posters to your mod, or if your mod is public, or if you are ever going to modify the posters in future, using a text localization file is a good idea. Removing hardcoded XML names and descriptions is a pain.
If you're lazy, you can just reuse a name from the vanilla Barotrauma poster, so that the poster name is literally the 'Poster' but already translated into the default languages. Add the following after the Identifier tag.
fallbacknameidentifier="op_circusposter"

Pro Tip 3: To optimise PNG texture filesize for public mods on Steam Workshop, you can use a tool to compress PNG like PNGOUT, pngcrush or a web-based PNG lossless optimizer.
Part 7: Further resources
Barotrauma Modding Guide[regalis11.github.io] was recently added to GitHub, it replaced the official Steam Guide. Here's the relevant Item attribute page.[regalis11.github.io]

FakeFish guide: Modding reference - the older depreciated official modding guide on Steam
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2181462640

Barotrauma DB[barotrauma-db.vercel.app] (a database of vanilla Barotrauma items)
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2766028795

Official Barotrauma wiki[barotraumagame.com]

Yak' All made a helpful video tutorial on YouTube

'How to add an Item to your Mod' by [bk]schorote
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=1851352576

'The SHEDU Item Modding GUide' by SHEDU
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2907929934

This 'sourcerect' guide image with photoshop UI that I stole from the Undertow discord, made by Jlobblet.
25 Comments
Dan Murphy Jr.  [author] 29 Jul, 2023 @ 7:19pm 
You mean a PNG that is wider than it is tall? That still works fine, many of my poster mods are oriented like landscape photos rather than portraits. You just need to match the sourcerect and the body values. The first sourcerect number will be larger than the second one, and the third will be larger than the fourth.
buzz 29 Jul, 2023 @ 12:02pm 
i followed this guide and got it to work, but how to i make the mod give me a Landscape orientation?
sawert42 30 Jun, 2023 @ 5:47pm 
For the ppl having [Failed to load file "Localmods/FolderName/xmlfile.xml" of type 'item' not found]
problem, in both xml files use %ModDir% instead of your own folder name, that helped me at least so maybe it will help others as well
Dan Murphy Jr.  [author] 17 Mar, 2023 @ 10:17pm 
Could you please post or dm me a screenshot of the error message? Maybe I can have a look. I'm not exactly clear about what is wrong, and if three people have the same issue, I must have put a mistake in my guide.
CamoNinja3600 17 Mar, 2023 @ 9:44pm 
Same @zyrph
Zyrph 17 Mar, 2023 @ 9:42pm 
Im having issues with it same as the stalker guy getting the same message of type 'item' not found. I don't have any periods or spaces in the names or anything
Dan Murphy Jr.  [author] 28 Feb, 2023 @ 6:29am 
Just learned that sometimes there are texture tiling issues in the Submarine Editor if you use a massive texture. These can disappear in an actual Barotrauma game, showing the proper sprite instead of 4 tiny repeated textures on the sprite, or a quarter sized texture on the sprite.

I didn't notice since I test all my mods using sub editor only :barotrauma:. Silly me.
Dan Murphy Jr.  [author] 4 Dec, 2022 @ 4:51pm 
@Conrad2Jubie I'm not sure if it will work, but you can try adding a few more attributes after the <Holdable /> tag.
https://regalis11.github.io/BaroModDoc/ItemComponents/Holdable.html
@Xenosilver63 You will need to use an image editor like Paint 3D to remove the white background. Paint.NET , GIMP, Photoshop all have the ability to do this as well, and you can try online image editors if you wish.
Destrino 4 Dec, 2022 @ 12:58pm 
i fixed he indentation issue however i would like to know how to make certain pngs's with white backrounds transparent?
Conrad2Jubie! 4 Dec, 2022 @ 12:29pm 
What i mean by "aim" is to physically raise the poster in the air when attempting to place said poster.