Barotrauma

Barotrauma

AI NPCs
 This topic has been pinned, so it's probably important
RubbingMyAxe  [developer] 6 Nov, 2023 @ 2:28pm
Current Features and Goals
So this is my first Barotrauma mod and also my first time using Lua, so there are a lot of things I want to do that I am still trying to figure out. Since the Steam page is pretty bare-bones at the moment, I just wanted to write something to explain a bit how it works and where I want to go with it.

How it Works
Currently when you start a chat with "!" and part of an NPC's name, it constructs a prompt asking ChatGPT to roleplay as the character. This prompt contains a lot of information, including:

Demographic Information
  • Full Name
  • Gender
  • Primary Job and Skill Level (e.g., Expert Engineer)
  • Role (e.g., Medic, Captain, Prisoner, VIP)
  • Title (e.g., Merchant, Researcher, Husk Cultist)
  • Home Submarine/Outpost Name and Function
  • Personality Type (e.g., Joker, Professional, Rude, Broken English)
  • Map Region (e.g., Europan Ridge)

Location Information
  • Current Submarine/Outpost Name and Type (e.g., Wreck, Beacon Station)
  • Current Room Name (or “Swimming Outside” if not in a hull)

Inventory and Appearance Information
  • Weapons and Tools (important items only)
  • Outer Clothing (e.g., Diving Suit, Body Armor, Exosuit)
  • Handcuffed (Yes/No)
  • Visual Traits (e.g., Bald, Face Scars, Tattoos)
  • Items Held in Hands
  • Weapon or Item Slung on Back

Orders and Activity Information
  • List of Current Orders (sorted by priority)
  • Current Action (e.g., repairing junction box, idling, using turret)
  • Current Position (e.g., sitting in chair, lying in bed)

Mission Information
  • List of Uncompleted Missions or Objectives
  • Destination Outpost (if in transit)

Health and Status Information
  • Vitality Status (e.g., Slightly Injured, Severely Injured)
  • List of Afflictions (with severity and causes if known)
  • Psychosis Status (with hallucination details if present)

Submarine Status Information
  • Hull Breach Locations (if visible or detected)
  • Flooded Areas (percentage or list of rooms)
  • Active Fires (count or locations)
  • Damaged Electrical Devices (with names and counts, if known)
  • Damaged Mechanical Devices (with names and counts, if known)

Source Information
  • Name, Role, and Gender of the Person Speaking to the NPC
  • Personality Type and Visual Description
  • Clothing and Items Worn or Carried
  • Relationship to NPC (Crewmate, Stranger, Enemy)

Conversation History Information
  • Recent Messages Said To and By This NPC (up to N lines)

So all of this is combined into a prompt, which can range from a few hundred characters to a couple of thousand depending on the NPC. For example, an NPC that is not part of your crew will have a much shorter prompt because it won't have orders or missions and very few tools/weapons.

Conversation history is saved into text files, by default in a ConversationHistory folder in the mod directory. There is a configuration setting for the folder name and the amount of history to use. When the prompt is being built, it goes to the NPC's file and pulls the last lines of conversation from its file and adds them to the prompt. The more lines you set in the configuration file the better the NPC's memory will be, but the more tokens you will use per prompt.

Goals
Short Term Goals
  • Setup a GitHub for the project so more people can contribute.
  • Improve the prompt in any way that I can, either by adding more information, making it more efficient, or eliminating bad responses from ChatGPT.
Future Goals
  • Support for different languages.
  • Allow NPCs to talk with each other.
  • Allow NPCs to interpret commands from the messages.
  • Give each NPC a random backstory to improve the ChatGPT responses.
  • Replace canned dialogue from the game with dialogue more fitting to the character, to make all of an NPC's chat consistent with its character.
  • Properly sync Personality traits on characters in Multiplayer, since that is currently bugged and I don't know if the developers will fix it.
Last edited by RubbingMyAxe; 5 Jul @ 10:53am
< >
Showing 1-15 of 28 comments
MSXTNA1 12 Nov, 2023 @ 6:08pm 
Is it possible to add your own pre-prompt or something to give the AI specific knowledge? I'm thinking about creating a full Neurotrauma guide (ignoring the token cost) to be able to have a medic bot that can act as a Neuro encyclopedia
RubbingMyAxe  [developer] 12 Nov, 2023 @ 6:35pm 
Originally posted by MSXTNA1:
Is it possible to add your own pre-prompt or something to give the AI specific knowledge? I'm thinking about creating a full Neurotrauma guide (ignoring the token cost) to be able to have a medic bot that can act as a Neuro encyclopedia
It would be possible to add that. Right now the closest thing I have, which you could probably repurpose, are the Backstories which are associated with a bot's name and saved to a file. You could put the Neurotrauma stuff in there and it would probably work, but only the bot with that name would have that information.

