Help Editing Mining Drill Prototype

Place to get help with not working mods / modding interface.
Post Reply
Malkasphia
Inserter
Inserter
Posts: 22
Joined: Wed Dec 18, 2013 4:18 am
Contact:

Help Editing Mining Drill Prototype

Post by Malkasphia »

Hey All,

What I am trying to do:
I am attempting to edit the Mining Drill Prototype to do the following :

1 - Become a container like a chest ( I have added the wooden chest prototype info from the entities.lua file for this)
2- To spawn coal,stone,iron ore, and copper ore inside of its inventory every 5 seconds. ( I have added a new function to busy-wait for 5 seconds and then insert the resources).

The problem I am having:
When I start Factorio, I am getting the error:

Image

Below is the code I edited for the burner-miner-drill prototype( my code in red)
I am a novice coder at best, so any help is greatly appreciated!



{
type = "mining-drill","container",
name = "burner-mining-drill",
icon = "__base__/graphics/icons/burner-mining-drill.png",
flags = {"placeable-neutral", "player-creation"},
resource_categories = {"basic-solid"},
minable = {mining_time = 1, result = "burner-mining-drill"},
max_health = 100,
corpse = "medium-remnants",
collision_box = {{ -0.9, -0.9}, {0.9, 0.9}},
selection_box = {{ -1, -1}, {1, 1}},
mining_speed = 0.35,
inventory_size = 16,
auto_mine = 1
local clock = os.clock
function sleep(n) -- seconds to sleep for auto_mine
local t0 = clock()
while clock() - t0 <= n do end
end
while auto_mine=1 do
sleep(5)
chest.insert({name="stone", count="1"})
chest.insert({name="copper-ore", count="1"})
chest.insert({name="iron-ore", count="1"})
chest.insert({name="coal", count="1"})
end
-- Mine Spawns resources every 5 seconds.

open_sound = { filename = "__base__/sound/wooden-chest-open.wav" },
close_sound = { filename = "__base__/sound/wooden-chest-close.wav" },
picture =
{
filename = "__base__/graphics/entity/wooden-chest/wooden-chest.png",
priority = "extra-high",
width = 46,
height = 33,
shift = {0.3, 0}
},

energy_source =
{
type = "burner",
effectivity = 1,
fuel_inventory_size = 1,
emissions = 0.1 / 3,
smoke =
{
{
name = "smoke",
deviation = {0.1, 0.1},
frequency = 1
}
}
},

energy_usage = "300kW",
mining_power = 2.5,
animations =
{
north =
{
priority = "extra-high",
frame_width = 110,
frame_height = 76,
line_length = 4,
shift = {0.7, -0.1},
filename = "__base__/graphics/entity/burner-mining-drill/north.png",
frame_count = 32,
animation_speed = 0.5,
run_mode = "forward-then-backward",
},
east =
{
priority = "extra-high",
frame_width = 94,
frame_height = 74,
line_length = 4,
shift = {0.45, -0.1},
filename = "__base__/graphics/entity/burner-mining-drill/east.png",
frame_count = 32,
animation_speed = 0.5,
run_mode = "forward-then-backward",
},
south =
{
priority = "extra-high",
frame_width = 89,
frame_height = 88,
line_length = 4,
shift = {0.4, 0},
filename = "__base__/graphics/entity/burner-mining-drill/south.png",
frame_count = 32,
animation_speed = 0.5,
run_mode = "forward-then-backward",
},
west =
{
priority = "extra-high",
frame_width = 91,
frame_height = 78,
line_length = 4,
shift = {0.1, -0.05},
filename = "__base__/graphics/entity/burner-mining-drill/west.png",
frame_count = 32,
animation_speed = 0.5,
run_mode = "forward-then-backward",
}
},
--resource_searching_radius = 0.99,
--vector_to_place_result = {-0.5, -1.3}
}

Normal Code Block for easy viewing:

Code: Select all

