Jump to content

Recommended Posts

hello again..... my last problem is fixed the cause is...... I forgot to put "if" in function oneat (facepalm :3)

now my character can go into chraracter select scene but... when i  select my character and get to the world

it crash again

I want my character perk is  can eat nightmare fuel to level up so i try to copy prefap of WX78 like this......

 

local master_postinit = function(inst)

-- choose which sounds this character will play
inst.level = 0
inst.components.eater:SetOnEatFn(oneat)
inst.components.eater:SetCanEatNightmarefuel()
applyupgrades(inst)
inst.soundsname = "willow"
-- Stats
inst.components.health:SetMaxHealth(150)
inst.components.hunger:SetMax(150)
inst.components.sanity:SetMax(200)
end

..it doesn' work......

here log file...

log.txt

Hello !!

First you have to make the prefab "nightmarefuel" edible !
 

Copy the prefab nightmarefuel.lua in your mod and add the following :

	--------------------- Mod edition :	    inst:AddComponent("edible")    inst.components.edible.foodtype = FOODTYPE.HORRIBLE	inst.components.edible.oneaten = function(inst, eater)    if eater.prefab == "yourcharacter" then        eater.components.health:DoDelta(x)        eater.components.hunger:DoDelta(y)         eater.components.sanity:DoDelta(z)    endend		--------------------- End of mod edition

Don't forget to change "yourcharacter" with the name of your character (but keep the " " ). And x, y and z with the correct values (can be negative if you want).

 

Now you have to create a custom food type for your character, in the modmain.lua.

 

You can use the code from my mod "Hulot the Grumpy Owl" :

local require = GLOBAL.requirelocal STRINGS = GLOBAL.STRINGSlocal Eater = require "components/eater"local Text = require "widgets/text"local Image = require "widgets/image"-- Create foodtype 'Owlfood'GLOBAL.FOODTYPE.OWLFOOD = "OWLFOOD"local owl_food = {"bee", "butterfly", "fireflies", "mosquito", }local function AddOwlFood(inst)    inst:AddTag("edible_"..GLOBAL.FOODTYPE.OWLFOOD)endfor k,v in pairs(owl_food) do    AddPrefabPostInit(v, AddOwlFood)end

change owlfood with your custom foodtype's name. And the name of the prefabs with all the edibles items you want your character to eat.

 

Finally, on your character's prefab :

inst.components.eater.foodprefs = { FOODTYPE.OWLFOOD, FOODTYPE.INSECT, FOODTYPE.SEEDS, FOODTYPE.MEAT, FOODTYPE.GENERIC, }

You can add all the foodtypes your character eats. Again this is from my mod, try to adapt the name so it matches what you did in the modmain.lua.

 

It should work, now. I know there are some cleaner ways to make the food edible. But I am a beginner in lua =)
Hope it helps.
 

Pyrobolser

Edited by Pyrobolser
Copy the prefab nightmarefuel.lua in your mod and add the following
 Actually, copying the file and editing it a little is bad practice. It will make your mod incompatible with any other mod that does the same. Instead, you should modify it with a PrefabPostInit. 
 

Also, since you're making your own foodtype for it, it's better to just assign normal edible values to it instead of writing DoDeltas into the oneaten, because no other characters would have that foodtype anyway.

 

So in this case, put this in the modmain:

AddPrefabPostInit("nightmarefuel", function(inst)    inst:AddComponent("edible")    inst.components.edible.foodtype = GLOBAL.FOODTYPE.HORRIBLE    inst.components.edible.healthvalue = x    inst.components.edible.sanityvalue = y    inst.components.edible.hungervalue = zend

And a little more clarification on the above, once you make your foodtype, for example DARKFOOD, you'd replace the GLOBAL.FOODTYPE.HORRIBLE there with GLOBAL.FOODTYPE.DARKFOOD.

 

To make item edible:

1) Add "edible" component to item

2) Set food type.

3) Set food values.

4) There should be "eater" component on charater (exists by default)

5) Add this food type to foodprefs of "eater" component.

 

For example, characters can't eat "HORRIBLE" food, but pigmans are able to eat it. Robots can eat "GEARS" type of food etc. For some animals there should be "bait" component.

 

Actually 1-3 steps can be skipped and replaced by adding "edible_FOODTYPE" tag, but it's a little bit dirty hack.

Try to add a "OnSave" function that saves your current level when you save the game (or exit the game).

And a "OnLoad" function that loads your level.

I think there are similar functions with the robot character.

so i have been trying what you guys have been saying but when i run the game it will quit before the game actually starts. the only thing that i added to my character was:

 

inst.components.eater.foodprefs = {FOODTYPE.ELEMENTAL,}

 

when i remove it, its runs just fine any ideas?

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