Jump to content

Recommended Posts

A couple questions regarding item usage and how to program sounds.

I want to know how to have a character announce speech when done using an item on either themselves or another player (both instances specified and not shared). I also want to know how to script a sound to play when an item is being used and/or after it's been used.

Edited by Eranthis

Just to continue with notes, I have found a series of strings that could relate to having announcements tie to actions
if owner and owner ~= nil then
owner.components.talker:Say(GetString(owner, "ANNOUNCE_INSERTNAMEHERE"))
end

Only problem is that I want the announcement to be after using a heal item and most heal items don't have strings related to actions but rather just a local function fn.

On 3/4/2018 at 5:50 PM, Eranthis said:

A couple questions regarding item usage and how to program sounds.

I want to know how to have a character announce speech when done using an item on either themselves or another player (both instances specified and not shared). I also want to know how to script a sound to play when an item is being used and/or after it's been used.

 

1 hour ago, Eranthis said:

Still need help coding in sounds. I can't find anything in the script files that showcase sound directories or events tied to sounds.

Spoiler

Once you have properly set up your sound files using fmod designer in the don't starve mod tools

You simply just need to add the assets to your applicable file


	Asset("SOUNDPACKAGE", "sound/filename.fev"),
	Asset("SOUND", "sound/filename.fsb"),

then call them


inst.SoundEmitter:PlaySound("project/group/sound")
--works similar to folder structures

In your case you'll probably want to add the sound package to modmain and change the soundemitter to owner.SoundEmitter instead adding it to the ComponentPostInit below before the return.

 

24 minutes ago, Eranthis said:

Just to continue with notes, I have found a series of strings that could relate to having announcements tie to actions
if owner and owner ~= nil then
owner.components.talker:Say(GetString(owner, "ANNOUNCE_INSERTNAMEHERE"))
end

Only problem is that I want the announcement to be after using a heal item and most heal items don't have strings related to actions but rather just a local function fn.

Spoiler

To fix this issue you just need to inject your code into the healer.heal function


local STRINGS = GLOBAL.STRINGS
local GetString = GLOBAL.GetString --These lines are randomized by default, it'll pick a random string from the list.
STRINGS.CHARACTERS.GENERIC.HEALSELF = {--GENERIC is default for wilson, and any character
	"Hang on I am healing", -- simply copy and paste and make as much as you want.
}
STRINGS.CHARACTERS.GENERIC.HEALOTHER = {
	"Hang on I am healing you",
}
STRINGS.CHARACTERS.COACH.HEALSELF = {-- you can also copy this and make them for any character you want
	"Hold on, y'all, I gotta heal.", -- simply copy and paste and make as much as you want.
}
STRINGS.CHARACTERS.COACH.HEALOTHER = {
	"Stop squirmin', I'm gonna heal ya.",
}
AddComponentPostInit("healer", function(self)
	local oldHeal = self.Heal
	self.Heal = function(self, target)
		local owner = self.inst.components.inventoryitem.owner
		if target and owner ~= nil and owner.components.talker then -- if you only want this to be useable by coach or w.e. just add a owner.prefab == "coach" or w.e. his prefab name is.
			if target == owner then
				--self.inst.components.inventoryitem.owner.components.talker:Say("heal self")
				owner.components.talker:Say(GetString(owner, "HEALSELF"))
			else
				--self.inst.components.inventoryitem.owner.components.talker:Say("heal other")
				owner.components.talker:Say(GetString(owner, "HEALOTHER"))
			end
		end
		return oldHeal(self, target)
	end
end)

Cheers,

Iron_Hunter

1 hour ago, IronHunter said:

 

  Hide contents

Once you have properly set up your sound files using fmod designer in the don't starve mod tools

You simply just need to add the assets to your applicable file



	Asset("SOUNDPACKAGE", "sound/filename.fev"),
	Asset("SOUND", "sound/filename.fsb"),

then call them



inst.SoundEmitter:PlaySound("project/group/sound")
--works similar to folder structures

In your case you'll probably want to add the sound package to modmain and change the soundemitter to owner.SoundEmitter instead adding it to the ComponentPostInit below before the return.

 

  Hide contents

