Jump to content

Custom chester problem(Newest update)


Recommended Posts

So apparently they did something new with chester and it's now conflicting with my Dogoo in my Plutia mod. I just need to figure out what this means:

[00:02:40]: [string "scripts/stategraphs/SGchester.lua"]:316: attempt to index field 'sounds' (a nil value)
LUA ERROR stack traceback:
    scripts/stategraphs/SGchester.lua:316 in (field) fn (Lua) <315-328>
    scripts/stategraph.lua:568 in (method) UpdateState (Lua) <536-580>
    scripts/stategraph.lua:607 in (method) Update (Lua) <599-627>
    scripts/stategraph.lua:125 in (method) Update (Lua) <109-148>
    scripts/update.lua:209 in () ? (Lua) <150-223>

I know its probably something missing but I'm kinda just sitting here all confused. Anything intel is appreciated!

Link to comment
Share on other sites

Here are chester related changes in v170540 (hutch not included here):

Spoiler

--- data/scripts/prefabs/chester.old.lua
+++ data/scripts/prefabs/chester.new.lua
@@ -15,6 +15,10 @@ local assets =
     Asset("ANIM", "anim/chester_snow_build.zip"),
 
     Asset("SOUND", "sound/chester.fsb"),
+
+    Asset("MINIMAP_IMAGE", "chester"),
+    Asset("MINIMAP_IMAGE", "chestershadow"),
+    Asset("MINIMAP_IMAGE", "chestersnow"),
 }
 
 local prefabs =
@@ -24,6 +28,18 @@ local prefabs =
     "chester_transform_fx",
 }
 
+local sounds =
+{
+    hurt = "dontstarve/creatures/chester/hurt",
+    pant = "dontstarve/creatures/chester/pant",
+    death = "dontstarve/creatures/chester/death",
+    open = "dontstarve/creatures/chester/open",
+    close = "dontstarve/creatures/chester/close",
+    pop = "dontstarve/creatures/chester/pop",
+    boing = "dontstarve/creatures/chester/boing",
+    lick = "dontstarve/creatures/chester/lick",
+}
+
 local function ShouldWakeUp(inst)
     return DefaultWakeTest(inst) or not inst.components.follower:IsNearLeader(WAKE_TO_FOLLOW_DISTANCE)
 end
@@ -63,10 +79,11 @@ end
 local function MorphShadowChester(inst)
     inst.AnimState:SetBuild("chester_shadow_build")
     inst:AddTag("spoiler")
+    inst.MiniMapEntity:SetIcon("chestershadow.png")
 
     inst.components.container:WidgetSetup("shadowchester")
 
-    local leader = inst.components.follower.leader    
+    local leader = inst.components.follower.leader
     if leader ~= nil then
         inst.components.follower.leader:MorphShadowEyebone()
     end
@@ -78,6 +95,7 @@ end
 local function MorphSnowChester(inst)
     inst.AnimState:SetBuild("chester_snow_build")
     inst:AddTag("fridge")
+    inst.MiniMapEntity:SetIcon("chestersnow.png")
 
     local leader = inst.components.follower.leader
     if leader ~= nil then
@@ -93,6 +111,7 @@ local function MorphNormalChester(inst)
     inst.AnimState:SetBuild("chester_build")
     inst:RemoveTag("fridge")
     inst:RemoveTag("spoiler")
+    inst.MiniMapEntity:SetIcon("chester.png")
 
     inst.components.container:WidgetSetup("chester")
 
@@ -147,7 +166,7 @@ local function DoMorph(inst, fn)
     inst.MorphChester = nil
     inst:StopWatchingWorldState("isfullmoon", CheckForMorph)
     inst:RemoveEventCallback("onclose", CheckForMorph)
-    fn(inst) 
+    fn(inst)
 end
 
 local function MorphChester(inst)
@@ -185,11 +204,19 @@ local function OnIsShadowChesterDirty(inst)
     end
 end
 
-local function create_chester()
-    --print("chester - create_chester")
+local function OnHaunt(inst)
+    if math.random() <= TUNING.HAUNT_CHANCE_ALWAYS then
+        inst.components.hauntable.panic = true
+        inst.components.hauntable.panictimer = TUNING.HAUNT_PANIC_TIME_SMALL
+        inst.components.hauntable.hauntvalue = TUNING.HAUNT_SMALL
+        return true
+    end
+    return false
+end
 
