Jump to content

Swapping character speech files?


Recommended Posts

Hello, I need some help :)... So you see, my character upon going insane changes his speech file & I had a way of doing this before I realized it also changes any other player that's also playing as my character is speech file, even if they're not insane :(! So this was the old code which I don't want anymore but If nobody can help me or there's no way to fix this then I guess i'll just keep it like this :?...

local master_postinit = function(inst)
STRINGS.CHARACTERS.ADAM = require "speech_adam"

inst:ListenForEvent("goinsane", function(inst, data)
STRINGS.CHARACTERS.ADAM = require "speech_insane_adam"
end)

inst:ListenForEvent("gosane", function(inst, data)
STRINGS.CHARACTERS.ADAM = require "speech_adam"
end)

So the help I need is that if there is an way of changing his speech file without changing the other guys playing as my character who aren't insane? I really would appreciate some help on this :), also, thanks for reading :D!!!

Edited by SuperDavid
Link to comment
Share on other sites

I can't help you, but I am curious as to how you implemented the code you posted. I'm modding for singleplayer DS and want to make an existing character (STRINGS.CHARACTERS.GENERIC) have different quotes based on sanity. Thanks.

Link to comment
Share on other sites

It's really simple.

Steps:

1-Add your speech file string(s) into modmain

STRINGS.CHARACTERS.ADAM = require "speech_adam"
STRINGS.CHARACTERS.ADAM = require "speech_insane_adam"

2-Have all your speech files in your character's scripts folder

3-In your characterprefab.lua do this...

local master_postinit = function(inst)

STRINGS.CHARACTERS.ADAM = require "speech_adam"

4-then put your strings under any event that triggers the swap, if you want his speech file to change on insanity then you'd do this...

-- You're insane, speech go insane.
inst:ListenForEvent("goinsane", function(inst, data)
STRINGS.CHARACTERS.ADAM = require "speech_insane_adam"
end)

-- You're sane, speech back to normal.
inst:ListenForEvent("gosane", function(inst, data)
STRINGS.CHARACTERS.ADAM = require "speech_adam"
end)

5-now you thank me for helping you, just kidding ;)! Hope this works for you :)!

Link to comment
Share on other sites

If you want multiple speech files for different levels of sanity and not on being insane here's how you would do it (anymore then 2 I think would be overkill :shock:...)

-- Blah, blah, blah.
local function sanitydelta(inst)
if inst.components.sanity.current <= 149.99 then --whatever his crazy speech is starst
STRINGS.CHARACTERS.ADAM = require "speech_insane_adam"
elseif inst.components.sanity.current >= 150 then --whatever number it reverts
STRINGS.CHARACTERS.ADAM = require "speech_adam"
end
end
  
  --if you want more then 2 like 3 then
  
 -- Blah, blah, blah.
local function sanitydelta(inst)
if inst.components.sanity.current <= 149.99 then --whatever his crazy speech is starst
STRINGS.CHARACTERS.ADAM = require "speech_insane_adam"
elseif inst.components.sanity.current >= 150 then --whatever number it reverts
STRINGS.CHARACTERS.ADAM = require "speech_adam"
elseif inst.components.sanity.current <= 50 then --whatever number goes even wacker
STRINGS.CHARACTERS.ADAM = require "speech_super_insane_adam"
end
end

 

Edited by SuperDavid
Link to comment
Share on other sites

Thank you so much! I really wish I could help you with the problem you're having. Try researching the client-server architecture or peeking into the script files. You should eventually bump into something.

Link to comment
Share on other sites

local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS

STRINGS.CHARACTERS.ADAM = require "speech_adam"
STRINGS.CHARACTERS.ADAM_INSANE = require "speech_insane_adam"

local function SwapSpeech(inst)
	if type(inst) == "table" and inst.prefab == "adam" then
		if inst.components.sanity and not inst.components.sanity:IsSane() then
			return "adam_insane"
		end
	end
	return inst
end

local _GetString = GLOBAL.GetString
function GLOBAL.GetString(inst, stringtype, modifier)
	return _GetString(SwapSpeech(inst), stringtype, modifier)
end

