Jump to content

[Help]Declare usage of a custom stategraph to a vanilla mob


Cyde042

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

Link to comment
Share on other sites

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)
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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