+local function create_chester()
     local inst = CreateEntity()
-    
+
     inst.entity:AddTransform()
     inst.entity:AddAnimState()
     inst.entity:AddSoundEmitter()
@@ -210,6 +237,7 @@ local function create_chester()
     inst:AddTag("scarytoprey")
     inst:AddTag("chester")
     inst:AddTag("notraptrigger")
+    inst:AddTag("noauradamage")
 
     inst.MiniMapEntity:SetIcon("chester.png")
     inst.MiniMapEntity:SetCanUseCache(false)
@@ -233,46 +261,34 @@ local function create_chester()
 
     ------------------------------------------
 
-    --print("   combat")
     inst:AddComponent("combat")
     inst.components.combat.hiteffectsymbol = "chester_body"
     inst.components.combat:SetKeepTargetFunction(ShouldKeepTarget)
-    --inst:ListenForEvent("attacked", OnAttacked)
 
-    --print("   health")
     inst:AddComponent("health")
     inst.components.health:SetMaxHealth(TUNING.CHESTER_HEALTH)
     inst.components.health:StartRegen(TUNING.CHESTER_HEALTH_REGEN_AMOUNT, TUNING.CHESTER_HEALTH_REGEN_PERIOD)
-    inst:AddTag("noauradamage")
 
-    --print("   inspectable")
     inst:AddComponent("inspectable")
     inst.components.inspectable:RecordViews()
-    --inst.components.inspectable.getstatus = GetStatus
 
-    --print("   locomotor")
     inst:AddComponent("locomotor")
     inst.components.locomotor.walkspeed = 3
     inst.components.locomotor.runspeed = 7
 
-    --print("   follower")
     inst:AddComponent("follower")
     inst:ListenForEvent("stopfollowing", OnStopFollowing)
     inst:ListenForEvent("startfollowing", OnStartFollowing)
 
-    --print("   knownlocations")
     inst:AddComponent("knownlocations")
 
-    --print("   burnable")
     MakeSmallBurnableCharacter(inst, "chester_body")
 
-    --("   container")
     inst:AddComponent("container")
     inst.components.container:WidgetSetup("chester")
     inst.components.container.onopenfn = OnOpen
     inst.components.container.onclosefn = OnClose
 
-    --print("   sleeper")
     inst:AddComponent("sleeper")
     inst.components.sleeper:SetResistance(3)
     inst.components.sleeper.testperiod = GetRandomWithVariance(6, 2)
@@ -280,21 +296,13 @@ local function create_chester()
     inst.components.sleeper:SetWakeTest(ShouldWakeUp)
 
     MakeHauntableDropFirstItem(inst)
-    AddHauntableCustomReaction(inst, function(inst, haunter)
-        if math.random() <= TUNING.HAUNT_CHANCE_ALWAYS then
-            inst.components.hauntable.panic = true
-            inst.components.hauntable.panictimer = TUNING.HAUNT_PANIC_TIME_SMALL
-            inst.components.hauntable.hauntvalue = TUNING.HAUNT_SMALL
-            return true
-        end
-        return false
-    end, false, false, true)
+    AddHauntableCustomReaction(inst, OnHaunt, false, false, true)
+
+    inst.sounds = sounds
 
-    --print("   sg")
     inst:SetStateGraph("SGchester")
     inst.sg:GoToState("idle")
 
-    --print("   brain")
     inst:SetBrain(brain)
 
     inst.ChesterState = "NORMAL"
@@ -305,7 +313,6 @@ local function create_chester()
     inst.OnSave = OnSave
     inst.OnPreLoad = OnPreLoad
 
-    --print("chester - create_chester END")
     return inst
 end
 
--- data/scripts/prefabs/chester_eyebone.old.lua
+++ data/scripts/prefabs/chester_eyebone.new.lua
@@ -4,33 +4,34 @@ local assets =
     Asset("ANIM", "anim/chester_eyebone_build.zip"),
     Asset("ANIM", "anim/chester_eyebone_snow_build.zip"),
     Asset("ANIM", "anim/chester_eyebone_shadow_build.zip"),