local _GetDescription = GLOBAL.GetDescription
function GLOBAL.GetDescription(inst, item, modifier)
	return _GetDescription(SwapSpeech(inst), item, modifier)
end

local _GetActionFailString = GLOBAL.GetActionFailString
function GLOBAL.GetActionFailString(inst, action, reason)
	return _GetActionFailString(SwapSpeech(inst), action, reason)
end

 

Link to comment
Share on other sites

30 minutes ago, DarkXero said:

local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS

STRINGS.CHARACTERS.ADAM = require "speech_adam"
STRINGS.CHARACTERS.ADAM_INSANE = require "speech_insane_adam"

local function SwapSpeech(inst)
	if type(inst) == "table" and inst.prefab == "adam" then
		if inst.components.sanity and not inst.components.sanity:IsSane() then
			return "adam_insane"
		end
	end
	return inst
end

local _GetString = GLOBAL.GetString
function GLOBAL.GetString(inst, stringtype, modifier)
	return _GetString(SwapSpeech(inst), stringtype, modifier)
end

local _GetDescription = GLOBAL.GetDescription
function GLOBAL.GetDescription(inst, item, modifier)
	return _GetDescription(SwapSpeech(inst), item, modifier)
end

local _GetActionFailString = GLOBAL.GetActionFailString
function GLOBAL.GetActionFailString(inst, action, reason)
	return _GetActionFailString(SwapSpeech(inst), action, reason)
end

 

Is this code for me? I put it in my modmain and removed my STRINGS.CHARACTERS.ADAM = require "speech_insane/adam" from his prefab but it didn't do anything :(, thanks for replying anyways :)!

Link to comment
Share on other sites

8 minutes ago, SuperDavid said:

Is this code for me? I put it in my modmain and removed my STRINGS.CHARACTERS.ADAM = require "speech_insane/adam" from his prefab but it didn't do anything

How do you know? What did you do or inspect?

Link to comment
Share on other sites

 

5 minutes ago, DarkXero said:

How do you know? What did you do or inspect?

