-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwin.lua
More file actions
106 lines (95 loc) · 3.5 KB
/
Copy pathwin.lua
File metadata and controls
106 lines (95 loc) · 3.5 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
function troy_destroy_o()
surface = game.surfaces["nauvis"]
global.kill_count_troy = global.kill_count_troy + 40
show_update_score()
for k, p in pairs (game.players) do
p.print("Spartas Roboport has been destroyed")
p.print("Troy was Awarded 40 Points")
end
Event.register(defines.events.on_tick, kill_sparta)
global.ending_tick = game.tick + 300
end
function sparta_destroy_p()
surface = game.surfaces["nauvis"]
global.kill_count_sparta = global.kill_count_sparta + 40
show_update_score()
for k, p in pairs (game.players) do
p.print("Troys Roboport has been destroyed")
p.print("Sparta was Awarded 40 Points")
end
Event.register(defines.events.on_tick, kill_troy)
global.ending_tick = game.tick + 300
end
-- if the Sparta roboport is destroyed, spawn a series of explosions.
function kill_sparta()
local s = game.surfaces["nauvis"]
local drx = global.drbp.x
local dry = global.drbp.y
if game.tick < global.ending_tick and game.tick % 20 == 0 then
s.create_entity{position = {drx + math.random(-2,2),dry + math.random(-2,2)}, name = "medium-explosion"}
end
if game.tick == global.ending_tick then
s.create_entity{position = {drx,dry}, name = "big-explosion"}
Event.remove(defines.events.on_tick, kill_sparta)
end
end
-- if the Troy roboport is destroyed, spawn a series of explosions.
function kill_troy()
local s = game.surfaces["nauvis"]
local drx = global.drbp.x
local dry = global.drbp.y
if game.tick < global.ending_tick and game.tick % 20 == 0 then
s.create_entity{position = {drx + math.random(-2,2),dry + math.random(-2,2)}, name = "medium-explosion"}
end
if game.tick == global.ending_tick then
s.create_entity{position = {drx,dry}, name = "big-explosion"}
Event.remove(defines.events.on_tick, kill_troy)
end
end
--check on tick, to see if anyone has won.
function win()
if global.kill_count_troy >= 100 then
for _, p in pairs (game.connected_players) do p.surface.create_entity{position=p.position, name="big-explosion"} end
global.end_screen = game.tick + 180
Event.register(defines.events.on_tick, troy_win)
end
if global.kill_count_sparta >= 100 then
for _, p in pairs (game.connected_players) do p.surface.create_entity{position=p.position, name="big-explosion"} end
global.end_screen = game.tick + 180
Event.register(defines.events.on_tick, sparta_win)
end
end
function sparta_win()
if game.tick == global.end_screen then
for k, player in pairs (game.connected_players) do
if player.force.name == "Sparta" then
showdialog(player, "You win :D", "Sparta has defeated Troy. Well done!")
end
if player.force.name == "Troy" then
showdialog(player, "You lost :(", "Troy was defeated by Sparta. Better luck next time.")
end
end
end
return
end
function troy_win()
if game.tick == global.end_screen then
for k, player in pairs (game.connected_players) do
if player.force.name == "Troy" then
showdialog(player, "You win :D", "Troy has defeated Sparta. Well done!")
end
if player.force.name == "Sparta" then
showdialog(player, "You lost :(", "Sparta was defeated by Troy. Better luck next time.")
end
end
end
return
end
--gui with a message, event on win.
function showdialog(player, title, message)
if player.gui.center.end_message == nil then
local frame = player.gui.center.add{type="frame", name="end_message", caption=title, direction="vertical"}
frame.add{type="label", caption=message}
frame.add{type="button", name="end_message_button", caption="Close this message"}
end
end