-	Asset("INV_IMAGE", "chester_eyebone" ),
-	Asset("INV_IMAGE", "chester_eyebone_closed" ),
-	Asset("INV_IMAGE", "chester_eyebone_closed_shadow" ),
-	Asset("INV_IMAGE", "chester_eyebone_closed_snow" ),
-	Asset("INV_IMAGE", "chester_eyebone_shadow" ),
-	Asset("INV_IMAGE", "chester_eyebone_snow" ),
-	Asset("MINIMAP_IMAGE", "treasure_chest"), --for debugging
+    Asset("INV_IMAGE", "chester_eyebone"),
+    Asset("INV_IMAGE", "chester_eyebone_closed"),
+    Asset("INV_IMAGE", "chester_eyebone_closed_shadow"),
+    Asset("INV_IMAGE", "chester_eyebone_closed_snow"),
+    Asset("INV_IMAGE", "chester_eyebone_shadow"),
+    Asset("INV_IMAGE", "chester_eyebone_snow"),
 }
 
 local SPAWN_DIST = 30
 
 local function OpenEye(inst)
-    inst.isOpenEye = true
-    inst.components.inventoryitem:ChangeImageName(inst.openEye)
+    if not inst.isOpenEye then
+        inst.isOpenEye = true
+        inst.components.inventoryitem:ChangeImageName(inst.openEye)
+        inst.AnimState:PlayAnimation("idle_loop", true)
+    end
 end
 
 local function CloseEye(inst)
-    inst.isOpenEye = nil
-    inst.components.inventoryitem:ChangeImageName(inst.closedEye)
+    if inst.isOpenEye then
+        inst.isOpenEye = nil
+        inst.components.inventoryitem:ChangeImageName(inst.closedEye)
+        inst.AnimState:PlayAnimation("dead", true)
+    end
 end
 
 local function RefreshEye(inst)
-    if inst.isOpenEye then
-        OpenEye(inst)
-    else
-        CloseEye(inst)
-    end
+    inst.components.inventoryitem:ChangeImageName(inst.isOpenEye and inst.openEye or inst.closedEye)
 end
 
 local function MorphShadowEyebone(inst)
@@ -58,7 +59,7 @@ local function MorphNormalEyebone(inst)
     inst.AnimState:SetBuild("chester_eyebone_build")
 
     inst.openEye = "chester_eyebone"
-    inst.closedEye = "chester_eyebone_closed"    
+    inst.closedEye = "chester_eyebone_closed"
     RefreshEye(inst)
 
     inst.EyeboneState = "NORMAL"
@@ -77,7 +78,7 @@ local function SpawnChester(inst)
 
     local pt = inst:GetPosition()
     --print("    near", pt)
-        
+
     local spawn_pt = GetSpawnPoint(pt)
     if spawn_pt ~= nil then
         --print("    at", spawn_pt)
@@ -98,7 +99,6 @@ end
 local StartRespawn
 
 local function StopRespawn(inst)
-    --print("chester_eyebone - StopRespawn")
     if inst.respawntask ~= nil then
         inst.respawntask:Cancel()
         inst.respawntask = nil
@@ -109,7 +109,6 @@ end
 local function RebindChester(inst, chester)
     chester = chester or TheSim:FindFirstEntityWithTag("chester")
     if chester ~= nil then
-        inst.AnimState:PlayAnimation("idle_loop", true)
         OpenEye(inst)
         inst:ListenForEvent("death", function() StartRespawn(inst, TUNING.CHESTER_RESPAWN_TIME) end, chester)
 
@@ -121,7 +120,6 @@ local function RebindChester(inst, chester)
 end
 
 local function RespawnChester(inst)
-    --print("chester_eyebone - RespawnChester")
     StopRespawn(inst)
     RebindChester(inst, TheSim:FindFirstEntityWithTag("chester") or SpawnChester(inst))
 end
@@ -132,26 +130,20 @@ StartRespawn = function(inst, time)
     time = time or 0
     inst.respawntask = inst:DoTaskInTime(time, RespawnChester)
     inst.respawntime = GetTime() + time
