Soo i've been looking all over the net to find a solution on how to change durability of a tool.
I found this post that was posted may but have yet gotten an response: viewtopic.php?f=25&t=25199
Change durability of tools/items.
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Change durability of tools/items.
There's no way to have a recipe change durability of existing items, however you could have a recipe that takes an existing item (maybe plus some other stuff) and outputs a new item (that looks like the old item but with better durability).
So essentially you have recipe: old tool + iron plate = new tool
Then just define the new tool to be same as old one but better durability.
Code: Select all
-- in data.lua
data.extend {
{
type = "recipe",
name = "improved-tool",
enabled = false, -- assuming you want tech to enable it
energy_required = 10,
ingredients =
{
{"old-tool-name", 1}, -- change as applicable
{"iron-plate", 1}
},
result = "new-tool", -- change as applicable
}
}
Then just define the new tool to be same as old one but better durability.
Last edited by aubergine18 on Wed Sep 21, 2016 6:50 pm, edited 1 time in total.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Change durability of tools/items.
The other alternative is to create a technology that can be researched, then when the tech is researched scan all existing tools (in player/vehicle inventories, chests, etc) and replace with new tool, then somehow disable old tool recipe and enable the new tool recipe.
The technology prototype would be responsible for enabling the improved durability recipe.
Code: Select all
local function upgradeExistingTools( from, to, player )
-- code here to update all existing tools
-- to a new type of tool
-- for all players on the same force as player
end
local function disableOldRecipe( name, player )
player = game.players[player]
player.force.recipes[name].enabled = false
end
local function researchComplete( event )
if event.research.name = "your-tech-name" then
upgradeExistingTools( "old-tool-name", "new-tool-name", event.player_index )
disableOldRecipe( "old-recipe-name", event.player_index )
end
end
script.on_event( defines.events.on_research_finished, researchComplete )
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Re: Change durability of tools/items.
Thanks for the help! I guess i could use this work around.