Jump to content

Scripting - Extra Food


Lawrence

Recommended Posts

Hello everyone, I was wondering if it is possible to make a custom char. who can eat things like wood, grass...

I found a similar question in the forum, http://forums.kleientertainment.com/index.php?/topic/23441-help-is-it-possible-to-code-the-character-to-eat-cut-grass-or-twigs/?hl=%2Bfoodprefs#entry244257

but I didn't understand...

 

Can you help me?

Link to comment
Share on other sites

Ah, I have to write the proprieties in mod main? Am I right?

 

 

Most food values are predetermined , you can find then in the tuning files if I remember correctly. 

 

If you wanna create new foods too , you can write the proprieties in the prefab , otherwise yes , in the modmain.

Link to comment
Share on other sites

Ok I did this in tuning:

 

 

TUNING.XXX_FOODS=
{
"twigs",
"cutgrass",
"log",
}

 

[\CODE]

 

and this in prefab

 

[code]

 

local fn = function(inst)
 
table.insert(inst.components.eater.foodprefs, TUNING.XXX_FOOD)
 
end

 

[\CODE]

 

Obviously does not work... Am I doing all wrong?

Link to comment
Share on other sites

Ok I did this in tuning:

 

 TUNING.XXX_FOODS=

{

"twigs",

"cutgrass",

"log",

} [\CODE] and this in prefab [code=auto:0] local fn = function(inst)

 

table.insert(inst.components.eater.foodprefs, TUNING.XXX_FOOD)

 

end

 

[\CODE]

 

Obviously does not work... Am I doing all wrong?

 

*sigh* I can't even do a code window in the forum -_-

Link to comment
Share on other sites

Well , first off , you don't have to modify the tuning files themselves. I'll give you an example that would make WIlson eat twigs.

 

 

You first copy your "twigs.lua" to /mods/yourmod/scripts/prefabs and add the following code to twigs.lua.

 
  
  inst:AddComponent("edible")    inst.components.edible.foodtype = "TWIGS"
 

 

The foodtype can be anything you want. Doesn't matter ,just make sure it's in caps to avoid crashes.

 

Although I imagine something similar should exist due to the fact that Woody can eat such things in the beaver thing form.

 

 

Aaaanyway , now you want to give it some value.

 

    inst:AddComponent("edible")    inst.components.edible.foodtype = "TWIGS"    inst.components.edible.healthvalue = TUNING.HEALING_HUGE    inst.components.edible.hungervalue = TUNING.CALORIES_HUGE    inst.components.edible.sanityvalue = TUNING.SANITY_HUGE
 
or if you wanna give it your own values
 
  
  inst:AddComponent("edible")     inst.components.edible.foodtype = "TWIGS"     inst.components.edible.healthvalue = 100  inst.components.edible.hungervalue = 10  inst.components.edible.sanityvalue = 30
 
You can make you food add only to 1 stat , or all 3.

 

 

 

Ok , so now you got your food. Moving on to making your character actually be able to eat the food. Again , copy the character you wanna edit's lua to yoursmod/scripts/prefabs. Following my example ,that would be Wilson.lua.

 

Opening that , you need to add to the local fn function:

 

local fn = function(inst)codecodemore codeyep,you guessed it : codetable.insert(inst.components.eater.foodprefs, "TWIGS")code code blah blah

So basically the "TWIGS" written in the table.insert are the "TWIGS" foodtype you created earlier. Again , they can be named anything you want instead of TWIGS , but they have to coincide when you insert them to the table.

 

 

And..that's it. Now you just have to write your modmain and modinfo and you're good.

Link to comment
Share on other sites

Instead of duplicating and editing the prefab files, you should be able to make those changes through Prefab PostInits.

Much cleaner, and it means you won't have to do it all again if there's an update to the files.

Or that ,yes , if you know how to use those.

 

But it might be confusing trying to use them if you're new at this.

Link to comment
Share on other sites

Or that ,yes , if you know how to use those.

 

But it might be confusing trying to use them if you're new at this.

But, especially if you're new to this, not using them and seeing your mod break every update, as well as being incompatible with a bunch of other mods, can be very dissuading. Learning how to do things "the proper way" right from the start pays off.

