Jump to content

[Help Needed] Coding a tool that allows fast harvesting


Recommended Posts

Ok, so i wrecked my ass long enough to finally accept, that I just don't know enough about lua and scripting to make it right. 

 

Main idea: add a hand-held item with limited uses, that allows quick picking twigs, grass, mushrooms, etc. while degrading with each item harvested. Also it prevents damage from picking spiked bushes and cacti.

 

There is already a mod (PickyPickyPicky) that just makes all those quick-pickable but its just too much of cheat to me. It adds a custom function:

function PPP_QuickPick(inst)	if inst.components.pickable then	inst.components.pickable.quickpick = true	endend 

Then writes it in plant's prefab files via AddPrefabPostInit, but I have no idea how to adapt it for OnEquip section of item parameters.

 

So main problems are:

1. How to make that function activate when this item is equipped and deactivate once it is unequipped or depleted? (Preferably without the need to overwrite the main game files, because of conflicts with other mods)

2. How to link finite uses of the item to character harvesting plants?

3. And how to make it prevent the damage, dealt by picking "spiked" type of plants?

 

Somehow I thought it would be much easier and even got everything else ready (item sprites, inventory images etc), so now I really don't wanna give up on this one. If anyone can give some advice, tips to what functions I could use - it'll be MUCH appreciated. Thanks for your time in advance;)

Link to comment
Share on other sites

Ok, so i wrecked my ass long enough to finally accept, that I just don't know enough about lua and scripting to make it right. 

 

Main idea: add a hand-held item with limited uses, that allows quick picking twigs, grass, mushrooms, etc. while degrading with each item harvested. Also it prevents damage from picking spiked bushes and cacti.

 

There is already a mod (PickyPickyPicky) that just makes all those quick-pickable but its just too much of cheat to me. It adds a custom function:

function PPP_QuickPick(inst)	if inst.components.pickable then	inst.components.pickable.quickpick = true	endend 

Then writes it in plant's prefab files via AddPrefabPostInit, but I have no idea how to adapt it for OnEquip section of item parameters.

 

So main problems are:

1. How to make that function activate when this item is equipped and deactivate once it is unequipped or depleted? (Preferably without the need to overwrite the main game files, because of conflicts with other mods)

2. How to link finite uses of the item to character harvesting plants?

3. And how to make it prevent the damage, dealt by picking "spiked" type of plants?

 

Somehow I thought it would be much easier and even got everything else ready (item sprites, inventory images etc), so now I really don't wanna give up on this one. If anyone can give some advice, tips to what functions I could use - it'll be MUCH appreciated. Thanks for your time in advance;)

 

I had this idea too, but with the razor in hands. The thing you "never" need. Maybe you use this?

Link to comment
Share on other sites

I had this idea too, but with the razor in hands. The thing you "never" need. Maybe you use this?

 

It does not really make a difference, what kind of item it'll be - I just can't find right coding to make it work. Plus it needs to have finite uses.

 

But thanks for replying anyway =)

Link to comment
Share on other sites

1. How to make that function activate when this item is equipped and deactivate once it is unequipped or depleted? (Preferably without the need to overwrite the main game files, because of conflicts with other mods)

inst:ListenForEvent("equipped", function(inst, data)    -- enable()end)inst:ListenForEvent("unequipped", function(inst, data)    -- disable()end)inst:ListenForEvent("percentusedchange", function(inst, data)    if data.percent <= 0 then        -- disable()    endend)

 

 

2. How to link finite uses of the item to character harvesting plants?

-- Item instanceinst.components.finiteUses:Use(1)

You'll probably want to work with Actions. Depends on what route you take.

 

 

 

3. And how to make it prevent the damage, dealt by picking "spiked" type of plants?

-- Player instancelocal old_GetAttacked = inst.components.combat.GetAttacked-- Enable protectionfunction inst.components.combat:GetAttacked(attacker, damage, weapon, stimuli)    if attacker.prefab ~= "marsh_bush" then        return old_GetAttacked(attacker, damage, weapon, stimuli)    endend-- Disable protectioninst.components.combat.GetAttacked = old_GetAttacked
Link to comment
Share on other sites

