Jump to content

Custom prefab really slow attacks?


Somnei

Recommended Posts

Hey, my custom monster (that has the stategraph of a smallbird morphed with a spider) sort of freezes up and pauses a long time once it's targeting something before attacking. I'm sure there are some obvious faults in my stategraph, and I'd love if someone experienced just read through it! (since I can't tell what's wrong with it myself x:)

require("stategraphs/commonstates")local actionhandlers = {    ActionHandler(ACTIONS.EAT, "eat"),}local events={    CommonHandlers.OnStep(),    CommonHandlers.OnSleep(),    CommonHandlers.OnLocomote(false,true),    CommonHandlers.OnFreeze(),    EventHandler("attacked", function(inst)        if not inst.components.health:IsDead() then            inst.sg:GoToState("hit")        end    end),    EventHandler("doattack", function(inst)         if not inst.components.health:IsDead() and not inst.sg:HasStateTag("busy") then             inst.sg:GoToState("attack")         end     end),    EventHandler("death", function(inst) inst.sg:GoToState("death") end),    EventHandler("locomote", function(inst)         if not inst.sg:HasStateTag("busy") then                        local is_moving = inst.sg:HasStateTag("moving")            local wants_to_move = inst.components.locomotor:WantsToMoveForward()            if not inst.sg:HasStateTag("attack") and is_moving ~= wants_to_move then                if wants_to_move then                    inst.sg:GoToState("premoving")                else                    inst.sg:GoToState("idle")                end            end        end    end),    }local function SoundPath(inst, event)    local creature = "spider"    if inst:HasTag("spiderchan") then        creature = "spider"    elseif inst:HasTag("spider_hider") or inst:HasTag("spider_spitter") then        creature = "cavespider"    else        creature = "spider"    end    return "dontstarve/creatures/" .. creature .. "/" .. eventendlocal states={                State{        name = "idle",        tags = {"idle", "canrotate"},                ontimeout = function(inst)			--inst.sg:GoToState("taunt")			            if math.random() <= inst.userfunctions.GetPeepChance(inst) then                inst.sg:GoToState("idle_peep")            else                inst.sg:GoToState("taunt")            end        end,                onenter = function(inst, start_anim)            inst.Physics:Stop()            local animname = "idle"            if math.random() < .3 then				inst.sg:SetTimeout(math.random()*2 + 2)			end                        if inst.LightWatcher:GetLightValue() > 1 then                inst.AnimState:PlayAnimation("cower" )                inst.AnimState:PushAnimation("cower_loop", true)            else                if start_anim then                    inst.AnimState:PlayAnimation(start_anim)                    inst.AnimState:PushAnimation("idle", true)                else                    inst.AnimState:PlayAnimation("idle", true)                end            end        end,       	 events=        {            EventHandler("startstarving",                 function(inst, data)                    --print("smallbird - SG - startstarving")                    inst.sg:GoToState("idle_peep")                end            ),        },    },        State{        name = "idle_peep",        tags = {"idle"},                onenter = function(inst)            inst.Physics:Stop()            inst.AnimState:PlayAnimation("cower")	    inst.components.talker:Say(SPIDERCHAN_TALK_HUNGRY)        end,               timeline =         {            TimeEvent(3*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/spider/attack") end),        },        events=        {            EventHandler("animover",                 function(inst,data)                     if math.random() <= inst.userfunctions.GetPeepChance(inst) then	    		inst.components.talker:Say(SPIDERCHAN_TALK_HUNGRIER)                    else                        inst.sg:GoToState("idle")                    end                end            ),        },    },	State{            name = "death",            tags = {"busy"},                onenter = function(inst)            inst.SoundEmitter:PlaySound("dontstarve/creatures/smallbird/death")            inst.AnimState:PlayAnimation("death")            inst.components.locomotor:StopMoving()            RemovePhysicsColliders(inst)                        inst.components.lootdropper:DropLoot(Vector3(inst.Transform:GetWorldPosition()))                    end,            },        State{        name = "hatch",        tags = {"busy"},        onenter = function(inst)            inst.SoundEmitter:PlaySound("dontstarve/creatures/smallbird/egg_hatch_crack")            inst.AnimState:PlayAnimation("taunt")        end,        timeline =         {            TimeEvent(30*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/smallbird/egg_hatch") end),        },        events=        {            EventHandler("animover", function(inst)                inst.sg:GoToState("idle")                inst.userfunctions.FollowPlayer(inst)            end),        },    },    State{        name = "growup",        tags = {"busy"},        onenter = function(inst)            inst.Physics:Stop()            inst.AnimState:PlayAnimation("grow")        end,        timeline =         {            TimeEvent(28*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/smallbird/leg_sproing") end),            TimeEvent(30*FRAMES, function(inst) inst.Transform:SetScale(1.1, 1.1, 1.1) end),            TimeEvent(100*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/teenbird/leg_sproing") end),            TimeEvent(102*FRAMES, function(inst) inst.Transform:SetScale(1.2, 1.2, 1.2) end),        },        events=        {            EventHandler("animover", function(inst)                inst.userfunctions.SpawnTeen(inst)            end),        },    },    State{        name = "taunt",        tags = {"busy", "canrotate"},                onenter = function(inst)            inst.Physics:Stop()            inst.AnimState:PlayAnimation("taunt")            inst.SoundEmitter:PlaySound(SoundPath(inst, "scream"))            if inst.components.combat and inst.components.combat.target then                inst:FacePoint(Vector3(inst.components.combat.target.Transform:GetWorldPosition()))            end        end,                timeline=        {            TimeEvent(10*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/spider/scream") end),            TimeEvent(17*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/spider/scream") end),            TimeEvent(28*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/spider/scream") end),        },                events=        {            EventHandler("animover", function(inst) inst.sg:GoToState("idle") end),        },    },            State{        name = "attack",        tags = {"attack"},                onenter = function(inst, cb)            inst.Physics:Stop()            inst.components.combat:StartAttack()            inst.AnimState:PushAnimation("atk", false)        end,                timeline=        {            TimeEvent(10*FRAMES, function(inst) inst.SoundEmitter:PlaySound(SoundPath(inst, "Attack")) end),            TimeEvent(10*FRAMES, function(inst) inst.SoundEmitter:PlaySound(SoundPath(inst, "attack_grunt")) end),            TimeEvent(25*FRAMES, function(inst) inst.components.combat:DoAttack(inst.sg.statemem.target) end),        },                events=        {            EventHandler("animover", function(inst) inst.sg:GoToState("idle") end),        },    },    State{        name = "hit",        tags = {"busy"},                onenter = function(inst)            inst.AnimState:PlayAnimation("hit")            inst.Physics:Stop()                    end,                events=        {            EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),        },            },            State{        name = "hit_stunlock",        tags = {"busy"},                onenter = function(inst)            inst.SoundEmitter:PlaySound(SoundPath(inst, "hit_response"))            inst.AnimState:PlayAnimation("hit")            inst.Physics:Stop()                    end,                events=        {            EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),        },    },      State{        name = "eat",        tags = {"busy", "canrotate"},                onenter = function(inst)            inst.Physics:Stop()                        inst.AnimState:PlayAnimation("eat")        end,                events=        {            EventHandler("animover", function(inst)                if inst:PerformBufferedAction() then                    inst.sg:GoToState("eat_loop")                else                    inst.sg:GoToState("idle")                end            end),        },    },      State{        name = "premoving",        tags = {"moving", "canrotate"},                onenter = function(inst)            inst.components.locomotor:WalkForward()            inst.AnimState:PlayAnimation("walk_pre")        end,                timeline=        {            TimeEvent(3*FRAMES, function(inst) inst.SoundEmitter:PlaySound(SoundPath(inst, "walk_spider")) end),        },                events=        {            EventHandler("animover", function(inst) inst.sg:GoToState("moving") end),        },    },    State{        name = "moving",        tags = {"moving", "canrotate"},                onenter = function(inst)            inst.components.locomotor:RunForward()            inst.AnimState:PushAnimation("walk_loop")        end,                timeline=        {                    TimeEvent(0*FRAMES, function(inst) inst.SoundEmitter:PlaySound(SoundPath(inst, "walk_spider")) end),            TimeEvent(3*FRAMES, function(inst) inst.SoundEmitter:PlaySound(SoundPath(inst, "walk_spider")) end),            TimeEvent(7*FRAMES, function(inst) inst.SoundEmitter:PlaySound(SoundPath(inst, "walk_spider")) end),            TimeEvent(12*FRAMES, function(inst) inst.SoundEmitter:PlaySound(SoundPath(inst, "walk_spider")) end),        },                events=        {            EventHandler("animover", function(inst) inst.sg:GoToState("moving") end),        },            },             State{        name = "eat_loop",        tags = {"busy"},                onenter = function(inst)            inst.Physics:Stop()            inst.AnimState:PlayAnimation("eat_loop", true)            inst.sg:SetTimeout(1+math.random()*1)        end,                ontimeout = function(inst)            inst.sg:GoToState("idle", "eat_pst")        end,           },  }--CommonStates.AddWalkStates(states, {--   walktimeline = --    { --        TimeEvent(1*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/smallbird/wings") end),        --TimeEvent(13*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/smallbird/footstep") end),--    }--}, nil, true)CommonStates.AddSleepStates(states,{    starttimeline =     {        TimeEvent(0*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/smallbird/sleep") end)    },    waketimeline =     {        TimeEvent(0*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/smallbird/wakeup") end)    },})CommonStates.AddFrozenStates(states)return StateGraph("spiderchan", states, events, "idle", actionhandlers)
Thank you!
Link to comment
Share on other sites

Hmm.. Try printing the name of each state in the onenter functions, then see which one it gets caught up in during the delay.

 

Example,

State{	name = "eat",	tags = {"busy", "canrotate"},	onenter = function(inst)		print("eating")				inst.Physics:Stop()		inst.AnimState:PlayAnimation("eat")	end,	events=	{		EventHandler("animover", function(inst)			if inst:PerformBufferedAction() then				inst.sg:GoToState("eat_loop")			else				inst.sg:GoToState("idle")			end		end),	},}
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...