-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.lua
More file actions
235 lines (216 loc) · 7.58 KB
/
control.lua
File metadata and controls
235 lines (216 loc) · 7.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
function initPlayer(player)
if player.character == nil then return end
if global.donePlayers == nil then
global.donePlayers = {}
end
if global.donePlayers[player.index] then return end
global.donePlayers[player.index] = true
player.get_inventory(defines.inventory.character_main).clear()
player.get_inventory(defines.inventory.character_armor).clear()
player.get_inventory(defines.inventory.character_guns).clear()
player.get_inventory(defines.inventory.character_ammo).clear()
-- Self item list
local items = {
-- basics
{"coal", 200},
{"iron-plate", 200},
{"copper-plate", 200},
{"iron-gear-wheel", 200},
{"electronic-circuit", 200},
-- belts
{"fast-transport-belt", 1800},
{"fast-underground-belt", 100},
{"fast-splitter", 50},
-- anti-biter
{"grenade", 100},
-- pipes
{"pipe-to-ground", 100},
{"pipe", 100},
-- other logistic
{"fast-inserter", 100},
{"long-handed-inserter", 100},
{"inserter", 100},
{"steel-chest", 50},
{"wooden-chest", 50},
{"construction-robot", 50},
-- buildings
{"steel-furnace", 100},
{"assembling-machine-2", 100},
{"assembling-machine-1", 20},
{"electric-mining-drill", 200},
-- transportation
{"carmk3", 1},
{"repair-pack", 50},
{"spidertron-remote", 4},
-- electricity
{"big-electric-pole", 100},
{"medium-electric-pole", 100},
{"small-electric-pole", 50},
{"boiler", 10},
{"steam-engine", 20},
{"offshore-pump", 5},
}
for _, item in pairs(items) do
player.insert{name = item[1], count = item[2]}
end
-- Power armor mk2 loadout
local armorInventory = player.get_inventory(defines.inventory.character_armor)
armorInventory.insert("power-armor-mk2")
local armorGrid = armorInventory.find_item_stack("power-armor-mk2").grid
local equipment = {
"fusion-reactor-equipment",
"fusion-reactor-equipment",
"fusion-reactor-equipment",
"fusion-reactor-equipment",
"exoskeleton-equipment",
"battery-mk2-equipment",
"battery-mk2-equipment",
"battery-mk2-equipment",
"belt-immunity-equipment",
"night-vision-equipment",
"personal-roboport-mk2-equipment",
}
for _, equip in pairs(equipment) do
armorGrid.put{name = equip}
end
-- Specific inventories for different spidertrons
-- Construction Spidertron
local constructionInventory = {
-- belts
{"fast-transport-belt", 3200},
{"fast-underground-belt", 200},
{"fast-splitter", 200},
-- pipes
{"pipe-to-ground", 400},
{"pipe", 400},
-- other logistic
{"fast-inserter", 400},
{"long-handed-inserter", 200},
{"steel-chest", 100},
{"construction-robot", 100},
-- buildings
{"steel-furnace", 400},
{"assembling-machine-2", 100},
{"electric-mining-drill", 600},
-- electricity
{"repair-pack", 100},
{"spidertron-remote", 1},
{"big-electric-pole", 600},
{"medium-electric-pole", 200},
{"small-electric-pole", 100},
{"boiler", 20},
{"steam-engine", 40},
{"offshore-pump", 10},
}
-- Military Spidertron
local militaryInventory = {
{"explosive-rocket", 23000},
{"repair-pack", 500},
{"construction-robot", 100},
{"spidertron-remote", 1},
}
-- Allrounder Spidertron
local allRounderInventory = {
-- belts
{"fast-transport-belt", 1800},
{"fast-underground-belt", 200},
{"fast-splitter", 100},
-- pipes
{"pipe-to-ground", 100},
{"pipe", 100},
-- other logistic
{"fast-inserter", 100},
{"long-handed-inserter", 100},
{"steel-chest", 100},
{"construction-robot", 100},
-- buildings
{"steel-furnace", 100},
{"assembling-machine-2", 100},
{"electric-mining-drill", 100},
-- electricity
{"repair-pack", 100},
{"spidertron-remote", 1},
{"big-electric-pole", 200},
{"medium-electric-pole", 100},
{"small-electric-pole", 50},
{"explosive-rocket", 12000},
{"boiler", 20},
{"steam-engine", 40},
{"offshore-pump", 10},
}
-- Function to add items to a spidertron
local function addItemsToSpidertron(spidertron, inventoryItems)
for _, item in pairs(inventoryItems) do
spidertron.insert{name = item[1], count = item[2]}
end
end
-- Add a random color function
local function randomColor()
return {r = math.random(), g = math.random(), b = math.random(), a = 1}
end
-- Create Spidertrons with specific roles
local function createSpidertrons(player)
-- Number of Spidertrons
local spidertronTypes = {
{inventory = constructionInventory, quantity = 1},
{inventory = militaryInventory, quantity = 2},
{inventory = allRounderInventory, quantity = 1},
}
for _, spidertronType in pairs(spidertronTypes) do
for i = 1, spidertronType.quantity do
-- Add small random offsets for position
local position = player.surface.find_non_colliding_position("spidertronmk3", player.position, 10, 1)
if position then
position.x = position.x + math.random(-5, 5)
position.y = position.y + math.random(-5, 5)
local spidertron = player.surface.create_entity{name="spidertronmk3", position=position, force=player.force}
if spidertron and spidertron.valid then
log("Spidertronmk3 created at position: " .. serpent.line(position))
-- Check if the spidertron has a grid and add equipment
if spidertron.grid then
-- Spidertron Equipment, Shared between all Spidertrons
local spidertronEquipment = {
{"fusion-reactor-equipment", 8},
{"personal-roboport-mk2-equipment", 6},
{"exoskeleton-equipment", 10},
{"battery-mk2-equipment", 14},
{"energy-shield-mk2-equipment", 4},
{"personal-laser-defense-equipment", 6},
}
for _, equip in pairs(spidertronEquipment) do
for i = 1, equip[2] do
spidertron.grid.put{name = equip[1]}
end
end
addItemsToSpidertron(spidertron, spidertronType.inventory)
-- Add a random color to each spidertron
spidertron.color = randomColor()
else
log("Failed to create Spidertronmk3")
end
else
log("No valid position found to create Spidertronmk3")
end
end
end
end
end
-- Self Ammo
player.get_inventory(defines.inventory.character_guns).insert{name = "submachine-gun", count = 5}
player.get_inventory(defines.inventory.character_ammo).insert{name = "uranium-rounds-magazine", count = 400}
-- Create Spidertrons
createSpidertrons(player)
end
function onPlayerJoined(event)
local player = game.players[event.player_index]
initPlayer(player)
end
script.on_event({defines.events.on_player_joined_game, defines.events.on_player_created}, onPlayerJoined)
-- Skip Crashsite and Intro
function onModInit()
if remote.interfaces["freeplay"] then
remote.call("freeplay", "set_disable_crashsite", true)
remote.call("freeplay", "set_skip_intro", true)
end
end
script.on_init(onModInit)