Old mod does not work anymore, can someone help me?

Looking for a mod? Have a review on a mod you'd like to share?
MrFactorio
Inserter
Inserter
Posts: 31
Joined: Tue Nov 13, 2018 4:50 pm
Contact:

Old mod does not work anymore, can someone help me?

Post by MrFactorio »

Hi,

I liked the old mod Repair to start where every building that has been placed started with 1 HP, so you needed to repair them first to make them work. But now with 2.0 or so the mod does not work anymore.

Is there a similar mod or can someone fix the script for me?
Error:
Error while running event RepairToStart::on_built_entity (ID 6)...

Code: Select all

script.on_event(defines.events.on_player_created, function(event)
  local player = game.players[event.player_index]
  -- log ('Added items to player '..player.name)
  player.insert{name="repair-pack", count=50}
end)

script.on_init(function()
  if not global then global = {} end
  if not global.entities then global.entities = {} end
  global.empty_table = true
end)

function on_build_handler (entity)
  if (entity.prototype.has_flag("not-repairable")) then
    return
  end
  entity.health = 1
  entity.active = false
  table.insert (global.entities, entity)
  global.empty_table = false
end

script.on_event(defines.events.on_built_entity, function(event)
  on_build_handler (event.created_entity)
end)

script.on_event(defines.events.on_robot_built_entity, function(event)
  on_build_handler (event.created_entity)
end)

script.on_event(defines.events.on_tick, function(event)
  if global.empty_table then return end
  for i, entity in pairs (global.entities) do
    if (not entity.valid) then 
      table.remove(global.entities, i)
      return
    end
    
    if entity.health and entity.health == entity.prototype.max_health then
      entity.active = true
      table.remove(global.entities, i)
      return
    end
  end
  if #global.entities == 0 then 
    global.empty_table = true 
  end
end)
Thank you very much!
User avatar
garrotte
Burner Inserter
Burner Inserter
Posts: 19
Joined: Tue Mar 10, 2020 5:10 pm
Contact:

Re: Old mod does not work anymore, can someone help me?

Post by garrotte »

Hello,
Can do if you still need it.
Is your plan to research first several techs with all your buildings deactivated (no smelting ore, no automated mining... how to get first dozens units of red science)? Probably you need some repair kits or even early bots too for a start.
There is a mod Building_Time. Did you try it (also before Factorio2.0 release)?
Pi-C
Smart Inserter
Smart Inserter
Posts: 1770
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Old mod does not work anymore, can someone help me?

Post by Pi-C »

MrFactorio wrote: Mon Jul 28, 2025 4:06 pm
Is there a similar mod or can someone fix the script for me?
Error:
Error while running event RepairToStart::on_built_entity (ID 6)...
Too bad you've left out the actual error message! But after taking a quick glance (without actually trying to run this), it seems all you need to do to get it working again is replacing 'global' with 'storage' everywhere in the file.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Post Reply

Return to “Questions, reviews and ratings”