-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui.lua
136 lines (130 loc) · 6.13 KB
/
gui.lua
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
--Gui elements
Event.register(defines.events.on_gui_click, function(event)
local s = game.surfaces.nauvis
local player = game.players[event.player_index]
local index = event.player_index
if not event.element.valid then
return
end
-- Turns on/off Flashlight
if (event.element.name == "flashlight_button") then
if player.character == nil then return end
global.player_flashlight_state = global.player_flashlight_state or {}
if global.player_flashlight_state == true then
player.character.enable_flashlight()
global.player_flashlight_state = false
else
player.character.disable_flashlight()
global.player_flashlight_state = true
end
return
end
if (event.element.name == "crouch_button") then
if player.character == nil then return end
global.player_crouch_state = global.player_crouch_state or {}
global.player_crouch_color = global.player_crouch_color or {}
if global.player_crouch_state == true then
global.player_crouch_state = false
player.character_running_speed_modifier = 0
player.color = global.player_crouch_color
else
global.player_crouch_state = true
player.character_running_speed_modifier = -0.6
global.player_crouch_color = player.color
player.color = black
end
end
if player.gui.center.end_message ~= nil then
if (event.element.name == "end_message_button") then
player.gui.center.end_message.destroy()
end
end
if player.gui.left.choose_team ~= nil then
if (event.element.name == "sparta") then
if global.sparta_count > global.troy_count then player.print("Too many Players in Sparta, try Troy") return end
join_a_team(event, "Sparta", "Troy")
elseif (event.element.name == "troy") then
if global.troy_count > global.sparta_count then player.print("Too many Players in Troy, try Sparta") return end
join_a_team(event, "Troy", "Sparta")
elseif (event.element.name == "spectator") then
player.teleport(game.forces["Spectators"].get_spawn_position(game.surfaces.nauvis), game.surfaces.nauvis)
if player.character then player.character.destroy() end
if player.admin then
global.player_spectator_character = global.player_spectator_character or {}
if (global.player_spectator_character[index] and global.player_spectator_character[index].valid) then global.player_spectator_character[index].destroy() end
-- Creating an Admins force so that it the admin.lua code from util's has a force to send the admin back to
if not game.forces["Admins"] then
game.create_force("Admins")
for k, f in pairs(game.forces) do
f.set_cease_fire(game.forces["Admins"], true)
end
end
global.player_spectator_force = global.player_spectator_force or {}
global.player_spectator_force[index] = game.forces["Admins"]
force_spectators(index, nil)
else
player.set_controller{type = defines.controllers.ghost}
player.print("You are now a spectator. You are unable to interact with the game until you join a team.")
end
player.gui.left.choose_team.spectator.destroy()
end
end
end)
function make_team_option(player)
if player.gui.left.choose_team == nil then
local frame = player.gui.left.add{name = "choose_team", type = "frame", direction = "vertical", caption="Choose your Team"}
if player.admin then
frame.add{type = "button", caption = "Join Spectators", name = "spectator"}.style.font_color = {r= 0/256, g= 255/256, b= 255/256}
end
if player.admin then frame.spectator.caption = "Join Admins" end
frame.add{type = "button", caption = "Join Sparta", name = "sparta"}.style.font_color = global.sparta_color
frame.add{type = "button", caption = "Join Troy", name = "troy"}.style.font_color = global.troy_color
player.print("Teams are now unlocked")
end
end
-- updates the player count gui for total players joined each force, and players online for each force.
function update_count()
local sparta_status = "Sparta("..#game.forces["Sparta"].connected_players..")"
local troy_status = "Troy("..#game.forces["Troy"].connected_players..")"
for _, p in pairs(game.connected_players) do
if p.gui.top.persons == nil then
local frame = p.gui.top.add{name = "persons", type = "frame", direction = "horizontal", caption="Players Online"}
frame.add{type = "label", caption = sparta_status, name = "sparta"}.style.font_color = global.sparta_color
frame.add{type = "label", caption = troy_status, name = "troy"}.style.font_color = global.troy_color
else
p.gui.top.persons.sparta.caption = sparta_status
p.gui.top.persons.troy.caption = troy_status
end
end
end
function show_update_score()
local sparta_status = "Sparta("..global.kill_count_sparta..")"
local troy_status = "Troy("..global.kill_count_troy..")"
if global.kill_count_troy == nil then global.kill_count_troy = 0 end
if global.kill_count_sparta == nil then global.kill_count_sparta = 0 end
for index, p in pairs(game.players) do
if p.gui.top.kill_score == nil then
local frame = p.gui.top.add{name="kill_score",type="flow",direction="horizontal"}
frame.add{type="flow",name="space",direction="horizontal"}.style.minimal_width = 550
frame.add{type="label",name="kill_count_sparta",caption=sparta_status, style = "caption_label_style"}.style.font_color = global.sparta_color
frame.add{type="label", name="Vs", caption= "VS", style="caption_label_style"}
frame.add{type="label",name="kill_count_troy",caption=troy_status, style = "caption_label_style"}.style.font_color = global.troy_color
p.gui.top.kill_score.kill_count_sparta.caption = sparta_status
p.gui.top.kill_score.kill_count_troy.caption = troy_status
else
p.gui.top.kill_score.kill_count_troy.caption = tostring(troy_status)
p.gui.top.kill_score.kill_count_sparta.caption = tostring(sparta_status)
end
end
win()
end
--using this to order the gui'
function create_buttons(event)
local player = game.players[event.player_index]
if (not player.gui.top["flashlight_button"]) then
player.gui.top.add{type="button", name="flashlight_button", caption="Flashlight"}
end
if (not player.gui.top["crouch_button"]) then
local frame = player.gui.top.add{name = "crouch_button", type = "button", direction = "horizontal", caption = "Crouch"}
end
end