Jump to content

[Help] Trying to add a StateGraph to mobs


Recommended Posts

Hi guys,
I can't understand how to add custom Stategraph to mobs, I looked to "API examples" but it doesn't work...
 

For example I wrote this on modmain:

 

local stunned = State({
    name = "stun",
    tags = {"idle", "canrotate"},
    onenter = function(inst)
        inst.Transform:SetRotation(0)
        inst.AnimState:PushAnimation("idle_loop", true)
    end,
    timeline = {
        TimeEvent(20*FRAMES, function(inst) inst.Transform:SetRotation(90) end),
        TimeEvent(40*FRAMES, function(inst) inst.Transform:SetRotation(180) end),
        TimeEvent(60*FRAMES, function(inst) inst.Transform:SetRotation(270) end),
        TimeEvent(80*FRAMES, function(inst) inst.Transform:SetRotation(0) end),
        TimeEvent(100*FRAMES, function(inst) inst.sg:GoToState("idle") end),
    },
    events =
    {
        EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),
    },
})

 

 

then I tried

AddStategraphState("pigman", stunned), but results in "TRIED TO GO TO INVALID STATE";

so I wrote

 

AddStategraphState("pig", stunned), no errors showing in this way, but the pigs doesn't do anything.

 

What am I doing wrong? Can you help me? Thanks.

Link to comment
Share on other sites

Hi guys,

I can't understand how to add custom Stategraph to mods, I looked to "API examples" but it doesn't work...

 

For example I wrote this on modmain:

 

(stuff)

 

then I tried

AddStategraphState("pigman", stunned), but results in "TRIED TO GO TO INVALID STATE";

so I wrote

 

AddStategraphState("pig", stunned), no errors showing in this way, but the pigs doesn't do anything.

 

What am I doing wrong? Can you help me? Thanks.

The correct would indeed be

 AddStategraphState("pig", stunned)
since the name of the stategraph is SGpig.lua.

Your state looks right to me. My guess is there's just nothing triggering it (such as event or action handlers). If you spawn a pigman and then do inst.sg:GoToState("stun"), does it work?

(by the way, if you want the state to be somewhat "permanent" until it ends, you may want to replace the "idle" tag with "busy")

Link to comment
Share on other sites

The correct would indeed be

 AddStategraphState("pig", stunned)
since the name of the stategraph is SGpig.lua.

Your state looks right to me. My guess is there's just nothing triggering it (such as event or action handlers). If you spawn a pigman and then do inst.sg:GoToState("stun"), does it work?

(by the way, if you want the state to be somewhat "permanent" until it ends, you may want to replace the "idle" tag with "busy")

 

 

I made a sort of staff that should stun mobs and yeah, I used    inst.sg:GoToState("stun") but doesn't do anything

Now I'm trying to replace idle with busy

Link to comment
Share on other sites

The correct would indeed be

 AddStategraphState("pig", stunned)
since the name of the stategraph is SGpig.lua.

Your state looks right to me. My guess is there's just nothing triggering it (such as event or action handlers). If you spawn a pigman and then do inst.sg:GoToState("stun"), does it work?

(by the way, if you want the state to be somewhat "permanent" until it ends, you may want to replace the "idle" tag with "busy")

 

 

Ok, with "busy" at least the pig rotates to 0 (from   inst.Transform:SetRotation(0) ), but does not spin :/

 

should I add an action?

Link to comment
Share on other sites

Mmh... Now it goes on idle for ever, but no spins yet

I don't know what to tell you. I just took the code snippet you posted, changed the "idle" tag to "busy", commented out the "animover" event handler, spawned a pig and put it in the stun state with inst.sg:GoToState("stun"). It worked, with each step of the 90 degree rotation happening properly.

Link to comment
Share on other sites

I don't know what to tell you. I just took the code snippet you posted, changed the "idle" tag to "busy", commented out the "animover" event handler, spawned a pig and put it in the stun state with inst.sg:GoToState("stun"). It worked, with each step of the 90 degree rotation happening properly.

 

It seems that it skips everything inside   " timeline = { ... } "

what the ...? o_o

Link to comment
Share on other sites

It seems that it skips everything inside   " timeline = { ... } "

what the ...? o_o

It seems something else in your code is causing a change of state right after it enters the stun state. Probably the onattacked event handler.

Link to comment
Share on other sites

No, sorry I was wrong

 

it works xD

sorry I'm stupid somethimes

(and with sometimes I mean always)

 

 

It seems something else in your code is causing a change of state right after it enters the stun state. Probably the onattacked event handler.

 

Thanks a lot for the help ^_^

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