Page 1 of 1

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

Posted: Mon Jul 28, 2025 4:06 pm
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!

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

Posted: Sun Aug 31, 2025 8:16 am
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)?

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

Posted: Sun Aug 31, 2025 2:41 pm
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.