-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseparate_spawns_guis.lua
542 lines (459 loc) · 25.5 KB
/
separate_spawns_guis.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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
-- separate_spawns_guis.lua
-- I made a separate file for all the GUI related functions
require("separate_spawns")
local SPAWN_GUI_MAX_WIDTH = 900
local SPAWN_GUI_MAX_HEIGHT = 1250
-- Use this for testing shared spawns...
-- local sharedSpawnExample1 = {openAccess=true,
-- position={x=50,y=50},
-- players={"ABC", "DEF"}}
-- local sharedSpawnExample2 = {openAccess=false,
-- position={x=200,y=200},
-- players={"ABC", "DEF"}}
-- local sharedSpawnExample3 = {openAccess=true,
-- owner="testName1",
-- players={"A", "B", "C", "D"}}
-- global.sharedSpawns = {testName1=sharedSpawnExample1,
-- testName2=sharedSpawnExample2,
-- testName3=sharedSpawnExample3}
-- A display gui message
-- Meant to be display the first time a player joins.
function DisplayWelcomeTextGui(player)
player.gui.center.add{name = "welcome_msg", type = "frame", direction = "vertical", caption=global.welcome_msg_title}
local wGui = player.gui.center.welcome_msg
wGui.style.maximal_width = SPAWN_GUI_MAX_WIDTH
wGui.style.maximal_height = SPAWN_GUI_MAX_HEIGHT
wGui.add{name = "welcome_msg_lbl1", type = "label", caption="The moment CTT (Consciousness Transferal Technology) was invented,"}
ApplyStyle(wGui.welcome_msg_lbl1, my_label_style)
wGui.add{name = "welcome_msg_lbl2", type = "label", caption="everything changed. Death was no longer permanent, people just"}
ApplyStyle(wGui.welcome_msg_lbl2, my_label_style)
wGui.add{name = "welcome_msg_lbl3", type = "label", caption="“respawned” in a healthy, young body. At first, it was just for"}
ApplyStyle(wGui.welcome_msg_lbl3, my_label_style)
wGui.add{name = "welcome_msg_lbl4", type = "label", caption="the ultra rich. But soon it was recognized as a human right."}
ApplyStyle(wGui.welcome_msg_lbl4, my_label_style)
wGui.add{name = "welcome_msg_spacer1", type = "label", caption=" "}
ApplyStyle(wGui.welcome_msg_spacer1, my_spacer_style)
wGui.add{name = "welcome_msg_lbl5", type = "label", caption="The population exploded and put a tremendous pressure on earth’s"}
ApplyStyle(wGui.welcome_msg_lbl5, my_label_style)
wGui.add{name = "welcome_msg_lbl6", type = "label", caption="resources. It sparked an age of incredible technological advances"}
ApplyStyle(wGui.welcome_msg_lbl6, my_label_style)
wGui.add{name = "welcome_msg_lbl7", type = "label", caption="and political turmoil. Soon the moon and Mars were colonised. But"}
ApplyStyle(wGui.welcome_msg_lbl7, my_label_style)
wGui.add{name = "welcome_msg_lbl8", type = "label", caption="even that wasn’t enough, the boundaries had to be pushed further."}
ApplyStyle(wGui.welcome_msg_lbl8, my_label_style)
wGui.add{name = "welcome_msg_lbl9", type = "label", caption="Almost every piece of the solar system that was colonisable has "}
ApplyStyle(wGui.welcome_msg_lbl9, my_label_style)
wGui.add{name = "welcome_msg_lbl10", type = "label", caption="been colonised."}
ApplyStyle(wGui.welcome_msg_lbl10, my_label_style)
wGui.add{name = "welcome_msg_spacer2", type = "label", caption=" "}
ApplyStyle(wGui.welcome_msg_spacer2, my_spacer_style)
wGui.add{name = "welcome_msg_lbl11", type = "label", caption="Now the human race is looking beyond it’s own solar system ..."}
ApplyStyle(wGui.welcome_msg_lbl11, my_label_style)
wGui.add{name = "welcome_msg_spacer3", type = "label", caption=" "}
ApplyStyle(wGui.welcome_msg_spacer3, my_spacer_style)
wGui.add{name = "welcome_msg_lbl12", type = "label", caption="A colonial ship with on board CTT has been dispatched a long time "}
ApplyStyle(wGui.welcome_msg_lbl12, my_label_style)
wGui.add{name = "welcome_msg_lbl13", type = "label", caption="ago and has arrived at a habitable planet. Consciousness can be "}
ApplyStyle(wGui.welcome_msg_lbl13, my_label_style)
wGui.add{name = "welcome_msg_lbl14", type = "label", caption="transferred through subspace to the ship making the trip near instant, "}
ApplyStyle(wGui.welcome_msg_lbl14, my_label_style)
wGui.add{name = "welcome_msg_lbl15", type = "label", caption="but very expensive."}
ApplyStyle(wGui.welcome_msg_lbl15, my_label_style)
wGui.add{name = "welcome_msg_spacer4", type = "label", caption=" "}
ApplyStyle(wGui.welcome_msg_spacer4, my_spacer_style)
wGui.add{name = "welcome_msg_lbl16", type = "label", caption="Only large corporations can afford to send someone there. You are on "}
ApplyStyle(wGui.welcome_msg_lbl16, my_label_style)
wGui.add{name = "welcome_msg_lbl17", type = "label", caption="of these representatives. It is your job to secure as much land and "}
ApplyStyle(wGui.welcome_msg_lbl17, my_label_style)
wGui.add{name = "welcome_msg_lbl18", type = "label", caption="resources as possible for your corporation. "}
ApplyStyle(wGui.welcome_msg_lbl18, my_label_style)
wGui.add{name = "welcome_msg_spacer5", type = "label", caption=" "}
ApplyStyle(wGui.welcome_msg_spacer5, my_spacer_style)
wGui.add{name = "welcome_msg_lbl19", type = "label", caption="The colonial ship is owned by the central government and enforces a "}
ApplyStyle(wGui.welcome_msg_lbl19, my_label_style)
wGui.add{name = "welcome_msg_lbl20", type = "label", caption="minimal number of laws on the new planet. But since death is no "}
ApplyStyle(wGui.welcome_msg_lbl20, my_label_style)
wGui.add{name = "welcome_msg_lbl21", type = "label", caption="longer permanent, they let you do pretty much anything as long as "}
ApplyStyle(wGui.welcome_msg_lbl21, my_label_style)
wGui.add{name = "welcome_msg_lbl22", type = "label", caption="you pay your taxes."}
ApplyStyle(wGui.welcome_msg_lbl22, my_label_style)
wGui.add{name = "welcome_msg_spacer6", type = "label", caption=" "}
ApplyStyle(wGui.welcome_msg_spacer6, my_spacer_style)
wGui.add{name = "welcome_msg_spacer7", type = "label", caption=" "}
ApplyStyle(wGui.welcome_msg_spacer7, my_spacer_style)
wGui.add{name = "welcome_okay_btn",
type = "button",
caption="Transfer my consciousness"}
end
-- Handle the gui click of the welcome msg
function WelcomeTextGuiClick(event)
if not (event and event.element and event.element.valid) then return end
local player = game.players[event.player_index]
local buttonClicked = event.element.name
if (buttonClicked == "welcome_okay_btn") then
if (player.gui.center.welcome_msg ~= nil) then
player.gui.center.welcome_msg.destroy()
end
DisplaySpawnOptions(player)
end
end
-- Display the spawn options and explanation
function DisplaySpawnOptions(player)
player.gui.center.add{name = "spawn_opts",
type = "frame",
direction = "vertical",
caption="Spawn Options"}
local sGui = player.gui.center.spawn_opts
sGui.style.maximal_width = SPAWN_GUI_MAX_WIDTH
sGui.style.maximal_height = SPAWN_GUI_MAX_HEIGHT
-- Warnings and explanations...
sGui.add{name = "warning_lbl1", type = "label",
caption="This is your ONLY chance to choose a spawn option. Choose carefully..."}
sGui.add{name = "warning_spacer", type = "label",
caption=" "}
ApplyStyle(sGui.warning_lbl1, my_warning_style)
ApplyStyle(sGui.warning_spacer, my_spacer_style)
sGui.add{name = "spawn_msg_lbl1", type = "label",
caption=SPAWN_MSG1}
sGui.add{name = "spawn_msg_lbl2", type = "label",
caption=SPAWN_MSG2}
sGui.add{name = "spawn_msg_lbl3", type = "label",
caption=SPAWN_MSG3}
sGui.add{name = "spawn_msg_spacer", type = "label",
caption="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"}
ApplyStyle(sGui.spawn_msg_lbl1, my_label_style)
ApplyStyle(sGui.spawn_msg_lbl2, my_label_style)
ApplyStyle(sGui.spawn_msg_lbl3, my_label_style)
ApplyStyle(sGui.spawn_msg_spacer, my_spacer_style)
if ENABLE_DEFAULT_SPAWN then
sGui.add{name = "default_spawn_btn",
type = "button",
caption="Default Spawn"}
sGui.add{name = "normal_spawn_lbl1", type = "label",
caption="This is the default spawn behavior of a vanilla game."}
sGui.add{name = "normal_spawn_lbl2", type = "label",
caption="You join the default team in the center of the map."}
sGui.add{name = "normal_spawn_lbl3", type = "label",
caption="(Back by popular request...)"}
ApplyStyle(sGui.normal_spawn_lbl1, my_label_style)
ApplyStyle(sGui.normal_spawn_lbl2, my_label_style)
ApplyStyle(sGui.normal_spawn_lbl3, my_label_style)
else
sGui.add{name = "normal_spawn_lbl1", type = "label",
caption="Default spawn is disabled in this mode."}
ApplyStyle(sGui.normal_spawn_lbl1, my_warning_style)
end
sGui.add{name = "normal_spawn_spacer", type = "label",
caption="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"}
ApplyStyle(sGui.normal_spawn_spacer, my_spacer_style)
-- The main spawning options. Solo near and solo far.
sGui.add{name = "isolated_spawn_near",
type = "button",
caption="Solo Spawn (Near)"}
sGui.add{name = "isolated_spawn_far",
type = "button",
caption="Solo Spawn (Far)"}
sGui.add{name = "isolated_spawn_lbl1", type = "label",
caption="You are spawned in a new area, with some starting resources."}
sGui.add{name = "isolated_spawn_lbl2", type = "label",
caption="You will still be part of the default team."}
sGui.add{name = "isolated_spawn_spacer", type = "label",
caption="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"}
ApplyStyle(sGui.isolated_spawn_lbl1, my_label_style)
ApplyStyle(sGui.isolated_spawn_lbl2, my_label_style)
ApplyStyle(sGui.isolated_spawn_spacer, my_spacer_style)
-- Spawn options to join another player's base.
if ENABLE_SHARED_SPAWNS then
local numAvailSpawns = GetNumberOfAvailableSharedSpawns()
if (numAvailSpawns > 0) then
sGui.add{name = "join_other_spawn",
type = "button",
caption="Join Someone (" .. numAvailSpawns .. " available)"}
sGui.add{name = "join_other_spawn_lbl1", type = "label",
caption="You are spawned in someone else's base."}
sGui.add{name = "join_other_spawn_lbl2", type = "label",
caption="This requires at least 1 person to have allowed access to their base."}
sGui.add{name = "join_other_spawn_lbl3", type = "label",
caption="This choice is final and you will not be able to create your own spawn later."}
sGui.add{name = "join_other_spawn_spacer", type = "label",
caption=" "}
ApplyStyle(sGui.join_other_spawn_lbl1, my_label_style)
ApplyStyle(sGui.join_other_spawn_lbl2, my_label_style)
ApplyStyle(sGui.join_other_spawn_lbl3, my_label_style)
ApplyStyle(sGui.join_other_spawn_spacer, my_spacer_style)
else
sGui.add{name = "join_other_spawn_lbl1", type = "label",
caption="There are currently no shared bases availble to spawn at."}
sGui.add{name = "join_other_spawn_spacer", type = "label",
caption=" "}
ApplyStyle(sGui.join_other_spawn_lbl1, my_warning_style)
ApplyStyle(sGui.join_other_spawn_spacer, my_spacer_style)
sGui.add{name = "join_other_spawn_check",
type = "button",
caption="Check Again"}
end
else
sGui.add{name = "join_other_spawn_lbl1", type = "label",
caption="Shared spawns are disabled in this mode."}
ApplyStyle(sGui.join_other_spawn_lbl1, my_warning_style)
end
-- Some final notes
sGui.add{name = "note_spacer1", type = "label",
caption="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"}
sGui.add{name = "note_spacer2", type = "label",
caption=" "}
if MAX_ONLINE_PLAYERS_AT_SHARED_SPAWN then
sGui.add{name = "shared_spawn_note1", type = "label",
caption="If you create your own spawn point you can allow up to " .. MAX_ONLINE_PLAYERS_AT_SHARED_SPAWN-1 .. " other online players to join." }
ApplyStyle(sGui.shared_spawn_note1, my_note_style)
end
sGui.add{name = "note_lbl1", type = "label",
caption="Near spawn is between " .. NEAR_MIN_DIST*CHUNK_SIZE .. "-" .. NEAR_MAX_DIST*CHUNK_SIZE .. " tiles away from the center of the map."}
sGui.add{name = "note_lbl2", type = "label",
caption="Far spawn is between " .. FAR_MIN_DIST*CHUNK_SIZE .. "-" .. FAR_MAX_DIST*CHUNK_SIZE .. " tiles away from the center of the map."}
sGui.add{name = "note_lbl3", type = "label",
caption="Solo spawns are dangerous! Expect a fight to reach other players."}
sGui.add{name = "note_spacer3", type = "label",
caption=" "}
ApplyStyle(sGui.note_lbl1, my_note_style)
ApplyStyle(sGui.note_lbl2, my_note_style)
ApplyStyle(sGui.note_lbl3, my_note_style)
ApplyStyle(sGui.note_spacer1, my_spacer_style)
ApplyStyle(sGui.note_spacer2, my_spacer_style)
ApplyStyle(sGui.note_spacer3, my_spacer_style)
end
-- Handle the gui click of the spawn options
function SpawnOptsGuiClick(event)
if not (event and event.element and event.element.valid) then return end
local player = game.players[event.player_index]
local buttonClicked = event.element.name
-- Check if a valid button on the gui was pressed
-- and delete the GUI
if ((buttonClicked == "default_spawn_btn") or
(buttonClicked == "isolated_spawn_near") or
(buttonClicked == "isolated_spawn_far") or
(buttonClicked == "join_other_spawn") or
(buttonClicked == "join_other_spawn_check")) then
if (player.gui.center.spawn_opts ~= nil) then
player.gui.center.spawn_opts.destroy()
end
end
if (buttonClicked == "default_spawn_btn") then
CreateSpawnCtrlGui(player)
GivePlayerStarterItems(player)
ChangePlayerSpawn(player, player.force.get_spawn_position("nauvis"))
SendBroadcastMsg(player.name .. " joined the main force!")
ChartArea(player.force, player.position, 4)
elseif ((buttonClicked == "isolated_spawn_near") or (buttonClicked == "isolated_spawn_far")) then
CreateSpawnCtrlGui(player)
-- Create a new spawn point
local newSpawn = {x=0,y=0}
-- Re-used abandoned spawns...
if (#global.unusedSpawns >= 1) then
newSpawn = table.remove(global.unusedSpawns)
global.uniqueSpawns[player.name] = newSpawn
player.print("Sorry! You have been assigned to an abandoned base! This is done to keep map size small.")
ChangePlayerSpawn(player, newSpawn)
SendPlayerToSpawn(player)
GivePlayerStarterItems(player)
SendBroadcastMsg(player.name .. " joined an abandoned base!")
else
-- Find coordinates of a good place to spawn
if (buttonClicked == "isolated_spawn_far") then
newSpawn = FindUngeneratedCoordinates(FAR_MIN_DIST,FAR_MAX_DIST)
elseif (buttonClicked == "isolated_spawn_near") then
newSpawn = FindUngeneratedCoordinates(NEAR_MIN_DIST,NEAR_MAX_DIST)
end
-- If that fails, find a random map edge in a rand direction.
if ((newSpawn.x == 0) and (newSpawn.x == 0)) then
newSpawn = FindMapEdge(GetRandomVector())
DebugPrint("Resorting to find map edge! x=" .. newSpawn.x .. ",y=" .. newSpawn.y)
end
-- Create that spawn in the global vars
ChangePlayerSpawn(player, newSpawn)
-- Send the player there
SendPlayerToNewSpawnAndCreateIt(player, newSpawn)
if (buttonClicked == "isolated_spawn_near") then
SendBroadcastMsg(player.name .. " joined the main force from a distance!")
elseif (buttonClicked == "isolated_spawn_far") then
SendBroadcastMsg(player.name .. " joined the main force from a great distance!")
end
player.print("PLEASE WAIT WHILE YOU ARE BEING TRANSPORTED!")
player.print("PLEASE WAIT WHILE YOU ARE BEING TRANSPORTED!!")
player.print("PLEASE WAIT WHILE YOU ARE BEING TRANSPORTED!!!")
end
elseif (buttonClicked == "join_other_spawn") then
DisplaySharedSpawnOptions(player)
-- Provide a way to refresh the gui to check if people have shared their
-- bases.
elseif (buttonClicked == "join_other_spawn_check") then
DisplaySpawnOptions(player)
end
end
-- Display the spawn options and explanation
function DisplaySharedSpawnOptions(player)
player.gui.center.add{name = "shared_spawn_opts",
type = "frame",
direction = "vertical",
caption="Available Bases to Join:"}
local shGuiFrame = player.gui.center.shared_spawn_opts
local shGui = shGuiFrame.add{type="scroll-pane", name="spawns_scroll_pane", caption=""}
ApplyStyle(shGui, my_fixed_width_style)
shGui.style.maximal_width = SPAWN_GUI_MAX_WIDTH
shGui.style.maximal_height = SPAWN_GUI_MAX_HEIGHT
shGui.horizontal_scroll_policy = "never"
for spawnName,sharedSpawn in pairs(global.sharedSpawns) do
if sharedSpawn.openAccess then
local spotsRemaining = MAX_ONLINE_PLAYERS_AT_SHARED_SPAWN - GetOnlinePlayersAtSharedSpawn(spawnName)
if (spotsRemaining > 0) then
shGui.add{type="button", caption=spawnName .. " (" .. spotsRemaining .. " spots remaining)", name=spawnName}
shGui.add{name = spawnName .. "spacer_lbl", type = "label", caption=" "}
ApplyStyle(shGui[spawnName], my_small_button_style)
ApplyStyle(shGui[spawnName .. "spacer_lbl"], my_spacer_style)
end
end
end
shGui.add{name = "shared_spawn_cancel",
type = "button",
caption="Cancel (Return to Previous Options)"}
end
-- Handle the gui click of the shared spawn options
function SharedSpwnOptsGuiClick(event)
if not (event and event.element and event.element.valid) then return end
local player = game.players[event.player_index]
local buttonClicked = event.element.name
-- Check for cancel button, return to spawn options
if (buttonClicked == "shared_spawn_cancel") then
DisplaySpawnOptions(player)
if (player.gui.center.shared_spawn_opts ~= nil) then
player.gui.center.shared_spawn_opts.destroy()
end
-- Else check for which spawn was selected
-- If a spawn is removed during this time, the button will not do anything
else
for spawnName,sharedSpawn in pairs(global.sharedSpawns) do
if (buttonClicked == spawnName) then
CreateSpawnCtrlGui(player)
ChangePlayerSpawn(player,sharedSpawn.position)
SendPlayerToSpawn(player)
GivePlayerStarterItems(player)
table.insert(sharedSpawn.players, player.name)
SendBroadcastMsg(player.name .. " joined " .. spawnName .. "'s base!")
if (player.gui.center.shared_spawn_opts ~= nil) then
player.gui.center.shared_spawn_opts.destroy()
end
break
end
end
end
end
function CreateSpawnCtrlGui(player)
if player.gui.top.spwn_ctrls == nil then
player.gui.top.add{name="spwn_ctrls", type="button", caption="Spawn Ctrl"}
end
end
local function IsSharedSpawnActive(player)
if ((global.sharedSpawns[player.name] == nil) or
(global.sharedSpawns[player.name].openAccess == false)) then
return false
else
return true
end
end
-- Get a random warp point to go to
function GetRandomSpawnPoint()
local numSpawnPoints = TableLength(global.sharedSpawns)
if (numSpawnPoints > 0) then
local randSpawnNum = math.random(1,numSpawnPoints)
local counter = 1
for _,sharedSpawn in pairs(global.sharedSpawns) do
if (randSpawnNum == counter) then
return sharedSpawn.position
end
counter = counter + 1
end
end
return {x=0,y=0}
end
-- This is a toggle function, it either shows or hides the spawn controls
function ExpandSpawnCtrlGui(player, tick)
local spwnCtrlPanel = player.gui.left["spwn_ctrl_panel"]
if (spwnCtrlPanel) then
spwnCtrlPanel.destroy()
else
local spwnCtrlPanel = player.gui.left.add{type="frame",
name="spwn_ctrl_panel", caption="Spawn Controls:"}
local spwnCtrls = spwnCtrlPanel.add{type="scroll-pane",
name="spwn_ctrl_panel", caption=""}
ApplyStyle(spwnCtrls, my_fixed_width_style)
spwnCtrls.style.maximal_height = SPAWN_GUI_MAX_HEIGHT
spwnCtrls.horizontal_scroll_policy = "never"
if ENABLE_SHARED_SPAWNS then
if (global.uniqueSpawns[player.name] ~= nil) then
-- This checkbox allows people to join your base when they first
-- start the game.
spwnCtrls.add{type="checkbox", name="accessToggle",
caption="Allow others to join your base.",
state=IsSharedSpawnActive(player)}
spwnCtrls["accessToggle"].style.top_padding = 10
spwnCtrls["accessToggle"].style.bottom_padding = 10
ApplyStyle(spwnCtrls["accessToggle"], my_fixed_width_style)
end
end
-- Sets the player's custom spawn point to their current location
if ((tick - global.playerCooldowns[player.name].setRespawn) > RESPAWN_COOLDOWN_TICKS) then
spwnCtrls.add{type="button", name="setRespawnLocation", caption="Set New Respawn Location (1 hour cooldown)"}
spwnCtrls["setRespawnLocation"].style.font = "default-small-semibold"
spwnCtrls.add{name = "respawn_cooldown_note2", type = "label",
caption="This will set your respawn point to your current location."}
spwnCtrls.add{name = "respawn_cooldown_spacer1", type = "label",
caption=" "}
ApplyStyle(spwnCtrls.respawn_cooldown_note2, my_note_style)
ApplyStyle(spwnCtrls.respawn_cooldown_spacer1, my_spacer_style)
else
spwnCtrls.add{name = "respawn_cooldown_note1", type = "label",
caption="Set Respawn Cooldown Remaining: " .. formattime(RESPAWN_COOLDOWN_TICKS-(tick - global.playerCooldowns[player.name].setRespawn))}
spwnCtrls.add{name = "respawn_cooldown_note2", type = "label",
caption="This will set your respawn point to your current location."}
spwnCtrls.add{name = "respawn_cooldown_spacer1", type = "label",
caption=" "}
ApplyStyle(spwnCtrls.respawn_cooldown_note1, my_note_style)
ApplyStyle(spwnCtrls.respawn_cooldown_note2, my_note_style)
ApplyStyle(spwnCtrls.respawn_cooldown_spacer1, my_spacer_style)
end
end
end
function SpawnCtrlGuiClick(event)
if not (event and event.element and event.element.valid) then return end
local player = game.players[event.element.player_index]
local name = event.element.name
if (name == "spwn_ctrls") then
ExpandSpawnCtrlGui(player, event.tick)
end
if (name == "accessToggle") then
if event.element.state then
if DoesPlayerHaveCustomSpawn(player) then
if (global.sharedSpawns[player.name] == nil) then
CreateNewSharedSpawn(player)
else
global.sharedSpawns[player.name].openAccess = true
end
SendBroadcastMsg("New players can now join " .. player.name .. "'s base!")
end
else
if (global.sharedSpawns[player.name] ~= nil) then
global.sharedSpawns[player.name].openAccess = false
SendBroadcastMsg("New players can no longer join " .. player.name .. "'s base!")
end
end
end
-- Sets a new respawn point and resets the cooldown.
if (name == "setRespawnLocation") then
if DoesPlayerHaveCustomSpawn(player) then
ChangePlayerSpawn(player, player.position)
global.playerCooldowns[player.name].setRespawn = event.tick
ExpandSpawnCtrlGui(player, event.tick)
player.print("Re-spawn point updated!")
end
end
end