forked from dtandersen/AdequateBotStart
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcontrol.lua
More file actions
149 lines (130 loc) · 5.11 KB
/
control.lua
File metadata and controls
149 lines (130 loc) · 5.11 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
local ItemPrototypes = {
Armor = "power-armor-mk2",
Robot = "construction-robot",
Fuel = "",
Reactor = "fission-reactor-equipment", --4x4
Exoskeleton = "exoskeleton-equipment", --2x4
Shield = "energy-shield-mk2-equipment", --2x2
Roboport = "personal-roboport-mk2-equipment", --2x2
Battery = "battery-mk2-equipment", --1x2
LaserDefense = "personal-laser-defense-equipment", --2x2
Nightvision = "night-vision-equipment", --2x2
}
local Items
local ArmorModules = {
--Vanilla, 10x10 grid
{ Name = ItemPrototypes["Reactor"], Count = 4 },
{ Name = ItemPrototypes["Roboport"], Count = 4 },
{ Name = ItemPrototypes["Battery"], Count = 2 },
{ Name = ItemPrototypes["Shield"], Count = 4 },
}
--Personal Equipment gives upgraded options, lets use a few.
if script.active_mods["bobequipment"] then
ItemPrototypes["Reactor"] = "bob-fission-reactor-equipment-4" --Reactor 4 4x4
ItemPrototypes["Shield"] = "bob-energy-shield-mk6-equipment" --Shield 6 2x2
ItemPrototypes["Roboport"] = "bob-personal-roboport-mk4-equipment" --Roboport 4 2x2
ItemPrototypes["Battery"] = "bob-battery-mk6-equipment" --Battery 6 1x2
ItemPrototypes["LaserDefense"] = "bob-personal-laser-defense-equipment-6" --Laser Defense 6 2x2
ItemPrototypes["Exoskeleton"] = "bob-exoskeleton-equipment-3" --Exoskeleton 3 2x4
ItemPrototypes["Nightvision"] = "bob-night-vision-equipment-3" --2x2
end
--Logistics gives us upgraded bots
if script.active_mods["boblogistics"] then
ItemPrototypes["Robot"] = "bob-construction-robot-5"
end
--Freeplay
script.on_init(function(event)
if script.active_mods["Krastorio2"] then
--Krastorio, mk 4, 12x12
ItemPrototypes["Armor"] = "power-armor-mk4"
--Reactors require fuel
ItemPrototypes["Fuel"] = "dt-fuel"
ArmorModules = {
{ Name = ItemPrototypes["Reactor"], Count = 4 },
{ Name = ItemPrototypes["Roboport"], Count = 4 },
{ Name = ItemPrototypes["Shield"], Count = 4 },
{ Name = ItemPrototypes["Battery"], Count = 2 },
{ Name = ItemPrototypes["Nightvision"], Count = 1 },
{ Name = ItemPrototypes["Exoskeleton"], Count = 4 },
}
elseif script.active_mods["bobequipment"] then
--Bob's Warfare, mk 5, 11x12 grid
ItemPrototypes["Armor"] = "bob-power-armor-mk5"
ArmorModules = {
{ Name = ItemPrototypes["Reactor"], Count = 4 },
{ Name = ItemPrototypes["Roboport"], Count = 4 },
{ Name = ItemPrototypes["Exoskeleton"], Count = 2 },
{ Name = ItemPrototypes["Shield"], Count = 3 },
{ Name = ItemPrototypes["Battery"], Count = 4 },
{ Name = ItemPrototypes["Nightvision"], Count = 1 },
{ Name = ItemPrototypes["LaserDefense"], Count = 2 },
{ Name = ItemPrototypes["Battery"], Count = 2 },
}
end
Items = { { ItemPrototypes["Robot"], settings.global["starting-robot-count"].value } }
if not (ItemPrototypes["Fuel"] == "") then
table.insert(Items, { ItemPrototypes["Fuel"], 80 })
end
if not (settings.global["faster-robots"].value == 0) then
for k, v in pairs(game.forces) do
for z = 1, settings.global["faster-robots"].value, 1 do
v.technologies["worker-robots-speed-" .. tostring(z)].researched = true
end
end
end
storage.GivenArmor = storage.GivenArmor or {}
if (storage.GivenArmor == nil) then
storage.GivenArmor = {}
print("test")
end
end)
function EquipArmor(event)
local Player = game.players[event.player_index]
local ArmorInventory = Player.get_inventory(defines.inventory.character_armor)
if not (ArmorInventory == nil) then --If the player doesn't have armor inventory, the player hasn't spawned, so we can skip this round.
if not (Items == nil) then
for i, v in pairs(Items) do
Player.insert { name = v[1], count = v[2] }
end
end
if not (ArmorInventory.is_empty()) then
--We want to remove whatever armor they had to slot in what we want.
local CurrentArmor = ArmorInventory[1].name
ArmorInventory.clear()
--Then for good measure we destroy it from the inventory.
local PlayerInventory = Player.get_inventory(defines.inventory.character_main)
PlayerInventory.remove(CurrentArmor);
end
local n = 0
n = ArmorInventory.insert { name = ItemPrototypes["Armor"], count = 1 }
if (n > 0) then -- we actually equipped the armor
local grid = ArmorInventory[1].grid
for i, module in pairs(ArmorModules) do
for y = 1, module.Count, 1 do
grid.put({ name = module.Name })
end
end
end
--Now mark the player as given their tools
storage.GivenArmor[game.players[event.player_index].name] = true
end
end
--check the player inside of storage that we gave them armor already
function CheckStorage(event)
if (storage.GivenArmor[game.players[event.player_index].name] == true) then
return false --Player was given armor already
end
return true
end
--Classic start/no cutscene/multiplayer addition
script.on_event(defines.events.on_player_created, function(event)
if CheckStorage(event) then
EquipArmor(event)
end
end)
--Freeplay/Cutscene start
script.on_event(defines.events.on_cutscene_cancelled, function(event)
if CheckStorage(event) then
EquipArmor(event)
end
end)