-    inst.AnimState:PlayAnimation("dead", true)
     CloseEye(inst)
 end
 
 local function FixChester(inst)
-	inst.fixtask = nil
-	--take an existing chester if there is one
-	if not RebindChester(inst) then
-        inst.AnimState:PlayAnimation("dead", true)
+    inst.fixtask = nil
+    --take an existing chester if there is one
+    if not RebindChester(inst) then
         CloseEye(inst)
-		
-		if inst.components.inventoryitem.owner ~= nil then
-			local time_remaining = 0
-			local time = GetTime()
-			if inst.respawntime and inst.respawntime > time then
-				time_remaining = inst.respawntime - time		
-			end
-			StartRespawn(inst, time_remaining)
-		end
-	end
+        
+        if inst.components.inventoryitem.owner ~= nil then
+            local time_remaining = inst.respawntime ~= nil and math.max(0, inst.respawntime - GetTime()) or 0
+            StartRespawn(inst, time_remaining)
+        end
+    end
 end
 
 local function OnPutInInventory(inst)
@@ -161,7 +153,6 @@ local function OnPutInInventory(inst)
 end
 
 local function OnSave(inst, data)
-    --print("chester_eyebone - OnSave")
     data.EyeboneState = inst.EyeboneState
     if inst.respawntime ~= nil then
         local time = GetTime()
@@ -184,14 +175,13 @@ local function OnLoad(inst, data)
 
     if data.respawntimeremaining ~= nil then
         inst.respawntime = data.respawntimeremaining + GetTime()
+    else
+        OpenEye(inst)
     end
 end
 
 local function GetStatus(inst)
-    --print("smallbird - GetStatus")
-    if inst.respawntask ~= nil then
-        return "WAITING"
-    end
+    return inst.respawntask ~= nil and "WAITING" or nil
 end
 
 local function fn()
@@ -201,10 +191,6 @@ local function fn()
     inst.entity:AddAnimState()
     inst.entity:AddNetwork()
 
-    --so I can find the thing while testing
-    --inst.entity:AddMiniMapEntity()
-    --inst.MiniMapEntity:SetIcon("treasure_chest.png")
-
     MakeInventoryPhysics(inst)
 
     inst:AddTag("chester_eyebone")
@@ -213,7 +199,7 @@ local function fn()
 
     inst.AnimState:SetBank("eyebone")
     inst.AnimState:SetBuild("chester_eyebone_build")
-    inst.AnimState:PlayAnimation("idle_loop", true)
+    inst.AnimState:PlayAnimation("dead", true)
 
     inst.entity:SetPristine()
 
@@ -221,15 +207,14 @@ local function fn()
         return inst
     end
 
-    inst:AddComponent("inventoryitem")
-    inst.components.inventoryitem:SetOnPutInInventoryFn(OnPutInInventory)
-
     inst.EyeboneState = "NORMAL"
     inst.openEye = "chester_eyebone"
     inst.closedEye = "chester_eyebone_closed"
-
     inst.isOpenEye = nil
-    OpenEye(inst)
+
+    inst:AddComponent("inventoryitem")
+    inst.components.inventoryitem:SetOnPutInInventoryFn(OnPutInInventory)
+    inst.components.inventoryitem:ChangeImageName(inst.closedEye)
 
     inst:AddComponent("inspectable")
     inst.components.inspectable.getstatus = GetStatus
@@ -251,4 +236,4 @@ local function fn()
     return inst
 end
 
-return Prefab("chester_eyebone", fn, assets)
\ No newline at end of file
+return Prefab("chester_eyebone", fn, assets)
--- data/scripts/stategraphs/SGchester.old.lua
+++ data/scripts/stategraphs/SGchester.new.lua
@@ -1,5 +1,31 @@
 require("stategraphs/commonstates")
 
