Jump to content

Help trying to pick up Rabbits and Birds (Custom Perk)


Recommended Posts

Well, don't be discouraged. I'm fairly sure everything you want to do is possible without overwriting game lua files. You can override an object's functions from a mod, as well as add more Actions (or modify existing ones, I guess), which are... stuff a player can do with an object, such as Examine, Murder, Pickup and such.

For example, in a PrefabPostInit for rabbits you could override the ondropped function of all rabbits in order to do additional custom stuff after they're dropped. You can probably access the stategraph from a mod environment in some manner and affect it. I haven't modded for quite a while to remember by heart the exact procedures. What I can tell you is that I think you don't really want to do any of this stuff (modifying ondropped or stategraph stuff for the rabbits) and what you should do is modify (override) the existing pickup action or add a new one that only appears for your character. This is a little more involved than doing the other things, but not overwhelmingly so. You'd need to imitate existing code for actions. Your custom action would differ from the original pickup action in that it would allow picking up rabbits regardless of their components.inventoryitem.canbepickedup value (for your character). Once you're done you should be able to do much the same (or exactly the same) in regards to birds to make them pickupable by your character, if you want. Also, if you keep referring to ThePlayer in your code (rather than a specific player instance, as delivered in a relevant argument to a function you'd be modifying), then obviously whatever you do will constantly regard only the same one player (the host) every time, regardless of, well, anything. So you don't want that.

Reading existing code and searching for examples and similar mods (ones that do stuff like what you're trying to) indeed helps. I actually found a thread of someone trying to do much the same as you. It should help you out.

 

Link to comment
Share on other sites

So looking into it more you can overwrite the rabbit's stategraph state "stunned". This can be added into your modmain. I didn't have time to make it exclusive to your own character, but this would remove the canbepickedup = false allowing anyone who sets down a rabbit to pick it back up. If I have time later I should be able to help more.

local stunned =
State(
{
        name = "stunned",
        tags = {"busy", "stunned"},
        
        onenter = function(inst) 
            inst.Physics:Stop()
            inst.AnimState:PlayAnimation("stunned_loop", true)
            inst.sg:SetTimeout(2)
            if inst.components.inventoryitem then
                inst.components.inventoryitem.canbepickedup = true
            end
        end,
        
        onexit = function(inst)
            -- if inst.components.inventoryitem then
                -- inst.components.inventoryitem.canbepickedup = false
            -- end
        end,
        
        ontimeout = function(inst) inst.sg:GoToState("idle") end,
}
)
AddStategraphState("rabbit", stunned)

 

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
 Share

×
  • Create New...