Jump to content

Where are NPC lines located (and how do I change them for a mod, without ruining the original file)


Recommended Posts

So I've been looking around the unzipped scripts folder and while I've found speech_character files, I struggle to find anything related to the NPCs.

So that's my question #1 - where are npc lines stored

Now question #2 - how do I change them?

I'd like to create a mod where pigman have different lines during, for example, winter; or maybe new, idle lines. Do I create a backup copy of the original file where npc lines are stored and then go to town on the original, or is there some sort of different method?

Thank you in advance to anyone who answers

Edited by Szczuku
Link to comment
Share on other sites

#1) Stored in strings.lua

#2) You don't need to make any changes to the strings file by replacing it. That would cause a lot of problems.

You can instead change the lines used by doing something like this in your mod. For example,

GLOBAL.STRINGS.PIG_TALK_FIGHT = {"MOOOOOOOO", "FIGHTING TIME"}

This would make it so it replaces the typical fighting talk 

{ "I KILL NOW!", "YOU GO SMASH!", "RAAAWR!" }

with the example lines I did.

 

#2.5) The category of lines to speak are chosen in brains/pigbrain.lua anywhere you see a ChattyNode, like here:
image.png.ef19d093af9befd76986f9917db6cfb7.png

 

To add new idle lines, you'd likely have to (I've never touched brains before) add a new ChattyNode with the logic for activating that node somewhere in the brain tree. 

 

  • Thanks 1
Link to comment
Share on other sites

38 minutes ago, penguin0616 said:
GLOBAL.STRINGS.PIG_TALK_FIGHT = {"MOOOOOOOO", "FIGHTING TIME"}

This would make it so it replaces the typical fighting talk 

{ "I KILL NOW!", "YOU GO SMASH!", "RAAAWR!" }

with the example lines I did.

If you want to replace them entirely do that, if you meant that you wanted to add to them, then insert into the existing table for each line:

table.insert(GLOBAL.STRINGS.PIG_TALK_FIGHT, "I am fighting you.")

 

38 minutes ago, penguin0616 said:

To add new idle lines, you'd likely have to (I've never touched brains before) add a new ChattyNode with the logic for activating that node somewhere in the brain tree. 

Thankfully, you don't need to mess with brains. The "talker" component has a resolvechatterfn() function that lets you change the line to choose before it's spoken. Merms use it to change their lines based on if the player can understand them or not. You could do something like this:

local function ResolvePigChatter(inst, strid, strtbl)
	local stringtable = GLOBAL.STRINGS[strtbl:value()]
	local winter_stringtable = GLOBAL.STRINGS[strtbl:value().."_WINTER"]
	
	-- Check if it's winter and winter lines exist for this chatter
	if GLOBAL.TheWorld.state.iswinter and winter_stringtable ~= nil and winter_stringtable[strid:value()] ~= nil then
		return winter_stringtable[strid:value()]
	-- Otherwise choose chatter as normal
	elseif stringtable ~= nil and stringtable[strid:value()] then
		return stringtable[strid:value()]
	end
end

-- Add this custom behavior to Pig Men
AddPrefabPostInit("pigman", function(inst)
	if inst.components.talker ~= nil then
		inst.components.talker.resolvechatterfn = ResolvePigChatter
	end
end)

-- Add more strings that have the same name as the chatter you want winter quotes for, with _WINTER added after it
-- Make sure the amount of lines in the table is the same as the regular chatter!
-- It won't crash if it's a different number, but if there's more, they won't be used and if there's less, the regular chatter will sometimes be chosen
GLOBAL.STRINGS.PIG_TALK_FOLLOWWILSON_WINTER = {"FRIEND I AM COLD", "I LOVE FRIEND BUT NOT SNOW", "YOU IS COLD", "I FOLLOW! BRRR..."}
GLOBAL.STRINGS.PIG_TALK_FIND_LIGHT_WINTER = {"SCARY AND COLD", "NO LIKE DARK AND SNOW", "WHERE IS WARM SUN?", "STAY NEAR WARM FIRE", "FIRE IS WARM"}
-- etc.

Of course you can change the quotes to whatever you want!

Edited by ClumsyPenny
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...