Jump to content

How to tweak health and hunger value for stale and spoiled food


Recommended Posts

Yes, you are right. That was supposed to be modmain.lua. I changed it.

Combine that modmain.lua with the ocsayaka.lua I posted earlier, and see what happens.

If you get an error, in order to help you, I need to know what the error is. Preferably attach the whole server_log.txt. You can find it here:

<SystemDriveLetter>:\Users\<UserName>\Documents\Klei\DoNotStarveTogether\Cluster_# (# = 1-5 the placement of your server on the list of servers)
In that folder, you will find a "Master" folder and perhaps also a "Caves" folder. Both should have a server_log.txt in them. Attach those files to a post here, by dragging and dropping them onto the reply you are about to submit.

If there are no such files, it is because the game dies before it can start the server. In that case, go back to
<SystemDriveLetter>:\Users\<UserName>\Documents\Klei\DoNotStarveTogether

...where you should find the file client_log.txt. Attach that one instead.

Edited by Ultroman
Link to comment
Share on other sites

You could do that, but I'm reading for an exam right now, so I don't really have that much time.

Try debugging everything. Just put different prints everywhere, so you can see what's going on (and not going on).

print("this just happened")

Put those in, so you can see what happens when, and which things aren't getting triggered. See if all the AddPrefabPostInit's go all the way to actually setting these functions, and put a print in the if-statements in the function, so you can see whether it runs the right function for your character etc.

Link to comment
Share on other sites

Like this?