+local NUM_FX_VARIATIONS = 7
+local MAX_RECENT_FX = 4
+local MIN_FX_SCALE = .5
+local MAX_FX_SCALE = 1.6
+
+local function SpawnMoveFx(inst, scale)
+    local fx = SpawnPrefab("hutch_move_fx")
+    if fx ~= nil then
+        if inst.sg.mem.recentfx == nil then
+            inst.sg.mem.recentfx = {}
+        end
+        local recentcount = #inst.sg.mem.recentfx
+        local rand = math.random(NUM_FX_VARIATIONS - recentcount)
+        if recentcount > 0 then
+            while table.contains(inst.sg.mem.recentfx, rand) do
+                rand = rand + 1
+            end
+            if recentcount >= MAX_RECENT_FX then
+                table.remove(inst.sg.mem.recentfx, 1)
+            end
+        end
+        table.insert(inst.sg.mem.recentfx, rand)
+        fx:SetVariation(rand, fx._min_scale + (fx._max_scale - fx._min_scale) * scale)
+        fx.Transform:SetPosition(inst.Transform:GetWorldPosition())
+    end
+end
 
 local actionhandlers = 
 {
@@ -13,10 +39,15 @@ local events=
     EventHandler("attacked", function(inst)
         if inst.components.health and not inst.components.health:IsDead() then
             inst.sg:GoToState("hit")
-            inst.SoundEmitter:PlaySound("dontstarve/creatures/chester/hurt")
+        
+            inst.SoundEmitter:PlaySound(inst.sounds.hurt)
+
         end
     end),
     EventHandler("death", function(inst) inst.sg:GoToState("death") end),
+    EventHandler("morph", function(inst, data)
+        inst.sg:GoToState("morph", data.morphfn)
+    end),
 }
 
 local states=
@@ -43,29 +74,33 @@ local states=
         {
             TimeEvent(7*FRAMES, function(inst) 
 				inst.sg.mem.pant_ducking = inst.sg.mem.pant_ducking or 1
-				inst.SoundEmitter:PlaySound("dontstarve/creatures/chester/pant", nil, inst.sg.mem.pant_ducking) 
+
+				inst.SoundEmitter:PlaySound(inst.sounds.pant, nil, inst.sg.mem.pant_ducking) 
 				if inst.sg.mem.pant_ducking and inst.sg.mem.pant_ducking > .35 then
 					inst.sg.mem.pant_ducking = inst.sg.mem.pant_ducking - .05
 				end
 			end),
-        },        
+        },
    },
-    
-   
+
+
     State{
         name = "death",
         tags = {"busy"},
-        
+
         onenter = function(inst)
             inst.components.container:Close()
             inst.components.container:DropEverything()
-            inst.SoundEmitter:PlaySound("dontstarve/creatures/chester/death")
+            inst.components.container.canbeopened = false
+
+            inst.SoundEmitter:PlaySound(inst.sounds.death)
+
             inst.AnimState:PlayAnimation("death")
             inst.Physics:Stop()
-            RemovePhysicsColliders(inst)            
+            RemovePhysicsColliders(inst)
         end,
     },
