Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.72 KB | None | 0 0
  1. local Event = require 'utils.event'
  2. local Game = require 'utils.game'
  3. local Command = require 'utils.command'
  4. local round = math.round
  5. local insert = table.insert
  6. local remove = table.remove
  7.  
  8. if global.config.market.enabled then
  9.     local new_items = {
  10.         {price = 5, name = 'construction-robot'},
  11.         {price = 15, name = 'logistic-robot'},
  12.         {price = 50, name = 'roboport'},
  13.         {price = 5, name = 'logistic-chest-passive-provider'},
  14.         {price = 5, name = 'logistic-chest-storage'},
  15.  
  16.     }
  17.     local market_items = require 'resources.market_items'
  18.  
  19.     for i = #market_items, 1, -1 do
  20.         local name = market_items[i].name
  21.         -- cleanup items we don't need, construction bot has to be replaced for convenience
  22.         if name == 'temporary-mining-speed-bonus' or name == 'construction-robot' or name == 'steel-axe' then
  23.             remove(market_items, i)
  24.         end
  25.     end
  26.  
  27.     for i = 1, #new_items do
  28.         insert(market_items, i, new_items[i])
  29.     end
  30. end
  31.  
  32.  
  33. -- disable pickaxes from the start
  34. Event.on_init(function ()
  35.     local recipes = game.forces.player.recipes
  36.     recipes['iron-axe'].enabled = false
  37.     recipes['steel-axe'].enabled = false
  38. end)
  39.  
  40. -- ensure the recipes are disabled all the time
  41. Event.add(defines.events.on_research_finished, function (event)
  42.     local recipes = event.research.force.recipes
  43.     recipes['iron-axe'].enabled = false
  44.     recipes['steel-axe'].enabled = false
  45. end)
  46.  
  47. -- players cannot build anything, just place ghosts
  48. Event.add(defines.events.on_built_entity, function(event)
  49.     local entity = event.created_entity
  50.     if not entity or not entity.valid then
  51.         return
  52.     end
  53.  
  54.     local name = entity.name
  55.  
  56.     if name == 'entity-ghost' then
  57.         return
  58.     end
  59.  
  60.     -- replace the entity by a ghost
  61.     local direction = entity.direction
  62.     local position = entity.position
  63.     local surface = entity.surface
  64.     local force = entity.force
  65.  
  66.     -- not every item has a ghost, this is the easiest way to prevent errors and stop replacement
  67.     pcall(function()
  68.         surface.create_entity({
  69.             name = 'entity-ghost',
  70.             inner_name = name,
  71.             direction = direction,
  72.             position = position,
  73.             force = force,
  74.         });
  75.         entity.destroy()
  76.  
  77.         -- attempt to give the item back to the player
  78.         local player = Game.get_player_by_index(event.player_index)
  79.         if not player or not player.valid then
  80.             return
  81.         end
  82.  
  83.         player.insert(event.stack)
  84.     end)
  85. end)
  86.  
  87. Command.add('lazy-bastard-bootstrap', {
  88.     description = 'Puts down the minimum requirements to get started',
  89.     admin_only = true,
  90. }, function(_, player)
  91.     local surface = player.surface
  92.     local force = player.force
  93.  
  94.     local pos = player.position
  95.     pos.y = round(pos.y - 4)
  96.     pos.x = round(pos.x)
  97.  
  98.     local bot_count = 3
  99.     local create_entity = surface.create_entity
  100.     local templates = {
  101.         {name = 'medium-electric-pole', force = force, position = {x = pos.x - 2, y = pos.y - 1}},
  102.         {name = 'roboport', force = force, position = {x = pos.x, y = pos.y}},
  103.         {name = 'solar-panel', force = force, position = {x = pos.x, y = pos.y}},
  104.         {name = 'logistic-chest-storage', force = force, position = {x = pos.x + 1, y = pos.y + 1}},
  105.         {name = 'logistic-chest-storage', force = force, position = {x = pos.x - 2, y = pos.y + 1}},
  106.     }
  107.  
  108.     for i = 1, #templates do
  109.         local entity = create_entity(templates[i])
  110.         entity.minable = false
  111.         entity.destructible = false
  112.     end
  113.  
  114.     for _ = 1, bot_count do
  115.         create_entity({name = 'construction-robot', force = force, position = pos})
  116.     end
  117. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement