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!
Post Reply

Return to “Questions, reviews and ratings”