-    
+
 
     State{
         name = "open",
@@ -75,6 +110,9 @@ local states=
             inst.Physics:Stop()
             inst.components.sleeper:WakeUp()
             inst.AnimState:PlayAnimation("open")
+            if inst.SoundEmitter:PlayingSound("hutchMusic") then
+                inst.SoundEmitter:SetParameter("hutchMusic", "intensity", 1)
+            end 
         end,
 
         events=
@@ -84,7 +122,7 @@ local states=
 
         timeline=
         {
-            TimeEvent(0*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/chester/open") end),
+            TimeEvent(0*FRAMES, function(inst) inst.SoundEmitter:PlaySound( inst.sounds.open ) end),
         },        
     },
 
@@ -112,7 +150,7 @@ local states=
         
             TimeEvent(3*FRAMES, function(inst) 
 				inst.sg.mem.pant_ducking = inst.sg.mem.pant_ducking or 1
-				inst.SoundEmitter:PlaySound("dontstarve/creatures/chester/pant", nil, inst.sg.mem.pant_ducking) 
+				inst.SoundEmitter:PlaySound( inst.sounds.pant , nil, inst.sg.mem.pant_ducking) 
 				if inst.sg.mem.pant_ducking and inst.sg.mem.pant_ducking > .35 then
 					inst.sg.mem.pant_ducking = inst.sg.mem.pant_ducking - .05
 				end
@@ -127,6 +165,12 @@ local states=
             inst.AnimState:PlayAnimation("closed")
         end,
 
+        onexit = function(inst)
+            if not inst.sg.statemem.muffled and inst.SoundEmitter:PlayingSound("hutchMusic") then
+                inst.SoundEmitter:SetParameter("hutchMusic", "intensity", 0)
+            end 
+        end,
+
         events=
         {   
             EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),
@@ -134,7 +178,13 @@ local states=
 
         timeline=
         {
-            TimeEvent(0*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/chester/close") end),
+            TimeEvent(0*FRAMES, function(inst) inst.SoundEmitter:PlaySound( inst.sounds.close ) end),
+            TimeEvent(4*FRAMES, function(inst)
+                if inst.SoundEmitter:PlayingSound("hutchMusic") then
+                    inst.sg.statemem.muffled = true
+                    inst.SoundEmitter:SetParameter("hutchMusic", "intensity", 0)
+                end 
+            end)
         },        
     },
 
@@ -177,7 +227,7 @@ local states=
                 SpawnPrefab("chester_transform_fx").Transform:SetPosition(x, y + 1, z)
             end),
             TimeEvent(60*FRAMES, function(inst)
-                inst.SoundEmitter:PlaySound("dontstarve/creatures/chester/pop")
+                inst.SoundEmitter:PlaySound( inst.sounds.pop )
                 if inst.MorphChester ~= nil then
                     inst:MorphChester()
                 end
@@ -189,33 +239,181 @@ local states=
             EventHandler("animqueueover", function(inst) inst.sg:GoToState("idle") end ),
         },
     },