I went into multiplayer with 2 of my character gave 1 a purpleamulet and the one that had full sanity also had insane speech :(...

Link to comment
Share on other sites

Here's his entire modmain

PrefabFiles = {
	"adam",
	"adam_none",
	"hound",
	"spider",
	"mossling",
	"warg",
	"dirtpile",
	"goose_feather",
	--"mosslingegg",
}

Assets = {
    Asset( "IMAGE", "images/saveslot_portraits/adam.tex" ),
    Asset( "ATLAS", "images/saveslot_portraits/adam.xml" ),

    Asset( "IMAGE", "images/selectscreen_portraits/adam.tex" ),
    Asset( "ATLAS", "images/selectscreen_portraits/adam.xml" ),
	
    Asset( "IMAGE", "images/selectscreen_portraits/adam_silho.tex" ),
    Asset( "ATLAS", "images/selectscreen_portraits/adam_silho.xml" ),

    Asset( "IMAGE", "bigportraits/adam.tex" ),
    Asset( "ATLAS", "bigportraits/adam.xml" ),
	
	Asset( "IMAGE", "images/map_icons/adam.tex" ),
	Asset( "ATLAS", "images/map_icons/adam.xml" ),
	
	Asset( "IMAGE", "images/avatars/avatar_adam.tex" ),
    Asset( "ATLAS", "images/avatars/avatar_adam.xml" ),
	
	Asset( "IMAGE", "images/avatars/avatar_ghost_adam.tex" ),
    Asset( "ATLAS", "images/avatars/avatar_ghost_adam.xml" ),
	
	Asset( "IMAGE", "images/avatars/self_inspect_adam.tex" ),
    Asset( "ATLAS", "images/avatars/self_inspect_adam.xml" ),
	
	Asset( "IMAGE", "images/names_adam.tex" ),
    Asset( "ATLAS", "images/names_adam.xml" ),
	
    Asset( "IMAGE", "bigportraits/adam_none.tex" ),
    Asset( "ATLAS", "bigportraits/adam_none.xml" ),

}

local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS
STRINGS.MOSSLINGNAMES =
{
-- Thunder god names.
"Oya",
"Zeus",
"Thor",
"Adad",
"Ukko",
"Aplu",
"Tupã",
"Chaac",
"Perun",
"Indra",
"Kaha'i",
"Cocijo",
"Aktzin",
"Heyoka",
"Xolotl",
"Teshub",
"Yopaat",
"Raijin",
"Bronte",
"Tlaloc",
"Tāwhaki",
"Xevioso",
"Mulungu",
"Juracán",
"Mjölnir",
"Astrape",
"Perkele",
"Taranis",
"Perëndi",
"Guatauva",
"Whaitiri",
"Perkūnas",
"Atämshkai",
"Tharapita",
"Horagalles",
"Gebeleizis",
"Chibchacum",
"Thunderbird",
"Tāwhirimātea",
"Bùzé Leigong",
"Fúmó Leigong",
"Wǔfāng Leigong",
"Hángyǔ Leigong",
"Fēishā Leigong",
"Shísuì Leigong",
"Tūnguǐ Leigong",
"Hángyún Leigong",
"Hángxuě Leigong",
"Hángbīng Leigong",
"Shénxiāo Leigong",
"Háng fēng Leigong",
}

-- The character select screen lines
STRINGS.CHARACTER_TITLES.adam = "The Next Step"
STRINGS.CHARACTER_NAMES.adam = "Adam"
STRINGS.CHARACTER_DESCRIPTIONS.adam = "*Is really powerful.\n*Is really sensitive.\n*Is not fully human?"
STRINGS.CHARACTER_QUOTES.adam = "\"Looks like I got lost, again...\""

local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS

STRINGS.CHARACTERS.ADAM = require "speech_adam"
STRINGS.CHARACTERS.ADAM_INSANE = require "speech_insane_adam"

local function SwapSpeech(inst)
	if type(inst) == "table" and inst.prefab == "adam" then
	if inst.components.sanity and not inst.components.sanity:IsSane() then
	return "adam_insane"
	end
	end
	return inst
end

local _GetString = GLOBAL.GetString
function GLOBAL.GetString(inst, stringtype, modifier)
	return _GetString(SwapSpeech(inst), stringtype, modifier)
end

local _GetDescription = GLOBAL.GetDescription
function GLOBAL.GetDescription(inst, item, modifier)
	return _GetDescription(SwapSpeech(inst), item, modifier)
end

local _GetActionFailString = GLOBAL.GetActionFailString
function GLOBAL.GetActionFailString(inst, action, reason)
	return _GetActionFailString(SwapSpeech(inst), action, reason)
end

-- The character's name as appears in-game 
STRINGS.NAMES.ADAM = "Adam"
AddModCharacter("adam", "FEMALE")
AddMinimapAtlas("images/map_icons/adam.xml")

-- Thanks DarkXero for all the below functions!

-- Fix insane arm punch texture glitch.
local function HackState(sg, state)
	local _attack_onenter = sg.states[state]["onenter"]
	sg.states[state]["onenter"] = function(inst)
	_attack_onenter(inst)
	local needs_fix = inst.prefab == "adam" and not inst.replica.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS)
	if needs_fix then
	inst.sg.statemem.isbeaver = nil
	inst.AnimState:PlayAnimation("punch")
	inst.sg:SetTimeout(24 * GLOBAL.FRAMES)
	end
	end
end
local function HackAttack(sg)
	HackState(sg, "attack")
	HackState(sg, "dojostleaction")
end
AddStategraphPostInit("wilson", HackAttack)
AddStategraphPostInit("wilson_client", HackAttack)

-- Lose all crafting on insanity.
local UpdateTabsInsanity = function() print("lol, closures") end
local function EditTabsForInsane(self)
	UpdateTabsInsanity = function(show, player)
	if player and player == GLOBAL.ThePlayer then
	for k, v in pairs(self.tabs) do
	if show then
	v:Show()
	else
	v:Hide()
	end				
	end
	end
	end
end
AddClassPostConstruct("widgets/tabgroup", EditTabsForInsane)

local function OnInsaneTabs(inst)
	inst.triggertabupdate:set(false)
end
local function OnSaneTabs(inst)
	inst.triggertabupdate:set(true)
