Jump to content

Custom character perk help: Food values


Recommended Posts

Hello there! First off, thank you for taking the time to read this and or helping in advanced. This is my first time programming anything and quite frankly I have next to no idea what I'm doing.

I'm making a custom character and I'm stuck on one of the perks I've planned for her. I want her to prefer meat. So she'd get 25% more hunger and hunger restored from meat, but 25% less restored from other categories. Say berries restore 9 hunger, she'd get something along the likes of 6 or 7 hunger back. Then meat gives 25, so she'd get around 31 maybe?

I want to know if this perk is possible, like I've seen other people do things where a character eats gold. If it is, could you please tell me how and what exactly I need to do? Basically a tutorial, I guess, but any help at all is appreciate. So far all the coding I've done is from the character sample mod tutorial.

Again, thank you for taking the time to read this. Any help and advice at all is appreciated! Apologies if this is in the wrong forum too. If it is, please tell me where to move it.

Link to comment
Share on other sites

in ur character.lua add this function:

local function oneat(eater, food)
	local foodtype = food.components.edible.foodtype
	local extrahunger = food.components.edible.hungervalue * 0.25 -- 25% of the hunger you are getting
	
	if foodtype == FOODTYPE.MEAT then
		eater.components.hunger:DoDelta(extrahunger)-- "add" 25%
	elseif foodtype == FOODTYPE.VEGGIE then
		eater.components.hunger:DoDelta(-extrahunger)-- "add" -25%
	end
end

and in ur character's master_postinit function add:

inst.components.eater:SetOnEatFn(oneat)

 

The above function works but when you eat vegetables, it makes the hunger badge pulse RED instead of GREEN, if you want it to pulse green then use this function instead:

 

 

 


local function oneat(eater, food)
	local foodtype = food.components.edible.foodtype
	local extrahunger = food.components.edible.hungervalue * 0.25 -- 25% of the hunger you are getting
	
	if foodtype == FOODTYPE.MEAT then
		eater.components.hunger.current = eater.components.hunger.current + extrahunger-- + the 25%
	elseif foodtype == FOODTYPE.VEGGIE then
		eater.components.hunger.current = eater.components.hunger.current - extrahunger-- - the 25% - 1
	end
	eater.components.hunger:DoDelta(0)
end

 

 

Edited by Aquaterion
Link to comment
Share on other sites

Thank you so much for the help! But I'm afraid it doesn't make too much sense to me. I hate to ask so much XD But explain it to me like I'm 5 year old... Who programs.

I tried doing the code and I keep getting crash reports. I know it's me who's messing up, but I need to know what I need to fix? Sorry if image is too large.

NzoMzq2.png

Link to comment
Share on other sites

12 minutes ago, Twazzi said:

Thank you so much for the help! But I'm afraid it doesn't make too much sense to me. I hate to ask so much XD But explain it to me like I'm 5 year old... Who programs.

I tried doing the code and I keep getting crash reports. I know it's me who's messing up, but I need to know what I need to fix? Sorry if image is too large.

NzoMzq2.png

should probably just post bushy.lua here so I can take a look what you did wrong.

The function I gave you should be outside, like; (don't copy paste this, I'm just showing your the FORMAT of where it should be placed)

local assets = 
{
	--assets
}

local prefabs =
{
	--assets
}

local function oneat(eater, food)
	--code i gave u
end

local common_postinit(inst)
	--bla bla
end

local function master_postinit(inst)
	inst.components.eater:SetOnEatFn(oneat)
end

 

Edited by Aquaterion
Link to comment
Share on other sites

I had tried a few things (I have no idea what I'm doing so I'm certain this is absolutely wrong) but this is the last thing I had tried. I didn't know if there was a specific place you wanted me to put it, so I had just put it at the end of the file. Probably one of the things I messed up on.

 

local function oneat(eater,food)
	local foodtype = food.components.edible.foodtype.meat = eater.components.hunger:DoDelta(extrahunger)
	local foodtype = food.components.edible.foodtype.meat = eater.components.hunger:DoDelta(-extrahunger)
	end
end

 

Link to comment
Share on other sites

19 minutes ago, Twazzi said:

I had tried a few things (I have no idea what I'm doing so I'm certain this is absolutely wrong) but this is the last thing I had tried. I didn't know if there was a specific place you wanted me to put it, so I had just put it at the end of the file. Probably one of the things I messed up on.

 


local function oneat(eater,food)
	local foodtype = food.components.edible.foodtype.meat = eater.components.hunger:DoDelta(extrahunger)
	local foodtype = food.components.edible.foodtype.meat = eater.components.hunger:DoDelta(-extrahunger)
	end
end

 

you need to put it somewhere above master_postinit, and that looks nothing like what I gave you, just copy what I wrote in the first post and paste it without changing anything.

If you don't figure it out, just post you're cost and I'll do it myself

Edited by Aquaterion
Link to comment
Share on other sites

My apologies. I had tried copying and pasting the first time when I put it in the bottom and since it didn't work, I thought it might be just an example so I tried changing things.

But I got it to work! Thank you soooooooo much, I wouldn't have been able to do this without you. And again, sorry for being so stupid q.q

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