+
+    State{
+        name = "morph",
+        tags = {"busy"},
+        onenter = function(inst, morphfn)
+            inst.Physics:Stop()
+                        
+            inst.SoundEmitter:PlaySound("dontstarve/creatures/chester/raise")
+            inst.AnimState:PlayAnimation("transition", false)
+
+            --Remove ability to open chester for short time.
+            inst.components.container.canbeopened = false
+            inst.components.container:Close()
+
+            inst.sg.statemem.morphfn = morphfn
+        end,
+
+        timeline =
+        {
+
+            TimeEvent(1*FRAMES, function(inst)
+                inst.SoundEmitter:PlaySound("dontstarve/creatures/hutch/bounce")
+            end),
+            TimeEvent(22*FRAMES, function(inst)
+                inst.SoundEmitter:PlaySound("dontstarve/creatures/hutch/clap")
+            end),
+            TimeEvent(27*FRAMES, function(inst)
+                inst.SoundEmitter:PlaySound("dontstarve/creatures/hutch/clap")
+            end),
+            TimeEvent(32*FRAMES, function(inst)
+                inst.SoundEmitter:PlaySound("dontstarve/creatures/hutch/clap")
+            end),
+            TimeEvent(36*FRAMES, function(inst) 
+                local x, y, z = inst.Transform:GetWorldPosition()
+                SpawnPrefab("chester_transform_fx").Transform:SetPosition(x, y + 1, z)
+            end),
+            TimeEvent(37*FRAMES, function(inst)
+                inst.SoundEmitter:PlaySound("dontstarve/creatures/hutch/clap")
+            end),
+            TimeEvent(40*FRAMES, function(inst)
+                if inst.sg.statemem.morphfn ~= nil then
+                    local morphfn = inst.sg.statemem.morphfn
+                    inst.sg.statemem.morphfn = nil
+                    morphfn(inst)
+                end
+                inst.SoundEmitter:PlaySound( inst.sounds.pop )
+            end),
+        },
+
+        events =
+        {
+            EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),
+        },
+
+        onexit = function(inst)
+            if inst.sg.statemem.morphfn ~= nil then
+                --In case state was interrupted
+                local morphfn = inst.sg.statemem.morphfn
+                inst.sg.statemem.morphfn = nil
+                morphfn(inst)
+            end
+            --Add ability to open chester again.
+            inst.components.container.canbeopened = true
+        end,
+
+    },
 }
 
 CommonStates.AddWalkStates(states, {
     walktimeline = 
     { 
         --TimeEvent(0*FRAMES, function(inst)  end),
+
         TimeEvent(1*FRAMES, function(inst) 
-            inst.SoundEmitter:PlaySound("dontstarve/creatures/chester/boing")
-            inst.components.locomotor:RunForward() 
+            inst.SoundEmitter:PlaySound( inst.sounds.boing )
+
+            inst.components.locomotor:RunForward()
+
+            --Cave chester leaves slime as he bounces
+            if inst.leave_slime then
+                inst.sg.statemem.slimein = true
+                if inst.sg.mem.lastspawnlandingmovefx ~= nil and inst.sg.mem.lastspawnlandingmovefx + 2 > GetTime() then
+                    inst.sg.statemem.slimeout = true
+                    SpawnMoveFx(inst, .45 + math.random() * .1)
+                end
+            end
+        end),
+
+        TimeEvent(2 * FRAMES, function(inst)
+            if inst.sg.statemem.slimeout then
+                SpawnMoveFx(inst, .2 + math.random() * .1)
+            end
+        end),
+
+        TimeEvent(4 * FRAMES, function(inst)
+            if inst.sg.statemem.slimeout and math.random() < .7 then
+                SpawnMoveFx(inst, .1 + math.random() * .1)
+            end
+        end),
+
+        TimeEvent(7 * FRAMES, function(inst)
+            if inst.sg.statemem.slimeout and math.random() < .3 then
+                SpawnMoveFx(inst, 0)
+            end
         end),
-        --TimeEvent(12*FRAMES, function(inst) PlayFootstep(inst) end),
+
+        TimeEvent(10 * FRAMES, function(inst)
+            if inst.sg.statemem.slimein and math.random() < .6 then
+                SpawnMoveFx(inst, .05 + math.random() * .1)
+            end
+        end),
+
+        TimeEvent(12 * FRAMES, function(inst)
+            if inst.sg.statemem.slimein then
+                SpawnMoveFx(inst, .25 + math.random() * .1)
+            end
+        end),
+
+        TimeEvent(13*FRAMES, function(inst) 
+            if inst.sounds.land_hit ~= nil then
+                inst.SoundEmitter:PlaySound(inst.sounds.land_hit)
+            end
+            if inst.sg.statemem.slimein then
+                if inst.sounds.land ~= nil then
+                    inst.SoundEmitter:PlaySound(inst.sounds.land)
+                end                
+                SpawnMoveFx(inst, .8 + math.random() * .2)
+                inst.sg.mem.lastspawnlandingmovefx = GetTime()
+            end
+        end),
+
         TimeEvent(14*FRAMES, function(inst) 
             PlayFootstep(inst)
             inst.components.locomotor:WalkForward()
         end),
-    }
+    },
+
+    endtimeline =
+    {
+        TimeEvent(1*FRAMES, function(inst) 
+--[[
+            if inst.sounds.land_hit then
+                inst.SoundEmitter:PlaySound( inst.sounds.land_hit )
+            end
+            ]]
+            if inst.sg.statemem.slimein then
+                if inst.sounds.land ~= nil then
+                    inst.SoundEmitter:PlaySound(inst.sounds.land)
+                end                
+                SpawnMoveFx(inst, .4 + math.random() * .2)
+                inst.sg.mem.lastspawnlandingmovefx = GetTime()
+            end
+        end),
+    },
+
 }, nil, true)
 
 CommonStates.AddSleepStates(states,
 {
     starttimeline = 
     {
-        TimeEvent(0*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/chester/close") end)
+        TimeEvent(0*FRAMES, function(inst) inst.SoundEmitter:PlaySound( inst.sounds.close ) end)
+    },
+
+    sleeptimeline = 
+    {
+        TimeEvent(1*FRAMES, function(inst) 
+            if inst.sounds.sleep then
+                inst.SoundEmitter:PlaySound( inst.sounds.sleep ) 
+            end
+        end)
     },
     waketimeline = 
     {
-        TimeEvent(0*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/chester/open") end)
+        TimeEvent(0*FRAMES, function(inst) inst.SoundEmitter:PlaySound( inst.sounds.open ) end)
     },
 })
 

 

In particular, chester's stategraph now doesn't have hard-coded references to chester's sounds, it expects them in chester's instance.

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