end
local function UpdateOnJoin(inst)
	inst.triggertabupdate:set(inst.components.sanity:IsSane())
end
local function UpdateTabsBySanity(inst)
	UpdateTabsInsanity(inst.triggertabupdate:value(), inst)
end
local function EditBuilder(inst)
	inst.triggertabupdate = GLOBAL.net_bool(inst.GUID, "special.insane", "checktabsanity")
	inst.triggertabupdate:set_local(false)
	inst:ListenForEvent("checktabsanity", UpdateTabsBySanity)
	if inst.components.builder then
	local _DoBuild = inst.components.builder.DoBuild
	inst.components.builder.DoBuild = function(self, recname, pt, rotation, skin)
	if not inst.components.sanity:IsSane() then
	return false
	end
	return _DoBuild(self, recname, pt, rotation, skin)
	end
	inst:ListenForEvent("goinsane", OnInsaneTabs)
	inst:ListenForEvent("gosane", OnSaneTabs)
	inst.components.builder.science_bonus = 3
	inst.components.builder.magic_bonus = 3
	inst.components.builder.ancient_bonus = 4
	inst.components.builder.shadow_bonus = 4
	inst:DoTaskInTime(0, UpdateOnJoin)
	end
end
AddPrefabPostInit("adam", EditBuilder)

local UpdateTabsInsanity = function() print("lol, closures") end
local function EditTabsForInsane(self)
	UpdateTabsInsanity = function(show, player)
	if player and player == GLOBAL.ThePlayer then
	for k, v in pairs(self.tabs) do
	if show then
	v:Show()
	else
	v:Hide()
	end				
	end
    end
	end
end
AddClassPostConstruct("widgets/tabgroup", EditTabsForInsane)

local function OnInsaneTabs(inst)
	inst.triggertabupdate:set(false)
end
local function OnSaneTabs(inst)
	inst.triggertabupdate:set(true)
end
local function UpdateOnJoin(inst)
	inst.triggertabupdate:set(inst.components.sanity:IsSane())
end
local function UpdateTabsBySanity(inst)
	UpdateTabsInsanity(inst.triggertabupdate:value(), inst)
end
local function EditBuilder(inst)
	inst.triggertabupdate = GLOBAL.net_bool(inst.GUID, "special.insane", "checktabsanity")
	inst.triggertabupdate:set_local(false)
	inst:ListenForEvent("checktabsanity", UpdateTabsBySanity)
	if inst.components.builder then
	local _DoBuild = inst.components.builder.DoBuild
	inst.components.builder.DoBuild = function(self, recname, pt, rotation, skin)
	if not inst.components.sanity:IsSane() then
	return false
	end
	return _DoBuild(self, recname, pt, rotation, skin)
	end
	inst:ListenForEvent("goinsane", OnInsaneTabs)
	inst:ListenForEvent("gosane", OnSaneTabs)
	inst.components.builder.science_bonus = 3
	inst.components.builder.magic_bonus = 3
	inst.components.builder.ancient_bonus = 4
	inst.components.builder.shadow_bonus = 4
	inst:DoTaskInTime(0, UpdateOnJoin)
	end
end

-- Beefalo fear.
GLOBAL.require("behaviours/runaway")
local function AddBeefaloFear(self)
	-- Beefalo entity, tag they run away from, distance they see spooker, distance to which they run away
	local fear = GLOBAL.RunAway(self.inst, "sparkspooker", 15, 30)
	fear.parent = self.bt.root
	-- Insert fear right after ChaseAndAttack
	table.insert(self.bt.root.children, 5, fear)
end
AddBrainPostInit("beefalobrain", AddBeefaloFear)
local function ApplyFearTag(inst)
	inst:AddTag("sparkspooker")
end
local function RemoveFearTag(inst)
	inst:RemoveTag("sparkspooker")
end
local function AddBeefaloFearOnInsanity(inst)
	if inst.components.sanity then
	inst:ListenForEvent("goinsane", ApplyFearTag)
	inst:ListenForEvent("gosane", RemoveFearTag)
	end
end
AddPrefabPostInit("adam", AddBeefaloFearOnInsanity)