AddPrefabPostInit("monsterlasagna", function(inst)
	print("this just happened")

Also I wish you the best of luck with your exams

I think I'll send you 2 .zip(s) the original (only with changed values for cooked, dried and lasagna by me) and your version at our current stage, so you can check when you'll have some free time to kill.

Ultroman's Sayaka version.zip

Frank's Sayaka version.zip

Link to comment
Share on other sites

Well, no errors, really, except for this one

[00:00:01]: AnimationFile::LoadFile Failed to open anim/ocsayaka.zip

Might want to look into that.

It seems you don't have any crashes, then. The only thing left to do, is to put in prints all over the place, to make sure that all the stuff you want to happen actually happens. Go nuts. Then check your logs.

Link to comment
Share on other sites

Found smth interesting on another server (was playing as Wolfgang and suddenly everything stops (animations works but nothing moves ( like pigmen)) and then back to main menu

LUA ERROR stack traceback

 

server_log.txt

And what do you mean by "all over the place"? Like before and after each line?

Prints like that will do? I put them in modmain.lua to your part (after origin code)

if GLOBAL.TheNet and GLOBAL.TheNet:GetIsServer() then
print("this just happened")
	local myGetHealth = function(self, eater)
	print("this just happened")
		local multiplier = 1
		print("this just happened")
		local healthvalue = self.gethealthfn ~= nil and self.gethealthfn(self.inst, eater) or self.healthvalue
print("this just happened")
		local ignore_spoilage = not self.degrades_with_spoilage or healthvalue < 0 or (eater ~= nil and eater.components.eater ~= nil and eater.components.eater.ignoresspoilage)
		print("this just happened")

		if not ignore_spoilage and self.inst.components.perishable ~= nil then
		print("this just happened")
			if self.inst.components.perishable:IsStale() then
			print("this just happened")
				multiplier = eater ~= nil and eater.components.eater ~= nil and eater.components.eater.stale_health or self.stale_health
				print("this just happened")
				multiplier = multiplier * 0.5
				print("this just happened")
			elseif self.inst.components.perishable:IsSpoiled() then
			print("this just happened")
				multiplier = 0
				print("this just happened")
			end
		end
		return multiplier * healthvalue
		print("this just happened")
	end

	local myGetHunger = function(self, eater)
	print("this just happened")
	print("this just happened")
		local multiplier = 1
		print("this just happened")
		local ignore_spoilage = not self.degrades_with_spoilage or self.hungervalue < 0 or (eater ~= nil and eater.components.eater ~= nil and eater.components.eater.ignoresspoilage)
		print("this just happened")

		if not ignore_spoilage and self.inst.components.perishable ~= nil then
		print("this just happened")
			if self.inst.components.perishable:IsStale() then
			print("this just happened")
				multiplier = eater ~= nil and eater.components.eater ~= nil and eater.components.eater.stale_hunger or self.stale_hunger
				print("this just happened")
				multiplier = multiplier * 0.5
				print("this just happened")
			elseif self.inst.components.perishable:IsSpoiled() then
			print("this just happened")
				multiplier = eater ~= nil and eater.components.eater ~= nil and eater.components.eater.spoiled_hunger or
				self.spoiled_hunger
				print("this just happened")
				multiplier = multiplier * 0.5
				print("this just happened")
				print("this just happened")
			end
		end

		return multiplier * self.hungervalue
		print("this just happened")
	end

	AddPrefabPostInit("monstermeat", function(inst)
	print("this just happened")
		local old_gethealth = inst.components.edible.GetHealth
		print("this just happened")
		inst.components.edible.GetHealth = function(self, eater)
		print("this just happened")
			if eater:HasTag("awaken") then
			print("this just happened")
				return myGetHealth(self, eater)
				print("this just happened")
			else
				return old_gethealth(self, eater)
				print("this just happened")
			end
		end
		
		local old_gethunger = inst.components.edible.GetHunger
		print("this just happened")
		inst.components.edible.GetHunger = function(self, eater)
		print("this just happened")
			if eater:HasTag("awaken") then
			print("this just happened")
				return myGetHunger(self, eater)
				print("this just happened")
			else
				return old_gethunger(self, eater)
				print("this just happened")
			end
		end
	end)

	AddPrefabPostInit("cookedmonstermeat", function(inst)
	print("this just happened")
		local old_gethealth = inst.components.edible.GetHealth
		print("this just happened")
		inst.components.edible.GetHealth = function(self, eater)
		print("this just happened")
			if eater:HasTag("awaken") then
			print("this just happened")
				return myGetHealth(self, eater)
				print("this just happened")
			else
			print("this just happened")
				return old_gethealth(self, eater)
				print("this just happened")
			end
		end
		
		local old_gethunger = inst.components.edible.GetHunger
		print("this just happened")
		inst.components.edible.GetHunger = function(self, eater)
		print("this just happened")
			if eater:HasTag("awaken") then
			print("this just happened")
				return myGetHunger(self, eater)
				print("this just happened")
			else
			print("this just happened")
				return old_gethunger(self, eater)
				print("this just happened")
			end
		end
	end)

	AddPrefabPostInit("monstermeat_dried", function(inst)
	print("this just happened")
		local old_gethealth = inst.components.edible.GetHealth
		print("this just happened")
		inst.components.edible.GetHealth = function(self, eater)
		print("this just happened")
			if eater:HasTag("awaken") then
			print("this just happened")
				return myGetHealth(self, eater)
				print("this just happened")
			else
			print("this just happened")
				return old_gethealth(self, eater)
				print("this just happened")
			end
		end
		print("this just happened")
		local old_gethunger = inst.components.edible.GetHunger
		print("this just happened")
		inst.components.edible.GetHunger = function(self, eater)
		print("this just happened")
			if eater:HasTag("awaken") then
			print("this just happened")
				return myGetHunger(self, eater)
				print("this just happened")
			else
			print("this just happened")
				return old_gethunger(self, eater)
				print("this just happened")
			end
		end
	end)
print("this just happened")
	AddPrefabPostInit("monsterlasagna", function(inst)
	print("this just happened")
		local old_gethealth = inst.components.edible.GetHealth
		print("this just happened")
		inst.components.edible.GetHealth = function(self, eater)
		print("this just happened")
			if eater:HasTag("awaken") then
			print("this just happened")
				return myGetHealth(self, eater)
				print("this just happened")
			else
				return old_gethealth(self, eater)
				print("this just happened")
			end
		end
		
		local old_gethunger = inst.components.edible.GetHunger
		print("this just happened")
		inst.components.edible.GetHunger = function(self, eater)
		print("this just happened")
			if eater:HasTag("awaken") then
			print("this just happened")
				return myGetHunger(self, eater)
				print("this just happened")
			else
				return old_gethunger(self, eater)
				print("this just happened")
			end
		end
	end)

	AddPrefabPostInit("ocsayakasoul", function(inst)
	print("this just happened")
		local old_gethealth = inst.components.edible.GetHealth
		print("this just happened")
		inst.components.edible.GetHealth = function(self, eater)
		print("this just happened")
			if eater:HasTag("awaken") then
			print("this just happened")
				return (inst.components.edible:GetHealth(inst)+10)*-3
				print("this just happened")
			else
			print("this just happened")
				return old_gethealth(self, eater)
				print("this just happened")
			end
		end
		print("this just happened")
		local old_gethunger = inst.components.edible.GetHunger
		print("this just happened")
		inst.components.edible.GetHunger = function(self, eater)
		print("this just happened")
			if eater:HasTag("awaken") then
			print("this just happened")
				return inst.components.edible:GetHunger(inst)*-5
				print("this just happened")
			else
				return old_gethunger(self, eater)
				print("this just happened")
			end
		end
		print("this just happened")
		local old_getsanity = inst.components.edible.GetSanity
		print("this just happened")
		inst.components.edible.GetSanity = function(self, eater)
		print("this just happened")
			if eater:HasTag("awaken") then
			print("this just happened")
				return inst.components.edible:GetSanity(inst)*-0.5
				print("this just happened")
			else
			print("this just happened")
				return old_getsanity(self, eater)
				print("this just happened")
			end
		end
	end)
end

 

Edited by Frank Klinton
Link to comment
Share on other sites

I'm sorry, but if you don't know LUA and don't want to, I don't think you're going to have success with this.

Printing several times in a row, and even printing the same thing, doesn't help anything. I'm sorry, but I don't think I can help you any further, other than by coding it for you, and I don't have time for that. To mod, you need to learn LUA and study the game code to know how it works. It's not a simple task. It might seem like it, but it never is.

I have no idea how you managed to get the clock-component to give an error (the latest error).

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