Jump to content

Recommended Posts

In my mods I usually need to add the ability for the player to apply a certain prefab to another prefab.

AddComponentAction("USEITEM", "unnecessary_component", function(inst, doer, target, actions, right)
    -- do something
end)

It bothers me that I have to create a empty unnecessary_component every time for the item the player needs to apply.
For example, if you want to add the use of boards on an item in the world, you will need to create an "unnecessary_component" and add it to the "boards".
 

AddPrefabPostInit("boards", function( inst )
    inst:AddComponent("unnecessary_component")
end)

Maybe there is an alternative way to bind an action to a prefab? An abstract function called "AddPrefabAction" in which you need to specify not the item component, but the name of the prefab itself.

AddPrefabAction("USEITEM", "boards", function(inst, doer, target, actions, right)
    -- do something
end)

As far as I know, creating a dummy component is the easiest way of binding a custom action to a prefab, or a set of prefabs for that matter. There is another way if you really don't like creating dummy components and that's to set up either `leftclickoverride` or `rightclickoverride` from the PlayerActionPicker component but that method is way more complicated and requires more code in general.

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