Jump to content

Recommended Posts

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 by Eremus007

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

 

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 :)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...