Change durability of tools/items.

Place to get help with not working mods / modding interface.
Post Reply
Wiloxe
Burner Inserter
Burner Inserter
Posts: 14
Joined: Fri Jun 05, 2015 10:00 am
Contact:

Change durability of tools/items.

Post 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

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Change durability of tools/items.

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

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Change durability of tools/items.

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

Wiloxe
Burner Inserter
Burner Inserter
Posts: 14
Joined: Fri Jun 05, 2015 10:00 am
Contact:

Re: Change durability of tools/items.

Post by Wiloxe »

Thanks for the help! I guess i could use this work around.

Post Reply

Return to “Modding help”