Give it a try after the next update. I'll try to think of a different way to add information to the bots.
RubbingMyAxe  [developer] 16 Nov, 2023 @ 11:21am 
Received confirmation that the devs have fixed the issue with personality trait syncing in multiplayer, so once that hits the unstable branch and I can test with it I will be enabling the traits and backstories code for multiplayer.
The ability to talk to NPCs without the prefix “!” and the possibility of talking to NPCs on the topic of the game barotrauma, ie - “Hey Mark hi, what are you doing here at the outpost?” the answer - “Yes so peredichiski receiving new visitors, selling goods, etc., in short, nothing new” - This will specifically apply to DynamicEuropa, namely from the type of outpost.
Well, and so that NPCs do not ask strange questions like: I - “Hi Denis, to you today came new submarines?”. NPC response - “What submarines, what are you talking about?
RubbingMyAxe  [developer] 8 Nov, 2024 @ 5:59pm 
Originally posted by #FixTF2 Heavy:
Well, and so that NPCs do not ask strange questions like: I - “Hi Denis, to you today came new submarines?”. NPC response - “What submarines, what are you talking about?
That is a good one, I would have to see all of the settings to figure that one out. Maybe you were on an outpost instead of a submarine, and the free model you were using isn't trained on anything barotrauma related?
CAPTAIN COMMANDO 12 Nov, 2024 @ 10:00pm 
Originally posted by #FixTF2 Heavy:
The ability to talk to NPCs without the prefix “!” and the possibility of talking to NPCs on the topic of the game barotrauma, ie - “Hey Mark hi, what are you doing here at the outpost?” the answer - “Yes so peredichiski receiving new visitors, selling goods, etc., in short, nothing new” - This will specifically apply to DynamicEuropa, namely from the type of outpost.

I second this. If someones using a free model and doesn't care about token usage, automatically prompting the nearest bot with your chat message would feel alot more natural. Even if you still had to include a !.

Example: "#how are you doing today?" The message would then prompt the closest bot to your character.
Last edited by CAPTAIN COMMANDO; 12 Nov, 2024 @ 10:03pm
CAPTAIN COMMANDO 12 Nov, 2024 @ 10:08pm 
AI chat to in-game commands or behavior seems like a difficult task.

You would almost need a second decision-based AI just to translate their sentence into an in-game command.

For example having an AI give an angry response: "I'm going to get you for that! Your out of line!"
and then a second decision AI to decipher it to "aggressive" and then use the decision AIs response to apply it to an in-game bot behavior/command.


I know this type of decision AI to group strings into specific categories exist because I was looking at one on github a while back for possible future use.
Last edited by CAPTAIN COMMANDO; 12 Nov, 2024 @ 10:11pm
RubbingMyAxe  [developer] 12 Nov, 2024 @ 11:14pm 
Originally posted by CAPTAIN COMMANDO:
AI chat to in-game commands or behavior seems like a difficult task.

You would almost need a second decision-based AI just to translate their sentence into an in-game command.
Yeah, that's sort of how I plan on doing it. I can send the message directly to the AI and ask it to interpret if it's a command or just a regular message first. If it's a regular message, I just do what it's doing now. If it's a command though, I can provide it a list of applicable commands and have functions that assign orders for each of them.

This would double the API calls and increase the token use, but I think it will work. I am not entirely sure how accurate it will be, but maybe having the bots misunderstand their orders sometimes will be a funny quirk.
RubbingMyAxe  [developer] 12 Nov, 2024 @ 11:18pm 
Originally posted by CAPTAIN COMMANDO:
Originally posted by #FixTF2 Heavy:
The ability to talk to NPCs without the prefix “!” and the possibility of talking to NPCs on the topic of the game barotrauma, ie - “Hey Mark hi, what are you doing here at the outpost?” the answer - “Yes so peredichiski receiving new visitors, selling goods, etc., in short, nothing new” - This will specifically apply to DynamicEuropa, namely from the type of outpost.

I second this. If someones using a free model and doesn't care about token usage, automatically prompting the nearest bot with your chat message would feel alot more natural. Even if you still had to include a !.

