Jump to content

Editing Component Actions

Recommended Posts

I'm trying to figure out how to edit the criteria that determines whether or not an action is displayed. For example, in my mod firepits and campfires can be fueled, but must have a spark before they will start burning. The COOK action only checks to determine if a firepit is fueled, not if it's on fire/burning, so this means that food can be cooked on a fueled, but not burning, firepit.

I know how to edit the ACTIONS.COOK.fn in order to prevent this, but this causes the animation to be carried out, after which the characters says "I can't do that." I'm looking for a way to prevent the action from being displayed at all, like when you try to cook something on an empty firepit and you only have the option to examine it. 

I know that this is in the componentactions.lua file, but they are all local and I can't figure out how to edit them from modmain. I'm fairly certain that all I need to do is add the condition: 

and not ((target.prefab == "campfire" or target.prefab == "firepit") and target.components.burnable:IsBurning() == false)

to the "cookable" component action, somehow..

Edited by Ziro2k
Link to comment
Share on other sites

From modmain you can edit cookable.lua functions with AddComponentPostInit("cookable", yourfunction) where yourfunction is a function written by you in the modmain. Use this to replace the function you need. For example for cookable.lua

function OnCookedPostInit(inst)
  local old_oncooked = inst.components.cookable and inst.components.cookable.oncooked
  local function new_oncooked(inst, cooker, chef)
    --add if conditions then call old_oncooked
    --like this assuming you have a check for if the campfire is burning
    if campfire_isburning then
      old_oncooked(inst, cooker, chef)
      --call the inspect here

AddComponentPostInit("cookable", OnCookedPostInit)

This should replace the cookable.lua oncooked which won't be called unless the campfire is burning. If the campfire isn't burning then you should call the inspect function. Hope this helps or at least points you in the right direction. Remember you can use AddComponentPostInit or if you need to modify a prefab with functions then AddPrefabPostInit("prefab name", yourfunction) will work.

Link to comment
Share on other sites

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