To fix this issue you just need to inject your code into the healer.heal function



local STRINGS = GLOBAL.STRINGS
local GetString = GLOBAL.GetString --These lines are randomized by default, it'll pick a random string from the list.
STRINGS.CHARACTERS.GENERIC.HEALSELF = {--GENERIC is default for wilson, and any character
	"Hang on I am healing", -- simply copy and paste and make as much as you want.
}
STRINGS.CHARACTERS.GENERIC.HEALOTHER = {
	"Hang on I am healing you",
}
STRINGS.CHARACTERS.COACH.HEALSELF = {-- you can also copy this and make them for any character you want
	"Hold on, y'all, I gotta heal.", -- simply copy and paste and make as much as you want.
}
STRINGS.CHARACTERS.COACH.HEALOTHER = {
	"Stop squirmin', I'm gonna heal ya.",
}
AddComponentPostInit("healer", function(self)
	local oldHeal = self.Heal
	self.Heal = function(self, target)
		local owner = self.inst.components.inventoryitem.owner
		if target and owner ~= nil and owner.components.talker then -- if you only want this to be useable by coach or w.e. just add a owner.prefab == "coach" or w.e. his prefab name is.
			if target == owner then
				--self.inst.components.inventoryitem.owner.components.talker:Say("heal self")
				owner.components.talker:Say(GetString(owner, "HEALSELF"))
			else
				--self.inst.components.inventoryitem.owner.components.talker:Say("heal other")
				owner.components.talker:Say(GetString(owner, "HEALOTHER"))
			end
		end
		return oldHeal(self, target)
	end
end)

Cheers,

Iron_Hunter

Nice usage of Coach quotes there.

Anyways the announce lines work but what I'm looking for is tying them to specific items. Using the strings you've provided seems to be global when I'm looking to have the dialogue be related to mod base item usage.

Also I'm not entirely following on the application of sounds. I already have an item sound I want to use which I have added into the modmain script (RemapSoundEvent( "dontstarve/characters/coach/use_healthkit", "coach/coach/use_healthkit" )) and I want it to play after healing using the mod-specified item. How would it be applied?

ALSO
Wanted to mention that the announcements come after the healing process so having the healother option doesn't seem relevant unless it was somehow announced once the healing started.

Edited by Eranthis
30 minutes ago, Eranthis said:

Nice usage of Coach quotes there.

Anyways the announce lines work but what I'm looking for is tying them to specific items. Using the strings you've provided seems to be global when I'm looking to have the dialogue be related to mod base item usage.

Also I'm not entirely following on the application of sounds. I already have an item sound I want to use which I have added into the modmain script (RemapSoundEvent( "dontstarve/characters/coach/use_healthkit", "coach/coach/use_healthkit" )) and I want it to play after healing using the mod-specified item. How would it be applied?

ALSO
Wanted to mention that the announcements come after the healing process so having the healother option doesn't seem relevant unless it was somehow announced once the healing started.

Just add another requirement to the if statements, checking if self.inst.prefab is your specific item.

rather than remapping the sound which is only played when the sound of the same name is called which is unlikely as I don't think there is a coach use_healtkit sound in vanilla don't starve together.

just use a soundemitter right after the announcment strings.

owner.SoundEmitter:PlaySound("coach/coach/use_healthkit")

The heal other and heal self is so coach can say he is healing your but or his own but, like from the game. That way you can call the right lines. If the healthkit sound is generic then something like:

AddComponentPostInit("healer", function(self)
	local oldHeal = self.Heal
	self.Heal = function(self, target)
		local owner = self.inst.components.inventoryitem.owner
		if target and owner ~= nil and owner.components.talker and owner.prefab == "coach" then -- if you only want this to be useable by coach or w.e. just add a owner.prefab == "coach" or w.e. his prefab name is.
			if target == owner then
				owner.components.talker:Say(GetString(owner, "HEALSELF"))
			else
				owner.components.talker:Say(GetString(owner, "HEALOTHER"))
			end
			owner.SoundEmitter:PlaySound("coach/coach/use_healthkit")
		end
		return oldHeal(self, target)
	end
end)