Example: "#how are you doing today?" The message would then prompt the closest bot to your character.
I like the idea. Closest bot might not necessarily work though, what if you're in a room with another bot but there is another bot above you or behind a door that is closer? I will have to figure out which bot can hear you the best.
CAPTAIN COMMANDO 13 Nov, 2024 @ 6:59pm 
Originally posted by RubbingMyAxe:
Originally posted by CAPTAIN COMMANDO:

I second this. If someones using a free model and doesn't care about token usage, automatically prompting the nearest bot with your chat message would feel alot more natural. Even if you still had to include a !.

Example: "#how are you doing today?" The message would then prompt the closest bot to your character.
I like the idea. Closest bot might not necessarily work though, what if you're in a room with another bot but there is another bot above you or behind a door that is closer? I will have to figure out which bot can hear you the best.

If you can get the direction the player is currently facing you can use that. Naturally you would want to get the closest person your character is facing towards.
You could just include a max distance before using the closest person behind you.

Or get the players cursor position and use that instead of their character position.
Last edited by CAPTAIN COMMANDO; 13 Nov, 2024 @ 7:04pm
CAPTAIN COMMANDO 13 Nov, 2024 @ 7:09pm 
For getting the AI commands, I wonder if it would be possible to feed both the players text and the bots response into the decision AI to decide whether the bot actually followed the order or changed to a different behavior based on their response.


So players input would be: "John, get to the guns!" - Order to turret position.
Bots input: "Sorry captain but I cant do that. You'll need to get a professional." - Said no.

Result: Ignore.


Token cost isn't a concern if there are any free models that can perform categorization. But it may have to be simplified to only accounting for the players command to the bot and bot responses by themselves.
Last edited by CAPTAIN COMMANDO; 13 Nov, 2024 @ 7:13pm
CAPTAIN COMMANDO 13 Nov, 2024 @ 7:21pm 
Originally posted by CAPTAIN COMMANDO:
For getting the AI commands, I wonder if it would be possible to feed both the players text and the bots response into the decision AI to decide whether the bot actually followed the order or changed to a different behavior based on their response.


So players input would be: "John, get to the guns!" - Order to turret position.
Bots input: "Sorry captain but I cant do that. You'll need to get a professional." - Said no.

Result: Ignore.

Just tested this theory with openchat/openchat-7b:free model and it has been able to successfully categorize orders along with whether they were obeyed or not.

Here were my prompts: "I need you to categorize any responses into the following categories: order to guns obeyed, order to attack obeyed, angry and refused, ignored."

My response: ""John, get on the guns!" "No thanks captain. You'll need somebody else for that.""
Decision AI response: ""John, get on the guns!" "No thanks captain. You'll need somebody else for that." - Angry and refused"


Search the return string for "Angry and refused" and you could translate this into the bot ignoring your commands in game.
Last edited by CAPTAIN COMMANDO; 13 Nov, 2024 @ 7:24pm
RubbingMyAxe  [developer] 13 Nov, 2024 @ 7:44pm 
I might be able to check if the bot takes to the order before I get the response from the AI.

So you say "John, get on the guns!". I send that to AI to determine what type of order it is, it determines it's asking John to get on a gun, and then I assign the order to the bot.

A few moments later, I check if getting on the guns is an active order for the bot. If so, I include something in the prompt about the bot accepting the order.

If the bot rejected the order, he would no longer have that as an active order, so I could include something in the prompt about him rejecting the order.
CAPTAIN COMMANDO 13 Nov, 2024 @ 8:02pm 
Originally posted by RubbingMyAxe:
I might be able to check if the bot takes to the order before I get the response from the AI.

So you say "John, get on the guns!". I send that to AI to determine what type of order it is, it determines it's asking John to get on a gun, and then I assign the order to the bot.

A few moments later, I check if getting on the guns is an active order for the bot. If so, I include something in the prompt about the bot accepting the order.

If the bot rejected the order, he would no longer have that as an active order, so I could include something in the prompt about him rejecting the order.

It would probably be easier on tokens and the coding side if you ran both the players text to the bot and the bots response at the same time.

Example prompt to the decision AI: "Players text sent to bot" "Bots response"

And then it could decide whether to set a command for the bot or not. If the AI decided the bot ignored the order it simply never gives the command to go to the guns.
< >
Showing 1-15 of 28 comments
Per page: 1530 50