Dryicefox Posted June 10, 2015 Share Posted June 10, 2015 I am looking to make a character that cannot eat. They will only be able to eat one thing. How would I code this for a character? Link to comment Share on other sites More sharing options...
DarkXero Posted June 10, 2015 Share Posted June 10, 2015 (edited) -- in modmain GLOBAL.FOODTYPE.UNIQUE = "UNIQUE" -- in the only thing you can eat prefab inst.components.edible.foodtype = FOODTYPE.UNIQUE -- in your character's prefab -- (to make the character only eat UNIQUEs) inst.components.eater:SetDiet({ FOODTYPE.UNIQUE }, { FOODTYPE.UNIQUE }) -- (to make the character spit out non UNIQUEs) inst.components.eater:SetDiet({ FOODGROUP.OMNI, FOODTYPE.UNIQUE }, { FOODTYPE.UNIQUE }) Edited June 10, 2015 by DarkXero Link to comment Share on other sites More sharing options...
Dryicefox Posted June 10, 2015 Author Share Posted June 10, 2015 (edited) -- in modmainGLOBAL.FOODTYPE.UNIQUE = "UNIQUE"-- in the only thing you can eat prefabinst.components.edible.foodtype = FOODTYPE.UNIQUE-- in your character's prefab-- (to make the character only eat UNIQUEs)inst.components.eater:SetDiet({ FOODTYPE.UNIQUE }, { FOODTYPE.UNIQUE })-- (to make the character spit out non UNIQUEs)inst.components.eater:SetDiet({ FOODGROUP.OMNI, FOODTYPE.UNIQUE }, { FOODTYPE.UNIQUE })Thanks! And how would I add the foodtype to the item I want them to be able to eat? Also got foodtype not declared in modmain Edited June 10, 2015 by Dryicefox Link to comment Share on other sites More sharing options...
DarkXero Posted June 10, 2015 Share Posted June 10, 2015 @Dryicefox, it would be not declared if you put all three lines in the modmain. This goes in modmain.lua:GLOBAL.FOODTYPE.UNIQUE = "UNIQUE"This goes in whatever edible prefab files (read myprefab.lua in scripts/prefabs) you want to eat:inst.components.edible.foodtype = FOODTYPE.UNIQUEThis goes in your character's master_postinit (read inside master_postinit function of mycharacter.lua in scripts/prefabs):inst.components.eater:SetDiet({ FOODGROUP.OMNI, FOODTYPE.UNIQUE }, { FOODTYPE.UNIQUE })If you want to dump it all in modmain.lua, I suppose you can go like this:local FOODTYPE = GLOBAL.FOODTYPElocal FOODGROUP = GLOBAL.FOODGROUPFOODTYPE.UNIQUE = "UNIQUE"local uniqueedile = "log"AddPrefabPostInit(uniqueedile, function(inst) inst.components.edible.foodtype = FOODTYPE.UNIQUEend)local mycharacter = "wilson"AddPrefabPostInit(mycharacter, function(inst) inst.components.eater:SetDiet({ FOODGROUP.OMNI, FOODTYPE.UNIQUE }, { FOODTYPE.UNIQUE })end) Link to comment Share on other sites More sharing options...
Dryicefox Posted June 10, 2015 Author Share Posted June 10, 2015 @Dryicefox, it would be not declared if you put all three lines in the modmain. This goes in modmain.lua:GLOBAL.FOODTYPE.UNIQUE = "UNIQUE"This goes in whatever edible prefab files (read myprefab.lua in scripts/prefabs) you want to eat:inst.components.edible.foodtype = FOODTYPE.UNIQUEThis goes in your character's master_postinit (read inside master_postinit function of mycharacter.lua in scripts/prefabs):inst.components.eater:SetDiet({ FOODGROUP.OMNI, FOODTYPE.UNIQUE }, { FOODTYPE.UNIQUE })If you want to dump it all in modmain.lua, I suppose you can go like this:local FOODTYPE = GLOBAL.FOODTYPElocal FOODGROUP = GLOBAL.FOODGROUPFOODTYPE.UNIQUE = "UNIQUE"local uniqueedile = "log"AddPrefabPostInit(uniqueedile, function(inst) inst.components.edible.foodtype = FOODTYPE.UNIQUEend)local mycharacter = "wilson"AddPrefabPostInit(mycharacter, function(inst) inst.components.eater:SetDiet({ FOODGROUP.OMNI, FOODTYPE.UNIQUE }, { FOODTYPE.UNIQUE })end)I'm using normal DS. I am still getting the same problem FOODTYPE undeclared. I will, however be using the character in DST as well, So this is helpful Link to comment Share on other sites More sharing options...
DarkXero Posted June 10, 2015 Share Posted June 10, 2015 (edited) @Dryicefox, you should have mentioned you were using DS. In DS there is no FOODTYPE table holding all the types. You directly do, for instance:inst.components.edible.foodtype = "UNIQUE"and inside your character:inst.components.eater.foodprefs = { "UNIQUE" } Edited June 10, 2015 by DarkXero Link to comment Share on other sites More sharing options...
Dryicefox Posted June 10, 2015 Author Share Posted June 10, 2015 (edited) @Dryicefox, you should have mentioned you were using DS. In DS there is no FOODTYPE table holding all the types. You directly do, for instance:inst.components.edible.foodtype = "UNIQUE"and inside your character:inst.components.eater.foodprefs = { "UNIQUE" }How would I insert these values into currently existing data.Like I would want to make rocks edible. How would I go about it without editing the rocks prefab in my mod? I've used inst:addcomponent with no luck Edited June 10, 2015 by Dryicefox Link to comment Share on other sites More sharing options...
Renarii Posted June 10, 2015 Share Posted June 10, 2015 (edited) @Dryicefox, you would use AddPrefabPostInit as shown earlier in this thread and then add the edible component. AddPrefabPostInit("rocks1", function(inst) inst:AddComponent("edible") inst.components.edible.foodtype = FOODTYPE.UNIQUEend)This may be slightly different for DS just check butterflywings.lua or any other thing that is already edible to see how the edible component is used. Also it seems that rocks have quite a few different prefabs, you'll have to do this for each one that you want edible.If you are trying to make your character eat rocks I would recommend calling the food type rocks instead of unique however since it makes more sense. Edited June 10, 2015 by Renarii Link to comment Share on other sites More sharing options...
Dryicefox Posted June 15, 2015 Author Share Posted June 15, 2015 @Dryicefox, it would be not declared if you put all three lines in the modmain. This goes in modmain.lua:GLOBAL.FOODTYPE.UNIQUE = "UNIQUE"This goes in whatever edible prefab files (read myprefab.lua in scripts/prefabs) you want to eat:inst.components.edible.foodtype = FOODTYPE.UNIQUEThis goes in your character's master_postinit (read inside master_postinit function of mycharacter.lua in scripts/prefabs):inst.components.eater:SetDiet({ FOODGROUP.OMNI, FOODTYPE.UNIQUE }, { FOODTYPE.UNIQUE })If you want to dump it all in modmain.lua, I suppose you can go like this:local FOODTYPE = GLOBAL.FOODTYPElocal FOODGROUP = GLOBAL.FOODGROUPFOODTYPE.UNIQUE = "UNIQUE"local uniqueedile = "log"AddPrefabPostInit(uniqueedile, function(inst) inst.components.edible.foodtype = FOODTYPE.UNIQUEend)local mycharacter = "wilson"AddPrefabPostInit(mycharacter, function(inst) inst.components.eater:SetDiet({ FOODGROUP.OMNI, FOODTYPE.UNIQUE }, { FOODTYPE.UNIQUE })end)Getting an error that states that it could not index the edible variable. [00:01:23]: error calling PrefabPostInit: newfood in mod mu (Mu the Radish): [string "../mods/mu/modmain.lua"]:72: attempt to index field 'edible' (a nil value)LUA ERROR stack traceback: ../mods/mu/modmain.lua(72,1) =(tail call) ? =[C] in function 'xpcall' scripts/mods.lua(144,1) in function 'mod' scripts/mainfunctions.lua(155,1) =[C] in function 'SpawnPrefab' scripts/mainfunctions.lua(182,1) in function 'SpawnPrefab' scripts/util.lua(23,1) in function 'DebugSpawn' scripts/consolecommands.lua(84,1) in function 'c_spawn' c_spawn"newfood"(1,1) in main chunk =[C] in function 'pcall' scripts/mainfunctions.lua(1241,1) in function 'ExecuteConsoleCommand' scripts/screens/consolescreen.lua(116,1) in function 'Run' scripts/screens/consolescreen.lua(209,1) in function 'fn' scripts/scheduler.lua(187,1) in function 'OnTick' scripts/scheduler.lua(398,1) in function 'RunScheduler' scripts/update.lua(162,1) [00:01:23]: Disabling mu (Mu the Radish) because it had an error. [00:01:23]: [string "../mods/mu/modmain.lua"]:72: attempt to index field 'edible' (a nil value)LUA ERROR stack traceback: ../mods/mu/modmain.lua(72,1) =(tail call) ? =[C] in function 'xpcall' scripts/mods.lua(144,1) in function 'mod' scripts/mainfunctions.lua(155,1) =[C] in function 'SpawnPrefab' scripts/mainfunctions.lua(182,1) in function 'SpawnPrefab' scripts/util.lua(23,1) in function 'DebugSpawn' scripts/consolecommands.lua(84,1) in function 'c_spawn' c_spawn"newfood"(1,1) in main chunk =[C] in function 'pcall' scripts/mainfunctions.lua(1241,1) in function 'ExecuteConsoleCommand' scripts/screens/consolescreen.lua(116,1) in function 'Run' scripts/screens/consolescreen.lua(209,1) in function 'fn' scripts/scheduler.lua(187,1) in function 'OnTick' scripts/scheduler.lua(398,1) in function 'RunScheduler' scripts/update.lua(162,1)[00:01:23]: SCRIPT ERROR! Showing error screen [00:01:24]: QueryServerComplete no callback[00:01:24]: QueryServerComplete no callback This was done by using modmain only. Link to comment Share on other sites More sharing options...
Dryicefox Posted June 17, 2015 Author Share Posted June 17, 2015 Anyone understand why? Link to comment Share on other sites More sharing options...
DarkXero Posted June 17, 2015 Share Posted June 17, 2015 @Dryicefox, you putinst:AddComponent("edible")in your item, right? Link to comment Share on other sites More sharing options...
Dryicefox Posted June 17, 2015 Author Share Posted June 17, 2015 @Dryicefox, you putinst:AddComponent("edible")in your item, right?Oh, I'm so silly. I have lost all faith in myself at this point. I don't even know how I missed something so simple. Thanks a lot! 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