{
    type = "mining-drill","container",
    name = "burner-mining-drill",
    icon = "__base__/graphics/icons/burner-mining-drill.png",
    flags = {"placeable-neutral", "player-creation"},
    resource_categories = {"basic-solid"},
    minable = {mining_time = 1, result = "burner-mining-drill"},
    max_health = 100,
    corpse = "medium-remnants",
    collision_box = {{ -0.9, -0.9}, {0.9, 0.9}},
    selection_box = {{ -1, -1}, {1, 1}},
    mining_speed = 0.35,
	inventory_size = 16,
	auto_mine = 1 
	local clock = os.clock
	function sleep(n)  -- seconds to sleep for auto_mine
		local t0 = clock()
		while clock() - t0 <= n do end
	end
	while auto_mine=1 do
		sleep(5)
		chest.insert({name="stone", count="1"})
		chest.insert({name="copper-ore", count="1"})
		chest.insert({name="iron-ore", count="1"})
		chest.insert({name="coal", count="1"})
	end
		-- Mine Spawns resources every 5 seconds.
    open_sound = { filename = "__base__/sound/wooden-chest-open.wav" },
    close_sound = { filename = "__base__/sound/wooden-chest-close.wav" },
    picture =
    {
      filename = "__base__/graphics/entity/wooden-chest/wooden-chest.png",
      priority = "extra-high",
      width = 46,
      height = 33,
      shift = {0.3, 0}
    },
    energy_source =
    {
      type = "burner",
      effectivity = 1,
      fuel_inventory_size = 1,
      emissions = 0.1 / 3,
      smoke =
      {
        {
          name = "smoke",
          deviation = {0.1, 0.1},
          frequency = 1
        }
      }
    },
	
    energy_usage = "300kW",
    mining_power = 2.5,
    animations =
    {
      north =
      {
        priority = "extra-high",
        frame_width = 110,
        frame_height = 76,
        line_length = 4,
        shift = {0.7, -0.1},
        filename = "__base__/graphics/entity/burner-mining-drill/north.png",
        frame_count = 32,
        animation_speed = 0.5,
        run_mode = "forward-then-backward",
      },
      east =
      {
        priority = "extra-high",
        frame_width = 94,
        frame_height = 74,
        line_length = 4,
        shift = {0.45, -0.1},
        filename = "__base__/graphics/entity/burner-mining-drill/east.png",
        frame_count = 32,
        animation_speed = 0.5,
        run_mode = "forward-then-backward",
      },
      south =
      {
        priority = "extra-high",
        frame_width = 89,
        frame_height = 88,
        line_length = 4,
        shift = {0.4, 0},
        filename = "__base__/graphics/entity/burner-mining-drill/south.png",
        frame_count = 32,
        animation_speed = 0.5,
        run_mode = "forward-then-backward",
      },
      west =
      {
        priority = "extra-high",
        frame_width = 91,
        frame_height = 78,
        line_length = 4,
        shift = {0.1, -0.05},
        filename = "__base__/graphics/entity/burner-mining-drill/west.png",
        frame_count = 32,
        animation_speed = 0.5,
        run_mode = "forward-then-backward",
      }
    },
    --resource_searching_radius = 0.99,
    --vector_to_place_result = {-0.5, -1.3}
  }
}

FishSandwich
Smart Inserter
Smart Inserter
Posts: 1847
Joined: Sun Feb 23, 2014 3:37 pm
Contact:

Re: Help Editing Mining Drill Prototype

Post by FishSandwich »

I think it's because you're missing commas at the end of a lot of your lines. I'm not 100% sure, I know a little bit of c#, and this makes sense to me, but I could be way off.

Malkasphia
Inserter
Inserter
Posts: 22
Joined: Wed Dec 18, 2013 4:18 am
Contact:

Re: Help Editing Mining Drill Prototype

Post by Malkasphia »

Thanks for the suggestion Fish but I added commas to separate the variables and then the function and while loop but it was a no go.

The prototype is a lua table, which should be able to accept the function and while loop...It just wants me to close off the table before I can put in the additional code. I feel like I am missing something obvious here...but I just don't know enough to put my finger on it hehe.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Help Editing Mining Drill Prototype

Post by FreeER »

The error message is saying that there is a missing '}' at line 99 (or more likely 98 since the interpreter would have moved to the next line in an attempt to find it and then encountered an 'illegal' token). I don't see an error there in what you posted, so I'm going to guess that it's not the full file, however there is a more important issue... You can't add multiple types to a single entity, nor can you add functionality through the prototypes like the clock (and some lua libraries are not reachable, like io and I believe os, for security reasons). It would be nice if that was possible though :)

