mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-29 20:16:38 +09:00
Added remaing modules
This commit is contained in:
126
modules/SpawnArea/control.lua
Normal file
126
modules/SpawnArea/control.lua
Normal file
@@ -0,0 +1,126 @@
|
||||
--- Creates a safe spawn area with chests and auto refilling turrets.
|
||||
-- @module SpawnArea@4.0.0
|
||||
-- @author Cooldude2606
|
||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||
-- @alais ThisModule
|
||||
|
||||
-- Module Require
|
||||
local Game = require('FactorioStdLib.Game@^0.8.0')
|
||||
|
||||
-- Local Varibles
|
||||
local turret_enabled = true
|
||||
local turret_ammo = 'uranium-rounds-magazine'
|
||||
|
||||
local tile_positions = require(module_path..'/src/spawn_tiles')
|
||||
local entity_positions = require(module_path..'/src/spawn_entities')
|
||||
|
||||
local global_offset = {x=0,y=-2}
|
||||
local decon_radius = 20
|
||||
local decon_tile = 'concrete'
|
||||
local partern_radius = 50
|
||||
local partern_tile = 'stone-path'
|
||||
|
||||
-- Module Define
|
||||
local module_verbose = false
|
||||
local ThisModule = {}
|
||||
|
||||
-- Global Define
|
||||
-- location of auto refill turrets
|
||||
local global = global{
|
||||
{1,-3,-3},
|
||||
{1,-3,3},
|
||||
{1,3,-3},
|
||||
{1,3,3}
|
||||
}
|
||||
|
||||
-- Function Define
|
||||
function ThisModule.afk_belt(surface,offset)
|
||||
local belts = {{-0.5,-0.5,2},{0.5,-0.5,4},{-0.5,0.5,0},{0.5,0.5,6}}
|
||||
for _,pos in pairs(belts) do
|
||||
local position = {pos[1]+offset[1],pos[2]+offset[2]}
|
||||
local belt = surface.create_entity{name='transport-belt',position=position,force='neutral',direction=pos[3]}
|
||||
belt.destructible = false; belt.health = 0; belt.minable = false; belt.rotatable = false
|
||||
end
|
||||
end
|
||||
|
||||
function ThisModule.auto_turret(surface,pos)
|
||||
if not turret_enabled then error('Auto Turrets are disabled.') end
|
||||
-- adds a new turrent to the global list, returns index
|
||||
local _return
|
||||
if surface then
|
||||
local surface = Game.get_surface(surface)
|
||||
if not surface then error('Surface is not valid.') end
|
||||
local posx = pos.x or pos[1] or error('Position is not valid.')
|
||||
local posy = pos.y or pos[2] or error('Position is not valid.')
|
||||
_return = table.insert(global,{surface.index,posx,posy})
|
||||
end
|
||||
-- spawns turrets and refills them
|
||||
if not game.forces['spawn'] then game.create_force('spawn').set_cease_fire('player',true) game.forces['player'].set_cease_fire('spawn',true) end
|
||||
for _,pos in pairs(global) do
|
||||
local surface = game.surfaces[pos[1]]
|
||||
local turret = surface.find_entity('gun-turret',{pos[2],pos[3]})
|
||||
if not turret then
|
||||
turret = surface.create_entity{name='gun-turret',position={pos[2],pos[3]},force='spawn'}
|
||||
turret.destructible = false; turret.health = 0; turret.minable = false; turret.rotatable = false; turret.operable = false; turret.health = 0
|
||||
end
|
||||
if turret.get_inventory(defines.inventory.turret_ammo).can_insert{name=turret_ammo,count=10} then
|
||||
turret.get_inventory(defines.inventory.turret_ammo).insert{name=turret_ammo,count=10}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Event Handlers Define
|
||||
if turret_enabled then
|
||||
script.on_event(defines.events.on_tick,function(event)
|
||||
if event.tick % 3600 then
|
||||
ThisModule.auto_turret()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
script.on_event(defines.events.on_player_created, function(event)
|
||||
if event.player_index == 1 then
|
||||
local player = Game.get_player(event)
|
||||
local surface = player.surface
|
||||
local offset = {x=0,y=0}
|
||||
local partern_base_tile = surface.get_tile(player.position).name
|
||||
if partern_base_tile == 'deepwater' or partern_base_tile == 'water' then partern_base_tile = 'grass-1' end
|
||||
local base_tiles = {}
|
||||
local tiles = {}
|
||||
-- generates a safe area of land and removes all entites
|
||||
for x = -partern_radius, partern_radius do
|
||||
for y = -partern_radius, partern_radius do
|
||||
if x^2+y^2 < decon_radius^2 then
|
||||
table.insert(base_tiles,{name=decon_tile,position={x+offset.x,y+offset.y}})
|
||||
local entities = surface.find_entities_filtered{area={{x+offset.x-1,y+offset.y-1},{x+offset.x,y+offset.y}}}
|
||||
for _,entity in pairs(entities) do if entity.name ~= 'player' then entity.destroy() end end
|
||||
elseif x^2+y^2 < partern_radius^2 then
|
||||
table.insert(base_tiles,{name=partern_base_tile,position={x+offset.x,y+offset.y}})
|
||||
end
|
||||
end
|
||||
end
|
||||
surface.set_tiles(base_tiles)
|
||||
-- creates the partern in the spawn
|
||||
for _,position in pairs(tile_positions) do
|
||||
table.insert(tiles,{name=partern_tile,position={position[1]+offset.x+global_offset.x,position[2]+offset.y+global_offset.y}})
|
||||
end
|
||||
surface.set_tiles(tiles)
|
||||
-- spawns all the entites in spawn
|
||||
for _,entity in pairs(entity_positions) do
|
||||
local entity = surface.create_entity{name=entity[1],position={entity[2]+offset.x+global_offset.x,entity[3]+offset.y+global_offset.y},force='neutral'}
|
||||
entity.destructible = false; entity.health = 0; entity.minable = false; entity.rotatable = false
|
||||
end
|
||||
-- generates spawn turrents and afk belts
|
||||
if turret_enabled then ThisModule.auto_turret() end
|
||||
ThisModule.afk_belt(surface,{offset.x-5,offset.y-5})
|
||||
ThisModule.afk_belt(surface,{offset.x+5,offset.y-5})
|
||||
ThisModule.afk_belt(surface,{offset.x-5,offset.y+5})
|
||||
ThisModule.afk_belt(surface,{offset.x+5,offset.y+5})
|
||||
-- sets the spawn and moves the first player there
|
||||
player.force.set_spawn_position(offset,surface)
|
||||
player.teleport(offset,surface)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Module Return
|
||||
return ThisModule
|
||||
17
modules/SpawnArea/softmod.json
Normal file
17
modules/SpawnArea/softmod.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "SpawnArea",
|
||||
"version": "4.0.0",
|
||||
"type": "Module",
|
||||
"description": "Creates a safe spawn area with chests and auto refilling turrets.",
|
||||
"location": "<blank>",
|
||||
"keywords": [
|
||||
"Spawn",
|
||||
"Safe",
|
||||
"Turrets",
|
||||
"Auto Refill"
|
||||
],
|
||||
"author": "Cooldude2606",
|
||||
"contact": "Discord: Cooldude2606#5241",
|
||||
"license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE",
|
||||
"dependencies": {}
|
||||
}
|
||||
16
modules/SpawnArea/src/spawn_entities.lua
Normal file
16
modules/SpawnArea/src/spawn_entities.lua
Normal file
@@ -0,0 +1,16 @@
|
||||
return {
|
||||
{"stone-wall",-10,-6},{"stone-wall",-10,-5},{"stone-wall",-10,-4},{"stone-wall",-10,-3},{"stone-wall",-10,-2},{"stone-wall",-10,-1},{"stone-wall",-10,0},{"stone-wall",-10,3},{"stone-wall",-10,4},{"stone-wall",-10,5},
|
||||
{"stone-wall",-10,6},{"stone-wall",-10,7},{"stone-wall",-10,8},{"stone-wall",-10,9},{"stone-wall",-8,-8},{"small-lamp",-8,-4},{"small-lamp",-8,-1},{"iron-chest",-8,0},{"iron-chest",-8,3},{"small-lamp",-8,4},
|
||||
{"small-lamp",-8,7},{"stone-wall",-8,11},{"stone-wall",-7,-8},{"small-electric-pole",-7,-2},{"iron-chest",-7,0},{"iron-chest",-7,3},{"small-electric-pole",-7,5},{"stone-wall",-7,11},{"stone-wall",-6,-8},{"small-lamp",-6,-6},
|
||||
{"iron-chest",-6,0},{"iron-chest",-6,3},{"small-lamp",-6,9},{"stone-wall",-6,11},{"stone-wall",-5,-8},{"small-lamp",-5,-1},{"iron-chest",-5,0},{"iron-chest",-5,3},{"small-lamp",-5,4},{"stone-wall",-5,11},
|
||||
{"stone-wall",-4,-8},{"small-electric-pole",-4,-5},{"iron-chest",-4,0},{"iron-chest",-4,3},{"small-electric-pole",-4,8},{"stone-wall",-4,11},{"stone-wall",-3,-8},{"small-lamp",-3,-6},{"small-lamp",-3,-3},{"small-lamp",-3,6},
|
||||
{"small-lamp",-3,9},{"stone-wall",-3,11},{"stone-wall",-2,-8},{"iron-chest",-2,-6},{"iron-chest",-2,-5},{"iron-chest",-2,-4},{"iron-chest",-2,-3},{"iron-chest",-2,-2},{"iron-chest",-2,5},{"iron-chest",-2,6},
|
||||
{"iron-chest",-2,7},{"iron-chest",-2,8},{"iron-chest",-2,9},{"stone-wall",-2,11},{"stone-wall",1,-8},{"iron-chest",1,-6},
|
||||
{"iron-chest",1,-5},{"iron-chest",1,-4},{"iron-chest",1,-3},{"iron-chest",1,-2},{"iron-chest",1,5},{"iron-chest",1,6},{"iron-chest",1,7},{"iron-chest",1,8},{"iron-chest",1,9},{"stone-wall",1,11},
|
||||
{"stone-wall",2,-8},{"small-lamp",2,-6},{"small-lamp",2,-3},{"small-lamp",2,6},{"small-lamp",2,9},{"stone-wall",2,11},{"stone-wall",3,-8},{"small-electric-pole",3,-5},{"iron-chest",3,0},{"iron-chest",3,3},
|
||||
{"small-electric-pole",3,8},{"stone-wall",3,11},{"stone-wall",4,-8},{"small-lamp",4,-1},{"iron-chest",4,0},{"iron-chest",4,3},{"small-lamp",4,4},{"stone-wall",4,11},{"stone-wall",5,-8},{"small-lamp",5,-6},
|
||||
{"iron-chest",5,0},{"iron-chest",5,3},{"small-lamp",5,9},{"stone-wall",5,11},{"stone-wall",6,-8},{"small-electric-pole",6,-2},{"iron-chest",6,0},{"iron-chest",6,3},{"small-electric-pole",6,5},{"stone-wall",6,11},
|
||||
{"stone-wall",7,-8},{"small-lamp",7,-4},{"small-lamp",7,-1},{"iron-chest",7,0},{"iron-chest",7,3},{"small-lamp",7,4},{"small-lamp",7,7},{"stone-wall",7,11},{"stone-wall",9,-6},{"stone-wall",9,-5},
|
||||
{"stone-wall",9,-4},{"stone-wall",9,-3},{"stone-wall",9,-2},{"stone-wall",9,-1},{"stone-wall",9,0},{"stone-wall",9,3},{"stone-wall",9,4},{"stone-wall",9,5},{"stone-wall",9,6},{"stone-wall",9,7},
|
||||
{"stone-wall",9,8},{"stone-wall",9,9}
|
||||
}
|
||||
@@ -1,13 +1,4 @@
|
||||
|
||||
-- made by cooldude - this makes a spawn area and auto refill turents to protect the afk people, idk what it is at this point, but feel ffree to try and make it yours
|
||||
|
||||
--[[
|
||||
note for positions
|
||||
{-1,-1} {0,-1} {1,-1}
|
||||
{-1,0} {0,0} {1,0}
|
||||
{-1,1} {0,1} {1,1}
|
||||
--]]
|
||||
local tile_positions = {
|
||||
return {
|
||||
{-49,-3},{-49,-2},{-49,1},{-49,2},{-49,5},{-49,6},{-48,-4},{-48,-3},{-48,-2},{-48,1},{-48,2},{-48,5},{-48,6},{-48,7},{-47,-7},{-47,-6},{-47,-5},{-47,-4},{-47,-3},{-47,-2},{-47,5},{-47,6},{-47,7},{-47,8},{-47,9},{-47,10},{-46,-8},{-46,-7},{-46,-6},{-46,-5},
|
||||
{-46,-4},{-46,-3},{-46,-2},{-46,-1},{-46,4},{-46,5},{-46,6},{-46,7},{-46,8},{-46,9},{-46,10},{-46,11},{-45,-17},{-45,-16},{-45,-15},{-45,-14},{-45,-13},{-45,-12},{-45,-9},{-45,-8},{-45,-7},{-45,-2},{-45,-1},{-45,0},{-45,1},{-45,2},{-45,3},{-45,4},{-45,5},{-45,10},
|
||||
{-45,11},{-45,12},{-45,15},{-45,16},{-45,17},{-45,18},{-45,19},{-45,20},{-44,-18},{-44,-17},{-44,-16},{-44,-15},{-44,-14},{-44,-13},{-44,-12},{-44,-9},{-44,-8},{-44,-1},{-44,0},{-44,1},{-44,2},{-44,3},{-44,4},{-44,11},{-44,12},{-44,15},{-44,16},{-44,17},{-44,18},{-44,19},
|
||||
@@ -115,99 +106,4 @@ local tile_positions = {
|
||||
{43,12},{43,15},{43,16},{43,17},{43,18},{43,19},{43,20},{43,21},{44,-17},{44,-16},{44,-15},{44,-14},{44,-13},{44,-12},{44,-9},{44,-8},{44,-7},{44,-2},{44,-1},{44,0},{44,1},{44,2},{44,3},{44,4},{44,5},{44,10},{44,11},{44,12},{44,15},{44,16},
|
||||
{44,17},{44,18},{44,19},{44,20},{45,-8},{45,-7},{45,-6},{45,-5},{45,-4},{45,-3},{45,-2},{45,-1},{45,4},{45,5},{45,6},{45,7},{45,8},{45,9},{45,10},{45,11},{46,-7},{46,-6},{46,-5},{46,-4},{46,-3},{46,-2},{46,5},{46,6},{46,7},{46,8},
|
||||
{46,9},{46,10},{47,-4},{47,-3},{47,-2},{47,1},{47,2},{47,5},{47,6},{47,7},{48,-3},{48,-2},{48,1},{48,2},{48,5},{48,6}
|
||||
}
|
||||
|
||||
local entitys = {
|
||||
{"stone-wall",-10,-6},{"stone-wall",-10,-5},{"stone-wall",-10,-4},{"stone-wall",-10,-3},{"stone-wall",-10,-2},{"stone-wall",-10,-1},{"stone-wall",-10,0},{"stone-wall",-10,3},{"stone-wall",-10,4},{"stone-wall",-10,5},
|
||||
{"stone-wall",-10,6},{"stone-wall",-10,7},{"stone-wall",-10,8},{"stone-wall",-10,9},{"stone-wall",-8,-8},{"small-lamp",-8,-4},{"small-lamp",-8,-1},{"iron-chest",-8,0},{"iron-chest",-8,3},{"small-lamp",-8,4},
|
||||
{"small-lamp",-8,7},{"stone-wall",-8,11},{"stone-wall",-7,-8},{"small-electric-pole",-7,-2},{"iron-chest",-7,0},{"iron-chest",-7,3},{"small-electric-pole",-7,5},{"stone-wall",-7,11},{"stone-wall",-6,-8},{"small-lamp",-6,-6},
|
||||
{"iron-chest",-6,0},{"iron-chest",-6,3},{"small-lamp",-6,9},{"stone-wall",-6,11},{"stone-wall",-5,-8},{"small-lamp",-5,-1},{"iron-chest",-5,0},{"iron-chest",-5,3},{"small-lamp",-5,4},{"stone-wall",-5,11},
|
||||
{"stone-wall",-4,-8},{"small-electric-pole",-4,-5},{"iron-chest",-4,0},{"iron-chest",-4,3},{"small-electric-pole",-4,8},{"stone-wall",-4,11},{"stone-wall",-3,-8},{"small-lamp",-3,-6},{"small-lamp",-3,-3},{"small-lamp",-3,6},
|
||||
{"small-lamp",-3,9},{"stone-wall",-3,11},{"stone-wall",-2,-8},{"iron-chest",-2,-6},{"iron-chest",-2,-5},{"iron-chest",-2,-4},{"iron-chest",-2,-3},{"iron-chest",-2,-2},{"iron-chest",-2,5},{"iron-chest",-2,6},
|
||||
{"iron-chest",-2,7},{"iron-chest",-2,8},{"iron-chest",-2,9},{"stone-wall",-2,11},{"stone-wall",1,-8},{"iron-chest",1,-6},
|
||||
{"iron-chest",1,-5},{"iron-chest",1,-4},{"iron-chest",1,-3},{"iron-chest",1,-2},{"iron-chest",1,5},{"iron-chest",1,6},{"iron-chest",1,7},{"iron-chest",1,8},{"iron-chest",1,9},{"stone-wall",1,11},
|
||||
{"stone-wall",2,-8},{"small-lamp",2,-6},{"small-lamp",2,-3},{"small-lamp",2,6},{"small-lamp",2,9},{"stone-wall",2,11},{"stone-wall",3,-8},{"small-electric-pole",3,-5},{"iron-chest",3,0},{"iron-chest",3,3},
|
||||
{"small-electric-pole",3,8},{"stone-wall",3,11},{"stone-wall",4,-8},{"small-lamp",4,-1},{"iron-chest",4,0},{"iron-chest",4,3},{"small-lamp",4,4},{"stone-wall",4,11},{"stone-wall",5,-8},{"small-lamp",5,-6},
|
||||
{"iron-chest",5,0},{"iron-chest",5,3},{"small-lamp",5,9},{"stone-wall",5,11},{"stone-wall",6,-8},{"small-electric-pole",6,-2},{"iron-chest",6,0},{"iron-chest",6,3},{"small-electric-pole",6,5},{"stone-wall",6,11},
|
||||
{"stone-wall",7,-8},{"small-lamp",7,-4},{"small-lamp",7,-1},{"iron-chest",7,0},{"iron-chest",7,3},{"small-lamp",7,4},{"small-lamp",7,7},{"stone-wall",7,11},{"stone-wall",9,-6},{"stone-wall",9,-5},
|
||||
{"stone-wall",9,-4},{"stone-wall",9,-3},{"stone-wall",9,-2},{"stone-wall",9,-1},{"stone-wall",9,0},{"stone-wall",9,3},{"stone-wall",9,4},{"stone-wall",9,5},{"stone-wall",9,6},{"stone-wall",9,7},
|
||||
{"stone-wall",9,8},{"stone-wall",9,9}
|
||||
}
|
||||
|
||||
local turrets = {{-3,-3},{-3,3},{3,-3},{3,3}}
|
||||
local turret_ammo = 'uranium-rounds-magazine'
|
||||
|
||||
local global_offset = {x=0,y=-2}
|
||||
local decon_radius = 20
|
||||
local decon_tile = 'concrete'
|
||||
local partern_radius = 50
|
||||
local partern_tile = 'stone-path'
|
||||
|
||||
local function afk_belt(surface,offset)
|
||||
local belts = {{-0.5,-0.5,2},{0.5,-0.5,4},{-0.5,0.5,0},{0.5,0.5,6}}
|
||||
for _,pos in pairs(belts) do
|
||||
local position = {pos[1]+offset[1],pos[2]+offset[2]}
|
||||
local belt = surface.create_entity{name='transport-belt',position=position,force='neutral',direction=pos[3]}
|
||||
belt.destructible = false; belt.health = 0; belt.minable = false; belt.rotatable = false
|
||||
end
|
||||
end
|
||||
|
||||
local function spawn_turrets()
|
||||
local surface = game.surfaces[1]
|
||||
if not game.forces['spawn'] then game.create_force('spawn').set_cease_fire('player',true) game.forces['player'].set_cease_fire('spawn',true) end
|
||||
for _,pos in pairs(turrets) do
|
||||
local turret = surface.find_entity('gun-turret',pos)
|
||||
if not turret then
|
||||
turret = surface.create_entity{name='gun-turret',position=pos,force='spawn'}
|
||||
turret.destructible = false; turret.health = 0; turret.minable = false; turret.rotatable = false; turret.operable = false; turret.health = 0
|
||||
end
|
||||
if turret.get_inventory(defines.inventory.turret_ammo).can_insert{name=turret_ammo,count=10} then
|
||||
turret.get_inventory(defines.inventory.turret_ammo).insert{name=turret_ammo,count=10}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.register(defines.events.on_tick,function(event)
|
||||
if event.tick % 3600 then
|
||||
spawn_turrets()
|
||||
end
|
||||
end)
|
||||
|
||||
Event.register(defines.events.on_player_created, function(event)
|
||||
if event.player_index == 1 then
|
||||
local player = Game.get_player(event)
|
||||
local surface = player.surface
|
||||
local offset = {x=0,y=0}
|
||||
local partern_base_tile = surface.get_tile(player.position).name
|
||||
if partern_base_tile == 'deepwater' or partern_base_tile == 'water' then partern_base_tile = 'grass-1' end
|
||||
local base_tiles = {}
|
||||
local tiles = {}
|
||||
for x = -partern_radius-5, partern_radius+5 do
|
||||
for y = -partern_radius-5, partern_radius+5 do
|
||||
if x^2+y^2 < decon_radius^2 then
|
||||
table.insert(base_tiles,{name=decon_tile,position={x+offset.x,y+offset.y}})
|
||||
local entities = surface.find_entities_filtered{area={{x+offset.x-1,y+offset.y-1},{x+offset.x,y+offset.y}}}
|
||||
for _,entity in pairs(entities) do if entity.name ~= 'player' then entity.destroy() end end
|
||||
elseif x^2+y^2 < partern_radius^2 then
|
||||
table.insert(base_tiles,{name=partern_base_tile,position={x+offset.x,y+offset.y}})
|
||||
end
|
||||
end
|
||||
end
|
||||
surface.set_tiles(base_tiles)
|
||||
for _,position in pairs(tile_positions) do
|
||||
table.insert(tiles,{name=partern_tile,position={position[1]+offset.x+global_offset.x,position[2]+offset.y+global_offset.y}})
|
||||
end
|
||||
surface.set_tiles(tiles)
|
||||
for _,entity in pairs(entitys) do
|
||||
local entity = surface.create_entity{name=entity[1],position={entity[2]+offset.x+global_offset.x,entity[3]+offset.y+global_offset.y},force='neutral'}
|
||||
entity.destructible = false; entity.health = 0; entity.minable = false; entity.rotatable = false
|
||||
end
|
||||
spawn_turrets()
|
||||
afk_belt(surface,{offset.x-5,offset.y-5})
|
||||
afk_belt(surface,{offset.x+5,offset.y-5})
|
||||
afk_belt(surface,{offset.x-5,offset.y+5})
|
||||
afk_belt(surface,{offset.x+5,offset.y+5})
|
||||
player.force.set_spawn_position(offset,surface)
|
||||
player.teleport(offset,surface)
|
||||
end
|
||||
end)
|
||||
}
|
||||
Reference in New Issue
Block a user