FoxxyTheOut Posted April 23, 2016 Share Posted April 23, 2016 So i've still been tweaking my two characters (That alot of people and friends like) and have been wanting to ask. How do you code in like, special items they can have? Like i was going to make a hat that has certain effects when worn. Consumables and such. Also is there a code that allows me to set what certain items can be eaten and given those effects? Like if the character ate them, say, inorganic type. These are like the major things I want to add. Help? XD Link to comment Share on other sites More sharing options...
Aquaterion Posted April 23, 2016 Share Posted April 23, 2016 for allowing a character to eat certain things, currently there are specified groups which you can use: inst.components.eater:SetDiet({ FOODTYPE.MEAT }, { FOODTYPE.MEAT }) --in ur character's file if you wanna let your character eat normally, but react to certain foods you could do --in ur character.lua local function oneat(eater, food) local foodtype = food.components.edible.foodtype local fooditem = food.prefab local extrahunger = food.components.edible.hungervalue * 0.25 -- 25% of the hunger you are getting -- these are just examples, if you wanna use both fooditem and foodtype, make sure u put an if for fooditems first, then foodtypes. if fooditem == "taffy" then -- if the fooditem is taffy, gain double the extra hunger eater.components.hunger:DoDelta(extrahunger * 2) elseif foodtype == FOODTYPE.MEAT then --if the food is in the "meat" group, gain the "extrahunger" value as hunger eater.components.hunger:DoDelta(extrahunger)-- "add" 25% elseif foodtype == FOODTYPE.VEGGIE then -- if the food is in the group "veggie", does it same, except it substracts eater.components.hunger:DoDelta(-extrahunger)-- "add" -25% end eat.componnets.hunger:DoDelta(0) end -- in ur character's master_postinit function inst.components.eater:SetOnEatFn(oneat) Link to comment Share on other sites More sharing options...
FoxxyTheOut Posted April 30, 2016 Author Share Posted April 30, 2016 On 4/23/2016 at 1:20 AM, Aquaterion said: for allowing a character to eat certain things, currently there are specified groups which you can use: inst.components.eater:SetDiet({ FOODTYPE.MEAT }, { FOODTYPE.MEAT }) --in ur character's file if you wanna let your character eat normally, but react to certain foods you could do --in ur character.lua local function oneat(eater, food) local foodtype = food.components.edible.foodtype local fooditem = food.prefab local extrahunger = food.components.edible.hungervalue * 0.25 -- 25% of the hunger you are getting -- these are just examples, if you wanna use both fooditem and foodtype, make sure u put an if for fooditems first, then foodtypes. if fooditem == "taffy" then -- if the fooditem is taffy, gain double the extra hunger eater.components.hunger:DoDelta(extrahunger * 2) elseif foodtype == FOODTYPE.MEAT then --if the food is in the "meat" group, gain the "extrahunger" value as hunger eater.components.hunger:DoDelta(extrahunger)-- "add" 25% elseif foodtype == FOODTYPE.VEGGIE then -- if the food is in the group "veggie", does it same, except it substracts eater.components.hunger:DoDelta(-extrahunger)-- "add" -25% end eat.componnets.hunger:DoDelta(0) end -- in ur character's master_postinit function inst.components.eater:SetOnEatFn(oneat) Sorry for replying very late, But Im confused as to the first line which is the code below. What are the different food types? Or do i set them by adding items? And for the reaction to eating them, do I have to set custom ones as well? inst.components.eater:SetDiet({ FOODTYPE.MEAT }, { FOODTYPE.MEAT }) Link to comment Share on other sites More sharing options...
Aquaterion Posted April 30, 2016 Share Posted April 30, 2016 4 hours ago, FoxxyTheOut said: Sorry for replying very late, But Im confused as to the first line which is the code below. What are the different food types? Or do i set them by adding items? And for the reaction to eating them, do I have to set custom ones as well? inst.components.eater:SetDiet({ FOODTYPE.MEAT }, { FOODTYPE.MEAT }) foodtypes are groups that are already made, if you want your character to be able to eat only a specific food that all you gotta do is add that line. list of foodtypes: MEAT,WOOD,VEGGIE,ELEMENTAL,GEARS,HORRIBLE,INSECT,SEEDS,BERRY,RAW,BURNT,ROUGHAGE to check what foodtype a certain food is, you can go in scripts/preparedfoods.lua (for crockpot foods), veggies and meats are obviously in their respective food group. Link to comment 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