Eonnn Posted March 23, 2016 Share Posted March 23, 2016 How would I go about it, in the style of DST's Telltale Heart/Meat Effigy? I tried lifting 'Ingredient(CHARACTER_INGREDIENT.SANITY, 10)' from recipes.lua, but the game refused to start after that. (Even with Ingredient(CHARACTER_INGREDIENT.HEALTH, 40) Link to comment https://forums.kleientertainment.com/forums/topic/65688-how-do-you-make-recipes-cost-healthsanity/ Share on other sites More sharing options...
Mobbstar Posted March 23, 2016 Share Posted March 23, 2016 I don't think the code DST uses has been ported back to DS yet. You can listen for the "onbuilt" event from your prefab (e.g. Meat Effigy) and take the health there. It's not particularly nice, and does not show as ingredient, but it works. Link to comment https://forums.kleientertainment.com/forums/topic/65688-how-do-you-make-recipes-cost-healthsanity/#findComment-737601 Share on other sites More sharing options...
Eonnn Posted March 24, 2016 Author Share Posted March 24, 2016 Could you elaborate about the ListenForEvent code in greater detail? I'm still not very clear on the syntax or function of listeners. Link to comment https://forums.kleientertainment.com/forums/topic/65688-how-do-you-make-recipes-cost-healthsanity/#findComment-737970 Share on other sites More sharing options...
Mobbstar Posted March 24, 2016 Share Posted March 24, 2016 Take structures as an example, they listen for that event to play an animation. Link to comment https://forums.kleientertainment.com/forums/topic/65688-how-do-you-make-recipes-cost-healthsanity/#findComment-737983 Share on other sites More sharing options...
Eonnn Posted March 24, 2016 Author Share Posted March 24, 2016 I tried this: inst:ListenForEvent( "onbuilt", function() builder.components.sanity:DoDelta(-25) end) inside the item's prefab, but crafting it doesn't drain any sanity. What am I doing wrong here? Link to comment https://forums.kleientertainment.com/forums/topic/65688-how-do-you-make-recipes-cost-healthsanity/#findComment-737988 Share on other sites More sharing options...
Mobbstar Posted March 24, 2016 Share Posted March 24, 2016 This code should crash for the reason below. Double-check the position of the code, it should be in the same place you add components like "inspectable" and "inventoryitem". You are passing a function to the event system, but that function does not receive the "builder" variable. Add "inst" and "builder" into the parantheses "()" so it says "(inst, builder)". These are the parameter given by the event system (I think). Link to comment https://forums.kleientertainment.com/forums/topic/65688-how-do-you-make-recipes-cost-healthsanity/#findComment-738037 Share on other sites More sharing options...
Eonnn Posted March 25, 2016 Author Share Posted March 25, 2016 I have done that (and moved the code to where it should be), but nothing happens still when the item is crafted. Is there something wrong with using "builder.components.sanity:DoDelta(-25)"? Link to comment https://forums.kleientertainment.com/forums/topic/65688-how-do-you-make-recipes-cost-healthsanity/#findComment-738356 Share on other sites More sharing options...
Mobbstar Posted March 25, 2016 Share Posted March 25, 2016 3 hours ago, Eonnn said: I have done that (and moved the code to where it should be), but nothing happens still when the item is crafted. Is there something wrong with using "builder.components.sanity:DoDelta(-25)"? Paste your item code. Something about the way you set the function up must be wrong. Link to comment https://forums.kleientertainment.com/forums/topic/65688-how-do-you-make-recipes-cost-healthsanity/#findComment-738417 Share on other sites More sharing options...
Eonnn Posted March 27, 2016 Author Share Posted March 27, 2016 local assets= { Asset("ANIM", "anim/alchemytoken.zip"), Asset("ATLAS", "images/inventoryimages/alchemytoken.xml"), Asset("IMAGE", "images/inventoryimages/alchemytoken.tex"), } local prefabs = { } local function onbuilt(inst, builder) inst.builder.components.sanity:DoDelta(-25) end local function fn(colour) local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() MakeInventoryPhysics(inst) anim:SetBank("alchemytoken") anim:SetBuild("alchemytoken") anim:PlayAnimation("idle") inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst:AddComponent("stackable") inst.components.inventoryitem.imagename = "alchemytoken" inst.components.inventoryitem.atlasname = "images/inventoryimages/alchemytoken.xml" STRINGS.NAMES.ALCHEMYTOKEN = "Philosopher's Stone" STRINGS.CHARACTERS.GENERIC.DESCRIBE.ALCHEMYTOKEN = "The essence of alchemy." inst:ListenForEvent("onbuilt", function(inst,builder) inst.builder.components.sanity:DoDelta(-25) end) return inst end return Prefab("common/inventory/alchemytoken", fn, assets, prefabs) Link to comment https://forums.kleientertainment.com/forums/topic/65688-how-do-you-make-recipes-cost-healthsanity/#findComment-739646 Share on other sites More sharing options...
Mobbstar Posted March 27, 2016 Share Posted March 27, 2016 @Eonnn the following should work: Spoiler local assets= { Asset("ANIM", "anim/alchemytoken.zip"), Asset("ATLAS", "images/inventoryimages/alchemytoken.xml"), Asset("IMAGE", "images/inventoryimages/alchemytoken.tex"), } local prefabs = { } local function fn() local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() MakeInventoryPhysics(inst) anim:SetBank("alchemytoken") anim:SetBuild("alchemytoken") anim:PlayAnimation("idle") inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "alchemytoken" inst.components.inventoryitem.atlasname = "images/inventoryimages/alchemytoken.xml" inst:AddComponent("stackable") --the following adds custom code for when crafted local oldonbuilt = inst.OnBuilt inst.OnBuilt = function(inst,builder) --your code here if builder.components.sanity then builder.components.sanity:DoDelta(-25) end -- oldonbuilt(inst,builder) end return inst end STRINGS.NAMES.ALCHEMYTOKEN = "Philosopher's Stone" STRINGS.CHARACTERS.GENERIC.DESCRIBE.ALCHEMYTOKEN = "The essence of alchemy." return Prefab("common/inventory/alchemytoken", fn, assets, prefabs) Link to comment https://forums.kleientertainment.com/forums/topic/65688-how-do-you-make-recipes-cost-healthsanity/#findComment-739657 Share on other sites More sharing options...
Arkathorn Posted March 27, 2016 Share Posted March 27, 2016 @Eonnn The next update for EndoxinAPI will focus on the recipe UI, and this will be one of the features. No telling when that'll come out though. Link to comment https://forums.kleientertainment.com/forums/topic/65688-how-do-you-make-recipes-cost-healthsanity/#findComment-739664 Share on other sites More sharing options...
Eonnn Posted March 27, 2016 Author Share Posted March 27, 2016 @Mobbstar Works like a charm, thanks! Link to comment https://forums.kleientertainment.com/forums/topic/65688-how-do-you-make-recipes-cost-healthsanity/#findComment-739722 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