Jump to content

Recommended Posts

7 minutes ago, FurryEskimo said:

I would, but for some reason I'm not able to do such a search on the game files, only the mod files.

You'll need to unzip them first most likely, to let Notepad++ or somethingorother do a find in files feature to scan over them.

Game stores its loose assets in zips to lower disk read times.

  • Like 1

@CarlZalph
My laptop had a near heart attack doing that search, and then the whole thing crashed.  It was searching almost 3k files, but I think I found it.

self.inst:ListenForEvent("oneat", OnEat)
inst:ListenForEvent("oneaten", OnEaten)

I'm still testing this, but I may be wrong.

Update 1:  The 'oneat' code seems to work, it activates when the player eats, but I'm having trouble getting any information about what the player ate..

local function EatTest(inst, data)
	print("Player Ate Something.")
	print("Inst: ", inst.name)
	print("Data: ", data.name)  --Reports 'nil'
	print("Food Value: ", data.components.edible:GetHunger())  --Causes an error.
end

Update 2:  I've managed to insert this code into the hound's AI, but it's the same issue as before, where I can't seem to get any information about the food being eaten.

Update 3:  Coded the dogs to gain a set amount of loyalty every time they eat food off the ground, but that's not ideal.

Edited by FurryEskimo
1 hour ago, FurryEskimo said:

@CarlZalph
My laptop had a near heart attack doing that search, and then the whole thing crashed.  It was searching almost 3k files, but I think I found it.


self.inst:ListenForEvent("oneat", OnEat)

inst:ListenForEvent("oneaten", OnEaten)

I'm still testing this, but I may be wrong.

Update 1:  The 'oneat' code seems to work, it activates when the player eats, but I'm having trouble getting any information about what the player ate..


local function EatTest(inst, data)
	print("Player Ate Something.")
	print("Inst: ", inst.name)
	print("Data: ", data.name)  --Reports 'nil'
	print("Food Value: ", data.components.edible:GetHunger())  --Causes an error.
end

Update 2:  I've managed to insert this code into the hound's AI, but it's the same issue as before, where I can't seem to get any information about the food being eaten.

Update 3:  Coded the dogs to gain a set amount of loyalty every time they eat food off the ground, but that's not ideal.

In eater component: self.inst:PushEvent("oneat", { food = food, feeder = feeder })

So listen for that on the hounds, and the event data "data.food" for the food entity, and "data.feeder" if someone fed the thing.

data.food.prefab to determine food prefab type, etc.

 

In edible component: self.inst:PushEvent("oneaten", { eater = eater })

So for this the food itself will report what ate it.

  • Like 1
  • Health 1

@CarlZalph
Wonderful, thank you.  I tried a few different methods of coding this but I got it in the end.

local HOUND_LOYALTY_PER_HUNGER = TUNING.TOTAL_DAY_TIME / 25  --A single dried meat will get you about a day of loyalty.
local HOUND_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 2.5

local function EatTestHound(inst, data)  --Test code.
	if inst.components.follower.leader ~= nil and inst.components.follower.leader:HasTag("player")then
	--	inst.SoundEmitter:PlaySound("dontstarve/common/makeFriend")
		playedfriendsfx = true
		inst.components.follower:AddLoyaltyTime(data.food.components.edible:GetHunger() * HOUND_LOYALTY_PER_HUNGER)  --Trained hounds become more loyal when stealing food off the ground.
	end
end
inst:ListenForEvent("oneat", EatTestHound)

The 'makeFriend' sound was too obnoxious though, so I turned it off.  I've tried a few other sounds but I've had no luck so far, most sounds are too loud or strange to serve as a helpful indicator.  I may simply leave it silent.

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