Jump to content

Recommended Posts

 I'm working on a milk-able goat mod and I can't find anywhere how to add a custom stategraph to an existing mob, and by that I mean how do I declare to use it in modmain.lua or where-ever do I declare that.

 

 Also, when making a custom stategraph, do I need to copy paste all the existing one and add my own bits or simply add the bits?

 

Thanks in advance

inst:SetStateGraph("SGbat")

 

in an addprefabpostinit should do the trick if you want to do it from modmain. Otherwise just put it in the prefab file where it belongs.

 

 

Edited by Heavenfall

inst:SetStateGraph("SGbat")

 

in an addprefabpostinit should do the trick if you want to do it from modmain. Otherwise just put it in the prefab file where it belongs.

 

 I hate to be that guy but I don't know how. This is what I have in modmain.lua, adding SetStateGraph in the function makes the game crash, but I don't know how to include it in the AddPrefabPostInit, could you help, please?

PrefabFiles = {	"lightninggoat",}function GoatPrefabPostInit(inst)local hair_growth_days = 2	    inst:AddComponent("beard")    inst.components.beard.bits = 2    inst.components.beard.daysgrowth = hair_growth_days + 1     inst.components.beard.onreset = function()        inst.sg:GoToState("shaved")    end        inst.components.beard.canshavetest = function() 	if not inst.components.sleeper:IsAsleep() then return false	    end return true end    inst.components.beard.prize = "goatmilk"    inst.components.beard:AddCallback(hair_growth_days, function()        if inst.components.beard.bits == 0 then            inst.hairGrowthPending = true        end    end)endAddPrefabPostInit("lightninggoat", GoatPrefabPostInit)

What does the log.txt say about your crash when you add it?

 

 I don't even know what happened. It didn't crash for some reason. But it seems that it doesn't use the custom stategraph since the goats don't "regrow" the milk back. And just to clarify that I explained my problem - I have added a Stategraph in the /scripts/stategraphs folder of the mod and I want it to be used instead of the game one, along with the changes that's in my previous post.

 

Edit: It might have crashed that because one of the goats was already harvested.

Edited by Cyde042

Post the mod.

 

http://www.filedropper.com/milkgoats

 

You can ignore the require bits, I was just messing around. Also the parts I added in the stategraph are between 2 long lines (--------------------------), near the end.

Edited by Cyde042

In modmain change

 

inst:SetStateGraph("SGlightninggoat")

 

to

 

inst:SetStateGraph("SGlightninggoat2")

 

and in SGlightninggoat2.lua change

 

return StateGraph("lightninggoat", states, events, "idle", actionhandlers)

 

to

 

return StateGraph("lightninggoat2", states, events, "idle", actionhandlers)

 

and delete SGlightninggoat.lua from your mod.

Edited by Heavenfall

In modmain change

 

inst:SetStateGraph("SGlightninggoat")

 

to

 

inst:SetStateGraph("SGlightninggoat2")

 

and in SGlightninggoat2.lua change

 

return StateGraph("lightninggoat", states, events, "idle", actionhandlers)

 

to

 

return StateGraph("lightninggoat2", states, events, "idle", actionhandlers)

 

and delete SGlightninggoat.lua from your mod.

 

 Forgot to delete the other SG, SGlightninggoat2 is the original and SGlightninggoat is the custom one

Let us know if you have any other problems.

 

I mean there is no lightninggoat2. I still get crashes even if I change the name of the stategraph in the function.

 

Edit: Talk about a rookie's mistake, I didn't set up a proper directory. Forgot to make a script folder. Anyway the stategraph seems to be working, but the milk doesn't grow back for some reason, or maybe goats aren't affected by time like a crockpot. I'll keep experimenting.

 

Edit2: The stategraph is fine, the animations work. What doesn't seem to work is the Callback function in the modmain.

 

Edit3: Got to make it work, finally. Had to add another line in the idle stat that responds to GrowthPending.

Edited by Cyde042

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