stasio30 Posted July 14, 2017 Share Posted July 14, 2017 Hello I need help one last time with a mod I am currently working on. I want to make a custom food item but when I try to give it health values it crashes. Also when it spawns into the game it is labelled as "MISSING INFO" local Assets = { Asset("ANIM", "anim/curry_build.zip"), Asset("ATLAS", "images/inventoryimages/curry.xml"), } local function fn(Sim) local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() MakeInventoryPhysics(inst) inst.AnimState:SetBank("curry") inst.AnimState:SetBuild("curry_build") inst.AnimState:PlayAnimation("idle", true) inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/curry.xml" inst:AddComponent("inspectable") inst:AddComponent("edible") inst.components.edible.healthvalue: default = 10 inst.components.edible.hungervalue: default = 10 inst.components.edible.sanityvalue: default = 10 inst.components.edible.foodtype: default = "GENERIC" return inst end STRINGS.NAMES.curry = "Curry" STRINGS.CHARACTERS.GENERIC.DESCRIBE.curry = "Seems spicy I guess" return Prefab( "common/inventory/curry", fn, Assets) Than you in advance Link to comment Share on other sites More sharing options...
Lumina Posted July 14, 2017 Share Posted July 14, 2017 Try something like this : inst.components.edible.healthvalue = TUNING.HEALING_MEDSMALL inst.components.edible.hungervalue = TUNING.CALORIES_TINY inst.components.edible.sanityvalue = 0 Replace the tuning.value part by the number you want. Also, try this for the strings : STRINGS.NAMES.CURRY = "Curry" STRINGS.CHARACTERS.GENERIC.DESCRIBE.CURRY = "Seems spicy I guess" Link to comment Share on other sites More sharing options...
stasio30 Posted July 14, 2017 Author Share Posted July 14, 2017 [00:00:46]: [string "scripts/mainfunctions.lua"]:119: Error loading file prefabs/curry [string "../mods/sampleprefab/scripts/prefabs/curry.lua"]:32: function arguments expected near '==' LUA ERROR stack traceback: =[C] in function 'assert' scripts/mainfunctions.lua(119,1) =(tail call) ? =[C] in function 'xpcall' scripts/mods.lua(154,1) scripts/mods.lua(593,1) in function 'RegisterPrefabs' scripts/gamelogic.lua(226,1) in function 'LoadAssets' scripts/gamelogic.lua(811,1) =[C] in function 'SetPersistentString' scripts/saveindex.lua(176,1) in function 'Save' scripts/saveindex.lua(366,1) =[C] in function 'SerializeWorldSession' scripts/networking.lua(278,1) in function 'SerializeWorldSession' scripts/saveindex.lua(369,1) in function 'OnGenerateNewWorld' scripts/gamelogic.lua(822,1) in function 'cb' scripts/screens/worldgenscreen.lua(144,1) in function 'OnUpdate' scripts/frontend.lua(594,1) in function 'Update' scripts/update.lua(92,1) I keep getting this error now :/ Link to comment Share on other sites More sharing options...
stasio30 Posted July 14, 2017 Author Share Posted July 14, 2017 Nevermind got this fixed by myself Link to comment Share on other sites More sharing options...
stasio30 Posted July 14, 2017 Author Share Posted July 14, 2017 One last question What's the code of adding something to players inventory (not as starting equipment) Link to comment Share on other sites More sharing options...
Lumina Posted July 14, 2017 Share Posted July 14, 2017 Adding something when, then ? Link to comment Share on other sites More sharing options...
stasio30 Posted July 14, 2017 Author Share Posted July 14, 2017 I got the code when to do it (while eating) but I can't find a way to add custom item to inventory Link to comment Share on other sites More sharing options...
Lumina Posted July 14, 2017 Share Posted July 14, 2017 Sorry i don't understand what you want to do. Link to comment Share on other sites More sharing options...
stasio30 Posted July 14, 2017 Author Share Posted July 14, 2017 When character eats something I want to spawn a custom prefab in hin inventory Link to comment Share on other sites More sharing options...
. . . Posted July 14, 2017 Share Posted July 14, 2017 I think this should work! Just put it in your event of eating & it should work, hopefully ! Spoiler local item = SpawnPrefab("sumthing") --replace "sumthing" with whatever the prefab is if inst.components.inventory and not inst.components.inventory:IsFull() then inst.components.inventory:GiveItem(item) elseif inst.components.container and not inst.components.container:IsFull() then inst.components.container:GiveItem(item) else inst.components.lootdropper:DropLootPrefab(item) end Link to comment Share on other sites More sharing options...
stasio30 Posted July 14, 2017 Author Share Posted July 14, 2017 1 hour ago, SuperDavid said: I think this should work! Just put it in your event of eating & it should work, hopefully ! Hide contents local item = SpawnPrefab("sumthing") --replace "sumthing" with whatever the prefab is if inst.components.inventory and not inst.components.inventory:IsFull() then inst.components.inventory:GiveItem(item) elseif inst.components.container and not inst.components.container:IsFull() then inst.components.container:GiveItem(item) else inst.components.lootdropper:DropLootPrefab(item) end Thank you very much. I will make sure to put you both in credits! One of the best game communities I've ever seen Without you I wouldn't have made this 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