-- Bee fear.
GLOBAL.require("behaviours/runaway")
local function AddBeeFear(self)
	-- Bee entity, tag they run away from, distance they see spooker, distance to which they run away
	local fear = GLOBAL.RunAway(self.inst, "sparkspooker", 15, 30)
	fear.parent = self.bt.root
	-- Insert fear right after ChaseAndAttack
	table.insert(self.bt.root.children, 5, fear)
end
AddBrainPostInit("beebrain", AddBeeFear)
local function ApplyFearTag(inst)
	inst:AddTag("sparkspooker")
end
local function RemoveFearTag(inst)
	inst:RemoveTag("sparkspooker")
end
local function AddBeeFearOnInsanity(inst)
	if inst.components.sanity then
	inst:ListenForEvent("goinsane", ApplyFearTag)
	inst:ListenForEvent("gosane", RemoveFearTag)
	end
end
AddPrefabPostInit("adam", AddBeeFearOnInsanity)

-- Lightning Goat fear.
GLOBAL.require("behaviours/runaway")
local function AddLightningGoatFear(self)
	-- Lightning Goat entity, tag they run away from, distance they see spooker, distance to which they run away
	local fear = GLOBAL.RunAway(self.inst, "sparkspooker", 15, 30)
	fear.parent = self.bt.root
	-- Insert fear right after ChaseAndAttack
	table.insert(self.bt.root.children, 5, fear)
end
AddBrainPostInit("lightninggoatbrain", AddLightningGoatFear)
local function ApplyFearTag(inst)
	inst:AddTag("sparkspooker")
end
local function RemoveFearTag(inst)
	inst:RemoveTag("sparkspooker")
end
local function AddLightningGoatFearOnInsanity(inst)
	if inst.components.sanity then
	inst:ListenForEvent("goinsane", ApplyFearTag)
	inst:ListenForEvent("gosane", RemoveFearTag)
	end
end
AddPrefabPostInit("adam", AddLightningGoatFearOnInsanity)

-- Penguin fear.
GLOBAL.require("behaviours/runaway")
local function AddPenguinFear(self)
	-- Penguin entity, tag they run away from, distance they see spooker, distance to which they run away
	local fear = GLOBAL.RunAway(self.inst, "sparkspooker", 15, 30)
	fear.parent = self.bt.root
	-- Insert fear right after ChaseAndAttack
	table.insert(self.bt.root.children, 5, fear)
end
AddBrainPostInit("penguinbrain", AddPenguinFear)
local function ApplyFearTag(inst)
	inst:AddTag("sparkspooker")
end
local function RemoveFearTag(inst)
	inst:RemoveTag("sparkspooker")
end
local function AddPenguinFearOnInsanity(inst)
	if inst.components.sanity then
	inst:ListenForEvent("goinsane", ApplyFearTag)
	inst:ListenForEvent("gosane", RemoveFearTag)
	end
end
AddPrefabPostInit("adam", AddPenguinFearOnInsanity)

-- Rabbit fear.
GLOBAL.require("behaviours/runaway")
local function AddRabbitFear(self)
	-- Rabbit entity, tag they run away from, distance they see spooker, distance to which they run away
	local fear = GLOBAL.RunAway(self.inst, "sparkspooker", 15, 30)
	fear.parent = self.bt.root
	-- Insert fear right after ChaseAndAttack
	table.insert(self.bt.root.children, 5, fear)
end
AddBrainPostInit("rabbitbrain", AddRabbitFear)
local function ApplyFearTag(inst)
	inst:AddTag("sparkspooker")
end
local function RemoveFearTag(inst)
	inst:RemoveTag("sparkspooker")
end
local function AddRabbitFearOnInsanity(inst)
	if inst.components.sanity then
	inst:ListenForEvent("goinsane", ApplyFearTag)
	inst:ListenForEvent("gosane", RemoveFearTag)
	end
end
AddPrefabPostInit("adam", AddRabbitFearOnInsanity)

-- Koalefant fear.
GLOBAL.require("behaviours/runaway")
local function AddKoalefantFear(self)
	-- Koalefant entity, tag they run away from, distance they see spooker, distance to which they run away
	local fear = GLOBAL.RunAway(self.inst, "sparkspooker", 15, 30)
	fear.parent = self.bt.root
	-- Insert fear right after ChaseAndAttack
	table.insert(self.bt.root.children, 5, fear)
