Jump to content

Need help. My item is invisible when I get back in the game.


Recommended Posts

I created my item in game. But when I return my host again, the item is invisible. :wilson_confused:

 

require "prefabutil"


local assets =
{
    Asset("ANIM", "anim/pot01.zip"),
    Asset("IMAGE", "images/inventoryimages/pot01.tex"),
    Asset("ATLAS", "images/inventoryimages/pot01.xml"),
}


local function onhammered(inst, worker)
    SpawnPrefab("petals").Transform:SetPosition(inst.Transform:GetWorldPosition())
    inst.components.lootdropper:DropLoot()
    inst.SoundEmitter:PlaySound("dontstarve/common/destroy_pot")
    inst:Remove()
end

local function ontransplantfn(inst)
    inst.components.pickable:MakeEmpty()
end


local function onpickedfn(inst, picker)
    if inst.stage == "flower" then
    if picker and picker.components.sanity then
    picker.components.sanity:DoDelta(TUNING.SANITY_TINY)
    end 
end
    inst.AnimState:PlayAnimation("idle")
    inst.animname = "idle" 
    inst.stage = nil
    inst.components.pickable:SetUp(nil, nil)
    if inst:HasTag("planted") then
    inst:RemoveTag("planted")
    end
    if inst:HasTag("flower") then
    inst:RemoveTag("flower")
    end
    if inst.components.sanityaura then
    inst.components.sanityaura.aura = 0
    end
end

local function ShouldAcceptItem(inst, item)
    if item.prefab == "seeds" and not inst:HasTag("planted") then
    return true
    else
    return false
    end
end

local function OnGetItemFromPlayer(inst, giver, item)
    if item.prefab == "seeds" then
    inst.AnimState:PlayAnimation("s")
    inst:AddTag("planted")
end 
end

local function onsave(inst, data)
    if inst.components.pickable:CanBePicked() then
        data.CanBePicked = true
    end
    if inst.animname == "idle" then
        data.anim = "idle"
    end
end

local function onload(inst, data)
    if data and data.CanBePicked then
        inst.CanBePicked = true
    end
    if data and data.anim then
        inst.animname = data.anim
        inst.AnimState:PlayAnimation(inst.animname)
    end
    if inst.animname == "idle" then
        inst.AnimState:PushAnimation("idle", true)
    end
end

local function onsave(inst, data)
    if inst:HasTag("planted") then
    data.planted = true
    end
    if inst.components.pickable:CanBePicked() then
    data.CanBePicked = true
    end
    if inst.components.pickable.targettime then
    data.targettime = inst.components.pickable.targettime
    end
    data.anim = inst.animname
end

local function onload(inst, data)
    if data and data.planted then
    inst:AddTag("planted")
    end
    if data and data.CanBePicked then
    inst.CanBePicked = true
    end
    if data and data.targettime then
    inst.targettime = data.targettime
    end
    if data and data.stage then
    inst.stage = data.stage
    stage(inst)
    end
    if data and data.anim then
    inst.animname = data.anim
    inst.AnimState:PlayAnimation(inst.animname)
    end
    if inst:HasTag("planted") and not inst.components.pickable:CanBePicked() then
    inst.AnimState:PlayAnimation("s")
    end
end

local function fn()
    local inst = CreateEntity()

    local function PlayIdleAnimation(inst)
        inst.AnimState:PlayAnimation("idle", true)
    end

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddSoundEmitter()
    inst.entity:AddMiniMapEntity()
    inst.entity:AddNetwork()
    local light = inst.entity:AddLight()
    light:SetFalloff(0.5)
    light:SetIntensity(.8)
    light:SetRadius(1.5)
    light:SetColour(237/255, 237/255, 209/255)
    light:Enable(true)

    inst.entity:AddDynamicShadow()
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "pot01"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/pot01.xml"

    inst:SetPhysicsRadiusOverride(.5)
    MakeObstaclePhysics(inst, inst.physicsradiusoverride)

    inst.MiniMapEntity:SetIcon("poticon01.tex")

    inst.Light:Enable(false)
    inst.Light:SetRadius(.6)
    inst.Light:SetFalloff(1)
    inst.Light:SetIntensity(.5)
    inst.Light:SetColour(235/255,62/255,12/255)

    inst.DynamicShadow:SetSize(2, 1)

    inst:AddTag("chậu_cự_giải")  
    inst.stage = nil
    inst.CanBePicked = false
    inst.targettime = nil

    inst:AddComponent("sanityaura")

    inst:AddComponent("trader")
    inst.components.trader.onaccept = OnGetItemFromPlayer
    inst.components.trader:SetAcceptTest(ShouldAcceptItem)

    inst:AddComponent("pickable")

    inst.AnimState:SetBank("pot01")
    inst.AnimState:SetBuild("pot01")
    
    local function PlayIdleAnimation(inst)
        inst.AnimState:PushAnimation("idle", true)
    end
    
    local function OnDeploy(inst, pt, deployer)
        inst.Physics:Teleport(pt:Get())
        PlayIdleAnimation(inst)
    end
    
    inst:ListenForEvent("ondropped", PlayIdleAnimation)
    inst:ListenForEvent("deploy", OnDeploy)


    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end


    inst:AddComponent("inspectable")
    inst.components.inspectable.getstatus = function() 
    if inst:HasTag("planted") and not inst.components.pickable:CanBePicked() then
    return "SEEDS"
    elseif inst.stage == "flower" and inst.components.pickable:CanBePicked() then 
    return "FLOWER"
end 
end
    inst:AddComponent("lootdropper")
    inst:AddComponent("workable")
    inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
    inst.components.workable:SetWorkLeft(2)
    inst.components.workable:SetOnFinishCallback(onhammered)

    inst.OnSave = onsave
    inst.OnLoad = onload

    return inst
end

local function OnFailedPlacement(inst)
    inst.components.talker:Say("Chật quá!")
end

return Prefab("pot01", fn, assets),
MakePlacer("pot01_placer", "pot01", "pot01", "idle", true, false, false, 1, nil, 8, nil, nil, OnFailedPlacement)

pot01.lua (1)

Edited by Kenichikuro
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...