Jump to content

Need Help With Some Scripting


Nycidian

Recommended Posts

So with my mod I added new crockpot and drying rack food which is all good except I can't figure out how to set the animations for them drying or for the crockpot being done.

 

Anyone have any ideas?

 

 

Edit:

 

Alright I lied I can dry things on the rack but not only am I not able to set an animation but at the end I get nothing by harvesting it either.

 

 

Edit Two: Well I feel silly I figured out what I wasn't getting any food it helps if you reference the new foods prefab file.  

 

  :(

 

Anyway I still need to figure out the animation issue.

Link to comment
Share on other sites

Look at "meat_rack_food.zip", you'll see that these are somehow incorporate in the animation of the drying rack. I haven't made any experience with it, but I'd guess you can create a duplicate of the file, hex-edit the build.bin and/or the anim.bin to change the names and fiddle a bit with the code.

Link to comment
Share on other sites

I know where the animations are what I need to know is how to assign new animations to drying food and food sitting in the cook pot.

 

As of right now I can easily make a new animation when I want/need too but if I can't figure out how to get the game to use it on those two items it won't help me much.

Link to comment
Share on other sites

Important line in "meat_rack.lua" is this:

inst.AnimState:OverrideSymbol("swap_dried", "meat_rack_food", dryable)

As I said, I have no experience with is, but I would try to duplicate "meat_rack_food.zip" and edit my atlas, build and anim and then change the above line to incorporate my new foods, somehow like this:

if "dryable is a vanilla food" then    inst.AnimState:OverrideSymbol("swap_dried", "meat_rack_food", dryable)else    inst.AnimState:OverrideSymbol("swap_dried", "meat_rack_new_food", dryable)end

and introduce some kind of test function for the if clause of course.

Good luck, and if you get it to work, let me know.

Link to comment
Share on other sites

I figured it out, kinda.

 

I will eventually be able to do custom animations with this method but for the moment I'm just happy not to have a empty dying rack.

 

Basically you just overwrite the meatrack.lua file and then add some scripts in the functions.

local function onstartdrying(inst, dryable)	if dryable == "pigskin" or dryable == "spoiled_food" then		dryable = "smallmeat"	end    inst.AnimState:PlayAnimation("drying_pre")	inst.AnimState:PushAnimation("drying_loop", true)    inst.AnimState:OverrideSymbol("swap_dried", "meat_rack_food", dryable)endlocal function setdone(inst, product)	if product == "dry_rot" or product == "pork_rinds" then		product = "smallmeat_dried"	end    inst.AnimState:PlayAnimation("idle_full")    inst.AnimState:OverrideSymbol("swap_dried", "meat_rack_food", product)endlocal function ondonedrying(inst, product)		if product == "dry_rot" or product == "pork_rinds" then		product = "smallmeat_dried"	end    inst.AnimState:PlayAnimation("drying_pst")    local ondonefn -- must be forward declared, as it refers to itself in the function body    ondonefn = function(inst)        inst:RemoveEventCallback("animover", ondonefn)        setdone(inst, product)    end    inst:ListenForEvent("animover", ondonefn)end

Mind you I'm not sure how yet to insert custom animations but from this point it should be fairly easy. I'll tackle that later

Link to comment
Share on other sites

I figured it out, kinda.

 

I will eventually be able to do custom animations with this method but for the moment I'm just happy not to have a empty dying rack.

 

Basically you just overwrite the meatrack.lua file and then add some scripts in the functions.

[...]

Mind you I'm not sure how yet to insert custom animations but from this point it should be fairly easy. I'll tackle that later

That's exactly what I meant, but for the sake of compatibility with other mods you shouldn't overwrite the vaniall files. Instead do it like this in modmain:

local function onstartdrying(inst, dryable)	if dryable == "pigskin" or dryable == "spoiled_food" then		dryable = "smallmeat"	end    inst.AnimState:PlayAnimation("drying_pre")	inst.AnimState:PushAnimation("drying_loop", true)    inst.AnimState:OverrideSymbol("swap_dried", "meat_rack_food", dryable)endlocal function setdone(inst, product)	if product == "dry_rot" or product == "pork_rinds" then		product = "smallmeat_dried"	end    inst.AnimState:PlayAnimation("idle_full")    inst.AnimState:OverrideSymbol("swap_dried", "meat_rack_food", product)endlocal function ondonedrying(inst, product)		if product == "dry_rot" or product == "pork_rinds" then		product = "smallmeat_dried"	end    inst.AnimState:PlayAnimation("drying_pst")    local ondonefn -- must be forward declared, as it refers to itself in the function body    ondonefn = function(inst)        inst:RemoveEventCallback("animover", ondonefn)        setdone(inst, product)    end    inst:ListenForEvent("animover", ondonefn)endlocal function ModDryingRack(inst)	inst.components.dryer:SetStartDryingFn(onstartdrying)	inst.components.dryer:SetDoneDryingFn(ondonedrying)	inst.components.dryer:SetContinueDryingFn(onstartdrying)	inst.components.dryer:SetContinueDoneFn(setdone)endAddPrefabPostInit("meatrack", ModDryingRack)

You can actually make it even more compatible by saving the old "StartDryingFn", "DoneDryingFn" etc. and calling those in your new functions to make sure you're not overwriting the functions of other mods. But I can't say for certain how to do that exactly right now. Anyways, I'm glad you made it work  ^^

Link to comment
Share on other sites

So I figured out I think how the animations are getting switched the problem is unless I want to use a default animation it looks like its impossible ATM to change them as there is something happening in a file that I don't have access too at least  can't find any lua file where this function is being defined.

inst.AnimState:OverrideSymbol("swap_cooked", "cook_pot_food", inst.components.stewer.product)

I tried making a copy of the cook_pot_food file renaming it and changing the build to match that name hoping that might work so I could swap out the files at need but that doesn't work.
 

So at this point I need someone in the know to either tell me another way to do this or is there a chance that in the future there will be a function made available to do this?

 

For any custom mods not being able to do custom animations for something as integral as food is a big drawback.

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