Eremus007 Posted February 1, 2016 Share Posted February 1, 2016 (edited) Hey, I am doing improvements to my custom dwarven character named Skyminer. I was trying to add three prefabs -Wooden mug [Done] (Plays role in the crafting recipe) -Dwarven tonic -Dwarven Ale I got stuck on the second one I was trying to make it so that when Skyminer ''eats'' the dwarven tonic that it will inflict him with nightvision for a specific amount of time and replaces the dwarven tonic with an empty wooden mug. That was the idea, It doesn't crash the game at the moment but I am not sure if the nightvision works but I am sure that the "Replacement" of the tonic isn't working. Here's the code: local function fn() if not TheWorld.ismastersim then return inst end inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/dwarventonic.xml" inst:AddComponent("edible") inst.components.edible.oneaten = function(inst, eater) if eater.prefab == "skyminer" then eater.components.hunger:DoDelta(3) eater.components.sanity:DoDelta(-10) inst:AddTag("nightvision") inst:AddComponent("cooldown") inst.components.cooldown.cooldown_duration = TUNING.TOTAL_NIGHT_TIME if inst.components.cooldown:IsCharged() then inst:RemoveTag("nightvision") inst:RemoveTag("cooldown") end inst.components.edible.oneatenreplacement = "woodenmug" end end Can someone tell me what I am doing wrong so I can make it work? Many thanks in advantage. Edited February 1, 2016 by Eremus007 Link to comment https://forums.kleientertainment.com/forums/topic/63639-help-i-am-trying-to-make-a-beer-tonic-prefab-for-a-dwarven-character/ Share on other sites More sharing options...
zUsername Posted February 1, 2016 Share Posted February 1, 2016 Instead of: inst.components.edible.oneatenreplacement = "woodenmug" You can try: if eater.components.inventory ~= nil then local item = SpawnPrefab("woodenmug") eater.components.inventory:GiveItem(item) inst:Remove() end Link to comment https://forums.kleientertainment.com/forums/topic/63639-help-i-am-trying-to-make-a-beer-tonic-prefab-for-a-dwarven-character/#findComment-716161 Share on other sites More sharing options...
Eremus007 Posted February 1, 2016 Author Share Posted February 1, 2016 36 minutes ago, zUsername said: Instead of: inst.components.edible.oneatenreplacement = "woodenmug" You can try: if eater.components.inventory ~= nil then local item = SpawnPrefab("woodenmug") eater.components.inventory:GiveItem(item) inst:Remove() end Thanks I will try that Link to comment https://forums.kleientertainment.com/forums/topic/63639-help-i-am-trying-to-make-a-beer-tonic-prefab-for-a-dwarven-character/#findComment-716179 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