Jump to content

Recommended Posts

Hey, a long time ago I made a phonograph mod - stuff got outdated and everything needed a fix.
Also I'm trying to make it smoother and more "vanilla". + Updated Textures.

Anyways, I ran into a problem (I'm a coding noob, just stealing stuff from the game and adding some code using basic logic).
Now that I added the functions to burn, hammer and do all that stuff to my phonograph, it won't allow/show the "Click to play Music" anymore.
Can anyone help me with this?

Here's the (relevant?) code:

local function play(inst)
    if not inst:HasTag("burnt") then
		inst.AnimState:PlayAnimation("play_loop", true)
		inst.SoundEmitter:PlaySound(inst.LiedAbspielen, "phonograph/play")
		inst:AddComponent("sanityaura")
		inst.components.sanityaura.aura = TUNING.SANITYAURA_SMALL
	
   	inst:PushEvent("turnedon")
	end
end

local function stop(inst)
    if not inst:HasTag("burnt") then
		inst.AnimState:PlayAnimation("idle")
		inst.SoundEmitter:KillSound("phonograph/play")
		inst.SoundEmitter:PlaySound("phonograph/end")
		inst:AddComponent("sanityaura")
		inst.components.sanityaura.aura = 0

		inst:PushEvent("turnedoff")
	end
end

And even more code:

Spoiler

 

local function onhammered(inst, worker)
    if inst.components.burnable ~= nil and inst.components.burnable:IsBurning() then
        inst.components.burnable:Extinguish()
    end
    inst.components.lootdropper:DropLoot()
    local fx = SpawnPrefab("collapse_small")
    fx.Transform:SetPosition(inst.Transform:GetWorldPosition())
    fx:SetMaterial("wood")
    inst:Remove()
end


--Beim Schlag
local function onhit(inst)
    if not inst:HasTag("burnt") then
        --inst.AnimState:PlayAnimation("hit")
			inst.SoundEmitter:PlaySound("phonograph/end")
        else
            inst.AnimState:PushAnimation("idle", false)
            inst.SoundEmitter:KillSound("phonograph/play")
    end
end


-- !!! Beim Schlag ALT !!!

--local function onhit(inst, worker)
--	inst.AnimState:PlayAnimation("hit")
--	inst.AnimState:PushAnimation("idle", true)
--end

--local function onfinished(inst)
--	inst.SoundEmitter:PlaySound("dontstarve/common/destroy_wood")
--	inst:Remove()              
--end

local function onsave(inst, data)
    if inst.components.burnable ~= nil and inst.components.burnable:IsBurning() or inst:HasTag("burnt") then
        data.burnt = true
    end
end

local function onload(inst, data)
    if data ~= nil and data.burnt then
        inst.components.burnable.onburnt(inst)
    end
end

local function onbuilt(inst)
    --inst.AnimState:PlayAnimation("place")
    inst.AnimState:PushAnimation("idle", false)
    inst.SoundEmitter:PlaySound("dontstarve/common/chest_place")
end


local function fn()
		local inst = CreateEntity()
		local trans = inst.entity:AddTransform()
		local anim = inst.entity:AddAnimState()
		local sound = inst.entity:AddSoundEmitter()
		
		inst.entity:AddSoundEmitter()
		inst.entity:AddTransform()
		inst.entity:AddAnimState()

        inst:AddComponent("lootdropper")
        inst:AddComponent("workable")
        inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
        inst.components.workable:SetWorkLeft(4)
        inst.components.workable:SetOnFinishCallback(onhammered)
        inst.components.workable:SetOnWorkCallback(onhit)
		MakeSnowCovered(inst)
		
		--MakeSnowCoveredPristine(inst)
		--inst.entity:SetPristine()

		if not TheWorld.ismastersim then
			return inst
		end

		MakeSmallBurnable(inst, nil, nil, true)
		MakeSmallPropagator(inst)
		
		inst.OnSave = onsave
		inst.OnLoad = onload

		inst:AddComponent("hauntable")
		inst.components.hauntable:SetHauntValue(TUNING.HAUNT_TINY)

		inst:ListenForEvent("onbuilt", onbuilt)
	
        inst.entity:AddNetwork() 
        MakeObstaclePhysics(inst, 0.1)
        anim:SetBank("phonograph")
        anim:SetBuild("phonograph")		
        anim:PlayAnimation("idle")
		
        inst.LiedAbspielen = "phonograph/play"

        inst:AddTag("phonograph")
		inst:AddTag("structure")

        inst:AddComponent("inspectable")
        inst:AddComponent("machine")
        inst.components.machine.turnonfn = play
        inst.components.machine.turnofffn = stop
	
        inst.entity:SetCanSleep(false)

        inst:AddComponent("lootdropper")

	return inst
end

 

I hope this community is active, as this is my first post.

Many thanks in advance!

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...