Jump to content

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.

Edited by Lawrence

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")

Edited by simplex

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

Edited by Lawrence

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?

Edited by Lawrence

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.

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

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 ^_^

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