Jump to content

[Please Help] Breaking my head on how to code this


Recommended Posts

Hello again,

I am still breaking my head over how I make my custom prefab inflict nightvision for a specific amount of time when eaten.

I was trying to copy the catpotion from the witcher mod, but I can't make it work.

This is what I had in mind but doesn't work:

local assets =
{
    Asset("ANIM", "anim/dwarventonic.zip"),

    Asset("ATLAS", "images/inventoryimages/dwarventonic.xml")
}

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("recycledpickaxe")
    inst.AnimState:SetBuild("dwarventonic")
    inst.AnimState:PlayAnimation("idle")
    
    inst.entity:AddNetwork()

    inst.entity:SetPristine()

    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)
    end
   if eater.components.inventory ~= nil then
    local item = SpawnPrefab("woodenmug")
    eater.components.inventory:GiveItem(item)
    inst:Remove()
   end     
 end    
    

    MakeHauntableLaunchAndIgnite(inst)

    return inst
end

return Prefab("common/inventory/dwarventonic", fn, assets)

 

Can someone please point me in the right direction?

Many thanks in advantage.

-Eremus

 

Link to comment
Share on other sites

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
 Share

×
  • Create New...