Lawrence Posted September 11, 2013 Share Posted September 11, 2013 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#entry244257but I didn't understand... Can you help me? Link to comment https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/ Share on other sites More sharing options...
Hugo M. Posted September 11, 2013 Share Posted September 11, 2013 Its easy, just add:local fn = function(inst) table.insert(inst.components.eater.foodprefs, "WOOD") end Link to comment https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-318810 Share on other sites More sharing options...
Lawrence Posted September 11, 2013 Author Share Posted September 11, 2013 Ah ok, thanks.But what about editing the "hunger" and "health" given by the food? Link to comment https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-319001 Share on other sites More sharing options...
Lawrence Posted September 12, 2013 Author Share Posted September 12, 2013 Ah ok, thanks.But what about editing the "hunger" and "health" given by the food? Ah, I have to write the proprieties in mod main? Am I right? Link to comment https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-319393 Share on other sites More sharing options...
RCatta Posted September 12, 2013 Share Posted September 12, 2013 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 https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-319430 Share on other sites More sharing options...
Lawrence Posted September 12, 2013 Author Share Posted September 12, 2013 Ok I'll take a look to the original files to try making proprieties Link to comment https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-319917 Share on other sites More sharing options...
Lawrence Posted September 13, 2013 Author Share Posted September 13, 2013 (edited) 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? Edited September 13, 2013 by Lawrence Link to comment https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-320284 Share on other sites More sharing options...
Lawrence Posted September 13, 2013 Author Share Posted September 13, 2013 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 https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-320288 Share on other sites More sharing options...
RCatta Posted September 13, 2013 Share Posted September 13, 2013 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 blahSo 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 https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-320312 Share on other sites More sharing options...
TheDanaAddams Posted September 13, 2013 Share Posted September 13, 2013 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. Link to comment https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-320339 Share on other sites More sharing options...
RCatta Posted September 13, 2013 Share Posted September 13, 2013 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 https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-320366 Share on other sites More sharing options...
simplex Posted September 13, 2013 Share Posted September 13, 2013 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 https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-320367 Share on other sites More sharing options...
Lawrence Posted September 13, 2013 Author Share Posted September 13, 2013 (edited) 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 = 30directly 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 Edited September 13, 2013 by Lawrence Link to comment https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-320413 Share on other sites More sharing options...
Armentia Posted September 13, 2013 Share Posted September 13, 2013 (edited) 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 Edited September 13, 2013 by Armentia Link to comment https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-320416 Share on other sites More sharing options...
RCatta Posted September 13, 2013 Share Posted September 13, 2013 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 = 30directly 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 improvisedYou didn't read my post carefully. You add that code to "twigs.lua" , not to yourcharacter.lua Link to comment https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-320427 Share on other sites More sharing options...
Lawrence Posted September 13, 2013 Author Share Posted September 13, 2013 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 https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-320441 Share on other sites More sharing options...
TheDanaAddams Posted September 13, 2013 Share Posted September 13, 2013 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 https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-320463 Share on other sites More sharing options...
Lawrence Posted September 14, 2013 Author Share Posted September 14, 2013 (edited) Thanks, I did not understand .. I'm really slow sometimes :S Edited September 18, 2013 by Lawrence Link to comment https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-321480 Share on other sites More sharing options...
Lawrence Posted September 14, 2013 Author Share Posted September 14, 2013 I feel so dumb -_- Link to comment https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-321502 Share on other sites More sharing options...
Lawrence Posted September 18, 2013 Author Share Posted September 18, 2013 (edited) 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 endTo 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? :/ Edited September 18, 2013 by Lawrence Link to comment https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-324799 Share on other sites More sharing options...
Lawrence Posted September 18, 2013 Author Share Posted September 18, 2013 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 endTo 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 https://forums.kleientertainment.com/forums/topic/27545-scripting-extra-food/#findComment-324852 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now