Link to comment
Share on other sites

Uff... I still cannot understand...

 

I tried to combine what RCatta and TheDanaAddams told me to do, by writing this

---food    inst:AddComponent("edible")    inst.components.edible.foodtype = "TWIGS"        inst.components.edible.twigs.healthvalue = 100    inst.components.edible.twigs.hungervalue = 10    inst.components.edible.twigs.sanityvalue = 30

directly on prefab of my custom character... Nothing works.

I tried to look at the original files, couldn't find anything useful for what I want to do.

 

 

I can't even figure if "inst.components.edible.twigs.healthvalue" etc is an existing code, I improvised

Link to comment
Share on other sites

I can't even figure if "inst.components.edible.twigs.healthvalue" etc is an existing code, I improvised

 

Just comparing notes here, but RCatta gave you some decent code to piece this together with. You added twigs between edible and healthvalue when that was not in what he had put together for you. Try removing those and seeing what happens.

inst.components.edible.healthvalue = 100inst.components.edible.hungervalue = 10inst.components.edible.sanityvalue = 30
Link to comment
Share on other sites

Uff... I still cannot understand...

 

I tried to combine what RCatta and TheDanaAddams told me to do, by writing this

---food    inst:AddComponent("edible")    inst.components.edible.foodtype = "TWIGS"        inst.components.edible.twigs.healthvalue = 100    inst.components.edible.twigs.hungervalue = 10    inst.components.edible.twigs.sanityvalue = 30

directly on prefab of my custom character... Nothing works.

I tried to look at the original files, couldn't find anything useful for what I want to do.

 

 

I can't even figure if "inst.components.edible.twigs.healthvalue" etc is an existing code, I improvised

You didn't read my post carefully. 

 

You add that code to "twigs.lua" , not to yourcharacter.lua

Link to comment
Share on other sites

I read it, but Dana said

 

Instead of duplicating and editing the prefab files, you should be able to make those changes through Prefab PostInits.

Much cleaner, and it means you won't have to do it all again if there's an update to the files.

 

So I tried to follow both suggestions @_@

Link to comment
Share on other sites

You need to do something like this in your modmain:

 

function TwigPostInit( inst )  inst:AddComponent("edible")     inst.components.edible.foodtype = "TWIGS"     inst.components.edible.healthvalue = 100  inst.components.edible.hungervalue = 10  inst.components.edible.sanityvalue = 30end AddPrefabPostInit("twigs", TwigPostInit)

 

The only thing you add to your character's prefab file is this:

table.insert(inst.components.eater.foodprefs, "TWIGS")
Link to comment
Share on other sites

YEEHEH!!

 

I'm trying to do a thing with the function dotaskintime, but I cannot figure how it should work

 

the idea is to make an action if the char eats an amount of a certain item (in this case meat) in less than 10 seconds.

 

So I made this:

local function EatTime(inst)     	if inst.EatingStuff == true then --Activated when character eats a piece of meat		inst:DoTaskInTime(10, function()  			inst.MeatEaten = 0 --it should prevent to do the action						inst.EatingStuff = false		EatTime(inst)	end)	 end	  end

To delete the variable value if the character doesn't eat the N number of meat in less than 10 seconds.

 

Strange to say (XD) it doesn't work

 

What am I doing wrong? :/

Link to comment
Share on other sites

YEEHEH!!

 

I'm trying to do a thing with the function dotaskintime, but I cannot figure how it should work

 

the idea is to make an action if the char eats an amount of a certain item (in this case meat) in less than 10 seconds.

 

So I made this:

local function EatTime(inst)     	if inst.EatingStuff == true then --Activated when character eats a piece of meat		inst:DoTaskInTime(10, function()  			inst.MeatEaten = 0 --it should prevent to do the action						inst.EatingStuff = false		EatTime(inst)	end)	 end	  end

To delete the variable value if the character doesn't eat the N number of meat in less than 10 seconds.

 

Strange to say (XD) it doesn't work

 

What am I doing wrong? :/

 

*Facepalm* Ok it works, I just put the code in a wrong position.

 

Why I always realize after asking? XD XD

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