Code: Select all
require "util"
require "defines"
game.oninit = function()
end
game.onevent = function(event)
--[[------------------Underground mining drill stuff------------------]]--
local randomResources={"coal", "coal", "coal","iron-ore","iron-ore","copper-ore","copper-ore","stone","stone","stone","stone","coal", "coal", "coal","iron-ore","iron-ore","copper-ore","copper-ore","stone","stone","stone","stone","stone","stone","stone","stone","gold-ore","silver-ore"}
if event.name == "onplayermineditem" and event.itemstack.name=="underground-mining-drill" then
glob.undergroundMinerPos[#glob.undergroundMinerPos].active=false
end
if event.name == "onbuiltentity" and event.createdentity.name=="underground-mining-drill" then
local bModified
for _,fieldValue in pairs(glob.undergroundMinerPos) do
if event.createdentity.position.x==fieldValue.x and event.createdentity.position.y==fieldValue.y then
fieldValue.active="true"
bModified=true
break
end
end
if not bModified then
local fieldName=#glob.undergroundMinerPos+1
glob.undergroundMinerPos[fieldName]={}
glob.undergroundMinerPos[fieldName].entity = event.createdentity
glob.undergroundMinerPos[fieldName].active="true"
if glob.undergroundMinerPos[fieldName].resource~="iron-ore" or glob.undergroundMinerPos[fieldName].resource~="coal" or glob.undergroundMinerPos[fieldName].resource~="stone" or glob.undergroundMinerPos[fieldName].resource~="copper-ore" or glob.undergroundMinerPos[fieldName].resource~="silver-ore" or glob.undergroundMinerPos[fieldName].resource~="gold-ore" then
glob.undergroundMinerPos[fieldName].resource=randomResources[math.random(1,#randomResources)]
glob.undergroundMinerPos[fieldName].resourcevalue=math.random(1,5)
end
glob.undergroundMinerPos[fieldName].position={}
glob.undergroundMinerPos[fieldName].position.x=event.createdentity.position.x
glob.undergroundMinerPos[fieldName].position.y=event.createdentity.position.y
glob.undergroundMinerPos[fieldName].name="underground-mining-drill"
end
end
if event.name == "ontick" then
for fieldName, _ in pairs(glob.undergroundMinerPos) do
if glob.undergroundMinerPos[fieldName].entity.isvalid() then
uminingdrill=glob.undergroundMinerPos[fieldName].entity.getinventory(defines.inventory.chest)
if math.random(130)==80 then
randomnumber2=math.random(1,glob.undergroundMinerPos[fieldName].resourcevalue)
if uminingdrill.isvalid() and uminingdrill.caninsert({name=(glob.undergroundMinerPos[fieldName].resource), count=(randomnumber2)}) then
uminingdrill.insert({name=(glob.undergroundMinerPos[fieldName].resource), count=(randomnumber2)})
end
end
end
end
end
if event.name == "onbuiltentity" and event.createdentity.name=="underground-scanner" then
for fieldName, v in ipairs(glob.undergroundMinerPos) do
local canbescanned={}
if event.createdentity.position.x==v.position.x and event.createdentity.position.y==v.position.y then
game.getplayer().print("The scanner has found "..glob.undergroundMinerPos[fieldName].resource.." in this zone, and the richness is "..glob.undergroundMinerPos[fieldName].resourcevalue)
canbescanned={fieldName=true}
break
end
if canbescanned[fieldname]==nil then
game.getplayer().print("The zone has not been drilled, the scanner will not work")
end
end
end
--[[-------------------------------End :)------------------------------]]--
function cheat(n,a)
if a == nil then
game.getplayer().insert{name=n,count=5}
else
game.getplayer().insert{name=n,count=a}
end
end