It can, however, be done by creating a regular container entity and using control.lua to insert the resources.
Oh, and if you want to overwrite the burner-mining-drill then you should use this in a mod's data.lua (obviously change sounds, graphics etc.).

Code: Select all

data.raw["mining-drill"]["burner-mining-drill"]={
    type = "container",
    name = "burner-mining-drill",
    icon = "__base__/graphics/icons/wooden-chest.png",
    flags = {"placeable-neutral", "player-creation"},
    minable = {mining_time = 1, result = "burner-mining-drill"},
    max_health = 50,
    corpse = "small-remnants",
    collision_box = {{-0.35, -0.35}, {0.35, 0.35}},
    fast_replaceable_group = "container",
    selection_box = {{-0.5, -0.5}, {0.5, 0.5}},
    inventory_size = 16,
    open_sound = { filename = "__base__/sound/wooden-chest-open.ogg" },
    close_sound = { filename = "__base__/sound/wooden-chest-close.ogg" },
    picture =
    {
      filename = "__base__/graphics/entity/wooden-chest/wooden-chest.png",
      priority = "extra-high",
      width = 46,
      height = 33,
      shift = {0.3, 0}
    }
  }
The control.lua code

Code: Select all

require "defines" -- require a file with event definitions

possibleInserts = { -- list of resources (in itemstack form) that can be inserted
  {name="iron-ore", count=1},
  {name="copper-ore", count=1}
}

game.oninit(function()
  -- create a table to store drills in when mod is added to a save (or a new game), only the glob is saved/loaded with saves
  glob.drills = {}
end)

game.onevent(defines.events.onbuiltentity, function(event)
  -- watch for drills, note this will not work when built by construction robots
  if event.createdentity.name == "burner-mining-drill" then
    table.insert(glob.drills, event.createdentity) -- insert the drill into the table, could also use glob.drills[#glob.drills] = event.createdentity
  end
end)

game.onevent(defines.events.ontick, function(event)
  if event.tick % (60 * 5) == 0 then -- every 5 seconds (there are 60 ticks per second)
    -- insert resources
    for i, drill in ipairs(glob.drills) do -- for every entry in the table, with i = the index and drill = the value
      if drill.valid then -- if the drill hasn't been mined or destroyed
        drill.insert(possibleInserts[math.random(1, #possibleInserts)] -- insert a random resource, #possibleInserts may need to be #possibleInserts+1
      else
        table.remove(glob.drills, i) -- this is potentially problematic if you remove more than 1 drill in a loop.
      end
    end
  end
end)
now obviously your code wasn't doing it randomly, but I thought I'd go ahead and show that :)
I should probably note that I haven't tested this code, but it should either work or only be off by syntax errors (of course, that's the reason you posted...lol).

PS. I am ever so thankful for the firefox Form History plugin right now :) (accidentally closed the tab and lost this post).

Malkasphia
Inserter
Inserter
Posts: 22
Joined: Wed Dec 18, 2013 4:18 am
Contact:

Re: Help Editing Mining Drill Prototype

Post by Malkasphia »

Wow FreeER,

Thank you very much. And thank you firefox Form History plugin!

You answered all of my questions and then some. BTW, I loved your modding tutorial on the wiki for your bomber, that was a great start for me.

So then, I got some testing to do and will get back to you if I got it all working as planned :)

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Help Editing Mining Drill Prototype

Post by FreeER »

Malkasphia wrote:Thank you very much
You are entirely welcome :)
After you get it working you might want to look at this as a way of detecting when bots build entities, or more directly the Extra Utilities github. It's not officially released, but if you have some experience coding (I had practically none before I started with Factorio by the way) you should get an idea or two.

Oh, and don't forget to thank jeroon if you get the chance for updating the wiki tutorial to a more 'modern' version of Factorio :P

User avatar
semvoz
Inserter
Inserter
Posts: 30
Joined: Wed Jun 17, 2015 12:03 pm
Contact:

Re: Help Editing Mining Drill Prototype

Post by semvoz »

FreeER wrote:the clock (and some lua libraries are not reachable, like io and I believe os, for security reasons). It would be nice if that was possible though :)
So, does that mean there's no way to keep track of the time at all? (unless maybe counting ticks?)

Post Reply

Return to “Modding help”