Jump to content

Modifying an action to allow for picking up rabbits?


Recommended Posts

Hello I'm a bit new to modding in DST, or modding in general for that matter, but I'm attempting to give my custom character the ability to pickup a rabbit like you would an item (or like you would from a trap for that matter) but I can't figure out how exactly to go about doing that. I've looked through the guideposts and previous threads on the forum, as well as looked through the game files or other mods, but haven't really been able to find anything that helps. From what I've read, it sounds like it could be possible through modifying the PICKUP action to bypass the components.inventoryitem.canbepickedup check but im not sure how to even start doing that, or if that is even the best way to do what I want.
Help would be much appreciated!

Link to comment
Share on other sites

As penguin0616 said, it will be quite difficult. With help of mod-commands (the ones from modutil.lua) you might be able to change the action only for your character without overwriting or making a new action.

But if you are new to lua and or modding, you should try to think of an alternative perk, that is easier to create, but also satisfy your needs.

If you still really want to be able to pick up rabbits (and I guesss they also should not run away from you?) I will dig into the code and see how this can be done without overwriting anything.

Link to comment
Share on other sites

Thank you two for the advice!

I've already managed to make rabbits not run from my character, but have been obviously struggling with allowing them to be picked up. On the surface it seemed like it wouldn't be that difficult to accomplish, but it seems less so now, oh well you live and you learn. I'll focus on other, easier, perk ideas to get a better grasp of lua and the dst code for now, but if you wouldn't mind figuring out how it could be done it would be much appreciated!

Link to comment
Share on other sites

ok, I will look into it when I have some time, guess will doing it over the weekend :)

edit:
I could not resist :D so no, it is not a good idea to mess with the actions to only make them pickable for your character. it is a "all or no one".  BUT: how about hammering the rabbits to knock them out, then you can pick them up. And since they don't run away from your character, this should be easy to do.

To make rabbits stunned when attacked with hammer, we could change their attacked stategraph (this is how it is done for moles). Or do you have a better idea? Of course we could also make all rabbits go stunned automatically without hamm,er if they are very close to your character, this would be even simpler.
What do you think? @Merkyrrie

 

Edited by Serpens
Link to comment
Share on other sites

Oh yeah, either of those options would work just as well! Though I feel using something other than a hammer would mesh better with what I'm going for, would it be possible to manage the same thing by say, feeding them carrots? If not, then making them automatically stunned when nearing them would be probably be the better way to go

Link to comment
Share on other sites

6 hours ago, Merkyrrie said:

Oh yeah, either of those options would work just as well! Though I feel using something other than a hammer would mesh better with what I'm going for, would it be possible to manage the same thing by say, feeding them carrots? If not, then making them automatically stunned when nearing them would be probably be the better way to go

Are you already able to feed them carrots, while they are not in your inventory?
If not, this is again a thing that is an all or nothing, so also all other players would be able to feed them carrots, although we might be able that it only gets stunned when it is your character feeding.

Link to comment
Share on other sites

1 hour ago, Merkyrrie said:

Its not currently possible to, no, so if its the same issue with just picking them up like before it would probably be best, and more preferable, to try and go for making them stunned if you get near them over anything else

how did you achieve, that the rabbits do not run away from you?
Removing the scarytoprey tag from your character also affects other creatures that usually run away. But of course this is by far the simplest solution.

Edited by Serpens
Link to comment
Share on other sites

I did just remove the scarytoprey tag, which affects a few other animals like grass geckos, butterflies, and penguins as well, but some like birds and buzzards are still affected by anything with a 'player' tag. I'm not sure what other way you'd make specifically rabbits not run away without overwriting something

For now I'm just letting that be a quote on quote "feature" until it becomes a problem, or until I can find a better way to do it

Link to comment
Share on other sites

ok, I think I found the best solution :) I simply added a new action for this (in modmain.lua):

-- adding a new action, that stuns rabbits
local action_string = "Tame" -- you can change this string to your liking. And replace "wilson" in the following with your character prefab (EXCEPT the ones within AddStategraphActionHandler(...) )
local MERK_TAME_RABBIT = AddAction("MERK_TAME_RABBIT", action_string, function(act)
    if act.doer~=nil and act.doer.prefab=="wilson" and act.target~=nil then
        act.target.sg:GoToState("stunned") -- make the rabbit stunned. Unfortunately we can not check if the target has this state, but rabbits will have it.
        return true
    end
end)
AddComponentAction("SCENE", "merk_tameable", function(inst, doer, actions, right)
    if doer~=nil and doer.prefab=="wilson" and inst~=nil and not inst:HasTag("INLIMBO") then
        table.insert(actions, MERK_TAME_RABBIT)
	end
end)
AddStategraphActionHandler("wilson", GLOBAL.ActionHandler(MERK_TAME_RABBIT, "give")) -- do the "give" animation for this action
AddStategraphActionHandler("wilson_client", GLOBAL.ActionHandler(MERK_TAME_RABBIT, "give"))

AddPrefabPostInit("rabbit",function(inst)
    inst:AddComponent("merk_tameable") -- we need this component, although it does nothing, to be able to do AddComponentAction
end)

AddPlayerPostInit(function(player)
    if player.prefab=="wilson" then
        player:RemoveTag("scarytoprey") -- removing this tag, so rabbits dont run away
    end
end)

And also put a component into the modfolder scripts/components which is named merk_tameable.lua and has the following code:

-- nothing more to do here, since we only need to to be able to add a componentaction
local Merk_Tameable = Class(function(self, inst)
    self.inst = inst
end)

return Merk_Tameable

and finished :)

Edited by Serpens
  • Like 1
Link to comment
Share on other sites

I've finally gotten around to testing the code, but it doesn't appear to be fully working. The game prompts me to do the action, both with or without an item in hand, and upon clicking does the Give animation, but the action itself doesn't appear to be doing anything to the rabbit

Link to comment
Share on other sites

27 minutes ago, Merkyrrie said:

I've finally gotten around to testing the code, but it doesn't appear to be fully working. The game prompts me to do the action, both with or without an item in hand, and upon clicking does the Give animation, but the action itself doesn't appear to be doing anything to the rabbit

hm strange, I tested the code myself and it works, just as I posted it, no errors in there.
Did you replace all "wilson" with your character prefab? If it still does not work, use the code as it is and try if it works with wilson at least.
 

edit:
ah, in AddStategraphActionHandler(...) you should not replace wilson by your character string. I think it is wislon here for every character. So the code above, with everything wilson works for wilson. If it still does not work for your character, try testing around with it, maybe try wolfgang and then again your character.

Edited by Serpens
Link to comment
Share on other sites

18 minutes ago, Serpens said:

hm strange, I tested the code myself and it works, just as I posted it, no errors in there.
Did you replace all "wilson" with your character prefab? If it still does not work, use the code as it is and try if it works with wilson at least.

I did replace it with my character prefab at first, and upon changing it back to wilson its working perfectly. Could my character prefab be missing something that would be needed to make the action work?

Link to comment
Share on other sites

7 minutes ago, Merkyrrie said:

I did replace it with my character prefab at first, and upon changing it back to wilson its working perfectly. Could my character prefab be missing something that would be needed to make the action work?

I edited above, that AddStategraphActionHandler(...) needs to be wilson. does it work then? (if not, I will be available in ~11 hours again ,going to sleep now :D)

Edited by Serpens
  • Thanks 2
Link to comment
Share on other sites

11 minutes ago, Serpens said:

I edited above, that AddStategraphActionHandler(...) needs to be wilson. does it work then? (if not, I will be available in ~11 hours again ,going to sleep now :D)

Oops, I missed your edit above my bad! I originally tried to keep the "wilson_client" part the same when testing because I figured that might be something that doesn't exist for each character, but I never thought to keep the other one as wilson.
But yep, with both the AddStategraphActionHandlers being 'wilson' it works now. Perfectly pickup-able rabbits

Thanks for all the help, it was very appreciated! And have a goodnight :)

  • Like 1
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...