Cheers,

Iron_Hunter

10 minutes ago, IronHunter said:

Just add another requirement to the if statements, checking if self.inst.prefab is your specific item.

rather than remapping the sound which is only played when the sound of the same name is called which is unlikely as I don't think there is a coach use_healtkit sound in vanilla don't starve together.

just use a soundemitter right after the announcment strings.


owner.SoundEmitter:PlaySound("coach/coach/use_healthkit")

The heal other and heal self is so coach can say he is healing your but or his own but, like from the game. That way you can call the right lines. If the healthkit sound is generic then something like:


AddComponentPostInit("healer", function(self)
	local oldHeal = self.Heal
	self.Heal = function(self, target)
		local owner = self.inst.components.inventoryitem.owner
		if target and owner ~= nil and owner.components.talker and owner.prefab == "coach" then -- if you only want this to be useable by coach or w.e. just add a owner.prefab == "coach" or w.e. his prefab name is.
			if target == owner then
				owner.components.talker:Say(GetString(owner, "HEALSELF"))
			else
				owner.components.talker:Say(GetString(owner, "HEALOTHER"))
			end
			owner.SoundEmitter:PlaySound("coach/coach/use_healthkit")
		end
		return oldHeal(self, target)
	end
end)

Cheers,

Iron_Hunter

The sound works perfectly so thanks for that but my other concerns are still unanswered.

First, I asked for the announcements to be applied only to mod specific items. Your script is still applying to things like healing salve and honey poultice when I want them to only be used for the health kit.

Second, the dialogue you're thinking of is more suitable for when the character is performing an action rather after the action. Saying "I'm healing you" after said character has already healed you doesn't quite fit. On top of that though, I'm not even certain you can heal other players (at least based on a test I did in game). I noticed you can heal mobs but not people so I don't even know if the healother script should even be included anymore.

Just now, Eranthis said:

The sound works perfectly so thanks for that but my other concerns are still unanswered.

First, I asked for the announcements to be applied only to mod specific items. Your script is still applying to things like healing salve and honey poultice when I want them to only be used for the health kit.

Second, the dialogue you're thinking of is more suitable for when the character is performing an action rather after the action. Saying "I'm healing you" after said character has already healed you doesn't quite fit. On top of that though, I'm not even certain you can heal other players (at least based on a test I did in game). I noticed you can heal mobs but not people so I don't even know if the healother script should even be included anymore.

I forgot to include the self.inst.prefab == "healthkit" in the if statement with coach prefab

Its your mod so you can, decide on the announcement stuff. It probably is nice to not say I am healing myself though when healing other things.

Cheers,

Iron_Hunter

7 minutes ago, IronHunter said:

I forgot to include the self.inst.prefab == "healthkit" in the if statement with coach prefab

Its your mod so you can, decide on the announcement stuff. It probably is nice to not say I am healing myself though when healing other things.

Cheers,

Iron_Hunter

Alright that did the trick! Thanks!
I take it there's still no way to apply announcements to when a character starts performing the action?

20 minutes ago, Eranthis said:

Alright that did the trick! Thanks!
I take it there's still no way to apply announcements to when a character starts performing the action?

I would imagine it is possible, but it would require making a custom stategraph that plays the string before playing the dolongaction.

I am pretty low on time right now, take a peak at wilson's stagegraph you pretty much are going to need to make a custom actionhandler and a custom stategraph. You'll need to call the stategraph with the actionhandler

local healmod = GLOBAL.ActionHandler(GLOBAL.ACTIONS.HEAL, function(inst, action)
	  --I don't think you can run any code here but returning a specific state, look at the wilson stategraph actionhandlers for examples on how to code these properly
      return "dolongaction" ) --placeholder, instead you should call your custom stategraph or return the old one. I am out of time atm. This isn't complete code just a quick query from the files.
end)

AddStategraphActionHandler("wilson", healmod)

Cheers,

Iron_Hunter

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
×
  • Create New...