-
Notifications
You must be signed in to change notification settings - Fork 23
/
hud.lua
59 lines (46 loc) · 1.23 KB
/
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
local huddata = {}
core.register_on_joinplayer(function(player)
local name = player:get_player_name()
local data = {}
data.imageid = player:hud_add({
hud_elem_type = "image",
name = "MailIcon",
position = {x=0.52, y=0.52},
text="",
scale = {x=1,y=1},
alignment = {x=0.5, y=0.5},
})
data.textid = player:hud_add({
hud_elem_type = "text",
name = "MailText",
position = {x=0.55, y=0.52},
text= "",
scale = {x=1,y=1},
alignment = {x=0.5, y=0.5},
})
huddata[name] = data
end)
core.register_on_leaveplayer(function(player)
local name = player:get_player_name()
huddata[name] = nil
end)
function mail.hud_update(playername, messages)
local data = huddata[playername]
local player = core.get_player_by_name(playername)
if not data or not player then
return
end
local unreadcount = 0
for _, message in ipairs(messages) do
if not message.read then
unreadcount = unreadcount + 1
end
end
if unreadcount == 0 or (not mail.get_setting(playername, "hud_notifications")) then
player:hud_change(data.imageid, "text", "")
player:hud_change(data.textid, "text", "")
else
player:hud_change(data.imageid, "text", "email_mail.png")
player:hud_change(data.textid, "text", unreadcount .. " /mail")
end
end