Page 1 of 1
Change durability of tools/items.
Posted: Wed Sep 21, 2016 5:56 pm
by Wiloxe
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
Re: Change durability of tools/items.
Posted: Wed Sep 21, 2016 6:32 pm
by aubergine18
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).
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
}
}
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.
Re: Change durability of tools/items.
Posted: Wed Sep 21, 2016 6:40 pm
by aubergine18
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.
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 )
The technology prototype would be responsible for enabling the improved durability recipe.
Re: Change durability of tools/items.
Posted: Fri Sep 23, 2016 11:55 am
by Wiloxe
Thanks for the help! I guess i could use this work around.