-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexecutor.hud.lua
104 lines (83 loc) · 2.45 KB
/
executor.hud.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
local HUD_POSITION = {x = missions.hud.posx, y = missions.hud.posy}
local HUD_ALIGNMENT = {x = 1, y = 0}
local hud = {} -- playerName -> {}
minetest.register_on_joinplayer(function(player)
local playername = player:get_player_name()
local data = {}
data.title = player:hud_add({
hud_elem_type = "text",
position = HUD_POSITION,
offset = {x = 0, y = 0},
text = "",
alignment = HUD_ALIGNMENT,
scale = {x = 100, y = 100},
number = 0xFFFFFF
})
data.mission = player:hud_add({
hud_elem_type = "text",
position = HUD_POSITION,
offset = {x = 0, y = 30},
text = "",
alignment = HUD_ALIGNMENT,
scale = {x = 100, y = 100},
number = 0x00FF00
})
data.time = player:hud_add({
hud_elem_type = "text",
position = HUD_POSITION,
offset = {x = 0, y = 60},
text = "",
alignment = HUD_ALIGNMENT,
scale = {x = 100, y = 100},
number = 0x00FF00
})
data.status = player:hud_add({
hud_elem_type = "text",
position = HUD_POSITION,
offset = {x = 0, y = 90},
text = "",
alignment = HUD_ALIGNMENT,
scale = {x = 100, y = 100},
number = 0x00FF00
})
hud[playername] = data
end)
missions.hud_update_status = function(player, status)
local playername = player:get_player_name()
local data = hud[playername]
if not data then
return
end
player:hud_change(data.status, "text", status)
end
missions.hud_update = function(player, mission)
local playername = player:get_player_name()
local data = hud[playername]
if not data then
return
end
if mission then
local now = os.time(os.date("!*t"))
local remainingTime = mission.time - (now - mission.start)
local percent = math.floor((mission.currentstep-1) / #mission.steps * 100)
player:hud_change(data.title, "text", "Mission: " .. mission.name)
player:hud_change(data.mission, "text", "Completed: " .. percent .. "%")
player:hud_change(data.time, "text", "Time: " .. missions.format_time(remainingTime))
if remainingTime > 60 then
player:hud_change(data.time, "number", 0x00FF00)
player:hud_change(data.mission, "number", 0x00FF00)
else
player:hud_change(data.time, "number", 0xFF0000)
player:hud_change(data.mission, "number", 0xFF0000)
end
else
player:hud_change(data.title, "text", "")
player:hud_change(data.mission, "text", "")
player:hud_change(data.time, "text", "")
player:hud_change(data.status, "text", "")
end
end
minetest.register_on_leaveplayer(function(player)
local playername = player:get_player_name()
hud[playername] = nil
end)