Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
restrictive_fluid_mining > bot mining addition
Browse files Browse the repository at this point in the history
  • Loading branch information
MewMew committed Dec 25, 2018
1 parent a94c8e9 commit 3712117
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions maps/modules/restrictive_fluid_mining.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ local message_color = {r = 255, g = 150, b = 0}

local max_fill_percentages = {
["storage-tank"] = 0.1,
["pipe"] = 0.25
["pipe"] = 0.25,
["pipe-to-ground"] = 0.25
}

local function on_player_mined_entity(event)
local function restrict_fluid_mining(event)
if not max_fill_percentages[event.entity.type] then return end
if not event.entity.fluidbox[1] then return end
if not event.entity.fluidbox then return end

local total_capacity = 0
local total_current_fluid_amount = 0


for i = 1, #event.entity.fluidbox, 1 do
if event.entity.fluidbox[i] then
local capacity = event.entity.fluidbox.get_capacity(i)
Expand All @@ -29,7 +29,7 @@ local function on_player_mined_entity(event)
end

if total_capacity == 0 or total_current_fluid_amount == 0 then return end

local fill_percentage = total_current_fluid_amount / total_capacity

if fill_percentage < max_fill_percentages[event.entity.type] then return end
Expand All @@ -39,9 +39,10 @@ local function on_player_mined_entity(event)
local replacement_entity = event.entity.surface.create_entity({
name = event.entity.name,
force = event.entity.force,
position = event.entity.position,
position = event.entity.position,
direction = event.entity.direction
})
replacement_entity.health = event.entity.health

local fluid_name = "fluid"
local container_name = event.entity.name
Expand All @@ -53,16 +54,24 @@ local function on_player_mined_entity(event)
end
end

if not event.player_index then return end

local messages = {
"Mining this " .. container_name .. " would cause a terrible mess.",
"You don´t want to spill all the " .. fluid_name .. ".",
"There is too much " .. fluid_name .. " in the " .. container_name .. " to dismantle it safely."
}

}
local player = game.players[event.player_index]
player.print(messages[math_random(1, #messages)], message_color)
end

--/c x = game.player.surface.create_entity({name = "storage-tank", position = {0, -10}, force = "player"}) x.fluidbox[1] = {name = "light-oil", amount = 25000}

local function on_player_mined_entity(event)
restrict_fluid_mining(event)
end

local function on_robot_mined_entity(event)
restrict_fluid_mining(event)
end

event.add(defines.events.on_robot_mined_entity, on_robot_mined_entity)
event.add(defines.events.on_player_mined_entity, on_player_mined_entity)

0 comments on commit 3712117

Please sign in to comment.