Hello again, @Blueberrys, unfortunately I wasn't able to use codes you suggested. It is first time I am working with player's actions and my experience in coding comes entirely from looking through other modders codes. I just have no idea how to tie change in action type with equipping an item (I don't really want to introduce a whole new action, I just need to change "dolongaction" to "doshortaction" in ACTION.PICK for all characters while certain item is equipped).
 
I see really three options: first
1) Add a function to bush, grass and etc. prefabs, that'll enable quick pick (that is already done in PickyPickyPicky mod)
2) Add a check in that function for a specific item to be equpped in player's hand slot.
3) In item's prefab - add a function that checks for player action and if its "Pick" and target of that action is a bush, grass tuft etc - degrades items uses by 1 each time player does that "pick" action.
4) Add a protection from spike damage while it equipped... (I never really got to that)
 
second one:
1) Add custom tag for things that'll be picked up fast with tool in hand
2) In item's perfab add a check for players action and if its pick action and its target is pickable and has custom tag - changes the character's stategraph ACTION.PICK from "dolongaction" to "doshortaction".
3) Lastly - add similar check for the item to be equipped, so that when it brakes or is unequipped - the pick action is "dolongaction" again.

 

third one:

1) Write a code that modifies all character's stategraphs,  more precisely - ActionHandler(ACTIONS.PICK section, to contain a check for equipped item in hand slot and an action target, resulting in a "doshortaction" if target and item are matching.

2) Same as first one 3) - In item's prefab - add a function that checks that target of that action is a bush, grass tuft etc, then if its true - degrades items uses by 1 each time player does "pick" action.
 

I tried making it work via AddStategraphPostInit and AddStategraphActionHandler containing new function for ActionHandler (ACTION.PICK but it always crashed and pointed on string number where the ACTION.PICK was mentioned... I am doing something wrong and I can't get what.

 

What frustrates me is that I know how it needs to be worked out, but have no friggin idea how to code it. I also tried looking up some mods that work with stategraphs and actions, but those mainly introduce completely new actions with tons of hard ass code and not one that modifies the existing ones.
 
If you have some time and samples for items that modify players actions when equpped or some pieces of code that might be useful (like the checks for equipped item), please send them my way.

Link to comment
Share on other sites

ACTIONS = GLOBAL.ACTIONS-- Replace "ATTACK" with whatever action you want to modify. See actions.lua.ACTIONS.ATTACK.fn = function(act)    -- Make use of act.doer, act.target, act.invobject, etc. See actions.lua    -- ...end

 

Will try to think of something with those, thanks :)

Link to comment
Share on other sites

I managed to adapt the code from "Slash Grass" mod to create two tools, that enable the character to harvest Grass\Twigs\Reeds using fast "pickup" animation instead of usual hand-fiddling one via adding new action "Collect", that is added to character's action table when right tool is in hand. The catch is that those tools do not lose durability when this action is done. Durability however decreases properly via "tool" component in item's prefab if the action is initiated with "action button" (spacebar). I am overlooking something in the code, that prevents durability loss when action is done via mouse cursor.

Could someone (@simplex, @Heavenfall, @Blueberrys) perhaps point me in the right direction? It'll be much appreciated if you have the time to look through it. The mod is in the archive attached.

Madman's Garden Tools.zip

Link to comment
Share on other sites

Still can't do anything about endless tool durability, so threadS up. How the tool component works properly decreasing durability if you do custom action with spacebar, but does not when you use cursor\mouse?

 

Any ideas and advice will be much appreciated.

Link to comment
Share on other sites

@Madman666 You could try calling FiniteUses:Use(1) to fix it. Or compare how your action works with the other tools' actions. It might have to do with the Collect_something_Actions in the corresponding components.

 

Yeah, I know about FiniteUses:Use(1), I just don't know how to  code it to apply every time collect action is done. It works fine when space bar is used to pick something like twigs - durability decreases properly - but if you use mouse - it does not. I tried comparing new action to chopping, mining, catching (with bugnet), fishing etc. - the answer is nowhere to be found... It looks right, but works wrong.

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