Jump to content

Custom character food preferations


Recommended Posts

I'm beginner in making codes so I would like to receive some help from players.

I'm making a new character to don't starve (not together). This character are going to have specific food preferations.

*He likes vegetables and fruits.

*Hates fishes.

I mean he will eat every food but he will receive more stats from eating that food what he likes and smaller stats from food what he doesn't like.

I know fishes haven't got any foodtype and they are just meat foodtype . I know vegetables are Veggie foodtype but I don't know nothing about fruits. Probably they are in veggie too.

Nevermind.Can you help me with that code,becuse when I was writting some of examples at forum that wasn't working and it was crushing a game.

 

I want to repeat that I am beginner so I will be glad if you will write that code in comments and I will just copy that and paste ,because at my lavel of creating mods I can only copying and pasting things to my lua.

Edited by Artanis_Squid
Link to comment
Share on other sites

well this will be little basic and long but you can use this code for edit every foods stats

,

local function oneat(inst, food)

	if food and food.components.edible and food.prefab == "any food you want to edit" then
		inst.components.health:DoDelta(amount of health that it gave)
		inst.components.sanity:DoDelta(amount of sanity that it gave)
		inst.components.hunger:DoDelta(amount of hunger that it gave)
 elseif food and food.components.edible and food.prefab == "any food you want to edit" then
		inst.components.health:DoDelta(amount of health that it gave)
		inst.components.sanity:DoDelta(amount of sanity that it gave)
		inst.components.hunger:DoDelta(amount of hunger that it gave)
    .
    .
    .
    
	end
end

and this in master postinit

inst.components.eater:SetOnEatFn(oneat)

 

Link to comment
Share on other sites

13 hours ago, Artanis_Squid said:

One question. Where I should put that ?

In modmain?

and this inst.components.eater....

you should put it in character.lua and in character.lua there is a part named master_postinit you should put 

inst.components.eater

there

Link to comment
Share on other sites

I hope this isn't hijacking the thread, but I have some questions about the code.

Is the value put after DoDelta the solid new value or is it the amount of change you want to do. Like if a food had a base hunger of 30 and I wanted to make it 45 would I put 45 or 15?

Also, is inst.components.health:DoDelta the only syntax for that? I've been picking through the code of a few other mods and seen some other code lines that seem to do similar things but they might be from outdated mods.

Link to comment
Share on other sites

12 hours ago, Mayli-Song said:

I hope this isn't hijacking the thread, but I have some questions about the code.

Is the value put after DoDelta the solid new value or is it the amount of change you want to do. Like if a food had a base hunger of 30 and I wanted to make it 45 would I put 45 or 15?

Also, is inst.components.health:DoDelta the only syntax for that? I've been picking through the code of a few other mods and seen some other code lines that seem to do similar things but they might be from outdated mods.

you should put 45 and im not sure im not pro :/

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