end
AddBrainPostInit("koalefantbrain", AddKoalefantFear)
local function ApplyFearTag(inst)
	inst:AddTag("sparkspooker")
end
local function RemoveFearTag(inst)
	inst:RemoveTag("sparkspooker")
end
local function AddKoalefantFearOnInsanity(inst)
	if inst.components.sanity then
	inst:ListenForEvent("goinsane", ApplyFearTag)
	inst:ListenForEvent("gosane", RemoveFearTag)
	end
end
AddPrefabPostInit("adam", AddKoalefantFearOnInsanity)

-- Glommer fear.
GLOBAL.require("behaviours/runaway")
local function AddGlommerFear(self)
	-- Glommer entity, tag they run away from, distance they see spooker, distance to which they run away
	local fear = GLOBAL.RunAway(self.inst, "sparkspooker", 15, 30)
	fear.parent = self.bt.root
	-- Insert fear right after ChaseAndAttack
	table.insert(self.bt.root.children, 5, fear)
end
AddBrainPostInit("Glommerbrain", AddGlommerFear)
local function ApplyFearTag(inst)
	inst:AddTag("sparkspooker")
end
local function RemoveFearTag(inst)
	inst:RemoveTag("sparkspooker")
end
local function AddGlommerFearOnInsanity(inst)
	if inst.components.sanity then
	inst:ListenForEvent("goinsane", ApplyFearTag)
	inst:ListenForEvent("gosane", RemoveFearTag)
	end
end
AddPrefabPostInit("adam", AddGlommerFearOnInsanity)

-- Player fear increase speed.
if GLOBAL.TheNet:GetIsMasterSimulation() then

	local SPEED_RADIUS = 20
	local SPEED_MULTIPLIER = 1.25

	local function SpeedUp(inst, guy)
	guy.components.locomotor:SetExternalSpeedMultiplier(inst, "sparkspeed", SPEED_MULTIPLIER)
	guy.sparkspeedgiver = inst
	end

	local function SlowDown(inst, guy)
	guy.components.locomotor:RemoveExternalSpeedMultiplier(inst, "sparkspeed")
	guy.sparkspeedgiver = nil
	end

	local function UpdateSlowness(inst)
	for i, v in ipairs(GLOBAL.AllPlayers) do
	if v.sparkspeedgiver == inst then
	SlowDown(inst, v)
	end
	end
	end

	local function CheckAndSpeedUp(inst)
	for i, v in ipairs(GLOBAL.AllPlayers) do
	if v ~= inst then
	if inst:IsNear(v, SPEED_RADIUS) then
	if not v.sparkspeedgiver then
	SpeedUp(inst, v)
	end
	else
	if v.sparkspeedgiver == inst then
    SlowDown(inst, v)
	end
	end
	end
	end
	end

	local function ApplyFearSpeed(inst)
	if inst.fearspeedtask == nil then
	inst.fearspeedtask = inst:DoPeriodicTask(1, CheckAndSpeedUp)
	end
	end

	local function RemoveFearSpeed(inst)
	if inst.fearspeedtask ~= nil then
	inst.fearspeedtask:Cancel()
	inst.fearspeedtask = nil
	end
	UpdateSlowness(inst)
	end

	local function AddSpeedStimulator(inst)
	inst:ListenForEvent("goinsane", ApplyFearSpeed)
	inst:ListenForEvent("gosane", RemoveFearSpeed)
	inst:ListenForEvent("onremove", UpdateSlowness)
	end

	AddPrefabPostInit("adam", AddSpeedStimulator)

end

 

Link to comment
Share on other sites

19 minutes ago, SuperDavid said:

I went into multiplayer with 2 of my character gave 1 a purpleamulet and the one that had full sanity also had insane speech

How did you check the speech?

I used the code to make Wilson have either his or Maxwell's speech, and it worked correctly.

Link to comment
Share on other sites

11 minutes ago, DarkXero said:

But what did you do to check? Examine the Florid Postern?

I don't think there is any other way to check correct implementation of speech files than to examine something.

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...