Jump to content

All 'ListenForEvent' Events?


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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...