-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.lua
173 lines (153 loc) · 8.45 KB
/
init.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
--settings, choose what you want
local hudpos = {x = 0.5, y = 0.5}--the position coordinates are the percentage of the screen, ranging in value from 0 to 1. 0 means left/top, 1 means right/bottom.
--i recommend you dont set any to one as part of it wont be visible, max you should set one of the values to so you can still see it is 0.925 for x and 0.725 for y
--code
local huds = {}
local keys = {"up", "left", "down", "right", "jump", "aux1", "sneak"}
local huddefs
local huddefs_54 = {
up = {hud_elem_type = "image", position = hudpos, offset = {x = 0, y = 0}, text = "w_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
left = {hud_elem_type = "image", position = hudpos, offset = {x = -33, y = 33}, text = "a_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
down = {hud_elem_type = "image", position = hudpos, offset = {x = 0, y = 33}, text = "s_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
right = {hud_elem_type = "image", position = hudpos, offset = {x = 33, y = 33}, text = "d_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
jump = {hud_elem_type = "image", position = hudpos, offset = {x = -33, y = 99}, text = "space_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
place = {hud_elem_type = "image", position = hudpos, offset = {x = 17, y = 66}, text = "rmb_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
dig = {hud_elem_type = "image", position = hudpos, offset = {x = -33, y = 66}, text = "lmb_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
aux1 = {hud_elem_type = "image", position = hudpos, offset = {x = 33, y = 0}, text = "e_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
sneak = {hud_elem_type = "image", position = hudpos, offset = {x = -66, y = 33}, text = "shift_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
}
local huddefs_pre54 = {
up = {hud_elem_type = "image", position = hudpos, offset = {x = 0, y = 0}, text = "w_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
left = {hud_elem_type = "image", position = hudpos, offset = {x = -33, y = 33}, text = "a_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
down = {hud_elem_type = "image", position = hudpos, offset = {x = 0, y = 33}, text = "s_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
right = {hud_elem_type = "image", position = hudpos, offset = {x = 33, y = 33}, text = "d_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
jump = {hud_elem_type = "image", position = hudpos, offset = {x = -33, y = 99}, text = "space_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
RMB = {hud_elem_type = "image", position = hudpos, offset = {x = 17, y = 66}, text = "rmb_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
LMB = {hud_elem_type = "image", position = hudpos, offset = {x = -33, y = 66}, text = "lmb_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
aux1 = {hud_elem_type = "image", position = hudpos, offset = {x = 33, y = 0}, text = "e_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
sneak = {hud_elem_type = "image", position = hudpos, offset = {x = -66, y = 33}, text = "shift_key.png", alignment = {x = 1, y = 1}, scale = {x = 2, y = 2}, number = 0xFFFFFF},
}
local image_press
local image_press_54 = {up = "w_key_press.png", left = "a_key_press.png", down = "s_key_press.png", right = "d_key_press.png", jump = "space_key_press.png", place = "rmb_key_press.png", dig = "lmb_key_press.png", aux1 = "e_key_press.png", sneak = "shift_key_press.png"}
local image_press_pre54 = {up = "w_key_press.png", left = "a_key_press.png", down = "s_key_press.png", right = "d_key_press.png", jump = "space_key_press.png", RMB = "rmb_key_press.png", LMB = "lmb_key_press.png", aux1 = "e_key_press.png", sneak = "shift_key_press.png"}
local image_normal
local image_normal_54 = {up = "w_key.png", left = "a_key.png", down = "s_key.png", right = "d_key.png", jump = "space_key.png", place = "rmb_key.png", dig = "lmb_key.png", aux1 = "e_key.png", sneak = "shift_key.png"}
local image_normal_pre54 = {up = "w_key.png", left = "a_key.png", down = "s_key.png", right = "d_key.png", jump = "space_key.png", RMB = "rmb_key.png", LMB = "lmb_key.png", aux1 = "e_key.png", sneak = "shift_key.png"}
local before = {}
local version = ""
local function getversion()
local player = minetest.localplayer
if player:get_control().place == nil then
version = "pre5.4"
else
version = "5.4"
end
end
local fps = ""
local function checkfps()
minetest.register_globalstep(function(dtime)
fps = math.floor(tostring(1/dtime))
end)
end
local function check()
if not minetest.localplayer then
minetest.after(0, check)
return
end
getversion()
if version == "pre5.4" then
table.insert(keys, "RMB")
table.insert(keys, "LMB")
huddefs = huddefs_pre54
image_press = image_press_pre54
image_normal = image_normal_pre54
else
table.insert(keys, "place")
table.insert(keys, "dig")
huddefs = huddefs_54
image_press = image_press_54
image_normal = image_normal_54
end
rmbcps = minetest.localplayer:hud_add({hud_elem_type = "text", position = hudpos, offset = {x = -33, y = 159}, text = "RMB CPS: 0", alignment = {x = 1, y = 1}, scale = {x = 1, y = 1}, number = 0xFFFFFF})
lmbcps = minetest.localplayer:hud_add({hud_elem_type = "text", position = hudpos, offset = {x = -33, y = 145}, text = "LMB CPS: 0", alignment = {x = 1, y = 1}, scale = {x = 1, y = 1}, number = 0xFFFFFF})
checkfps()
framesps = minetest.localplayer:hud_add({hud_elem_type = "text", position = hudpos, offset = {x = -33, y = 131}, text = "FPS: " .. fps, alignment = {x = 1, y = 1}, scale = {x = 3, y = 3}, number = 0xFFFFFF})
for _, key in ipairs(keys) do
huds[key] = minetest.localplayer:hud_add(huddefs[key])
end
end
minetest.after(0, check)
local timer = 0
minetest.register_globalstep(function(dtime)
if minetest.localplayer then
timer = timer + dtime;
if timer >= 0.5 then
checkfps()
minetest.localplayer:hud_change(framesps, "text", "FPS: " .. fps)
timer = 0
end
end
end)
local rmbclicks = 0
local rmbpress = false
local rmbtimer = 0
minetest.register_globalstep(function(dtime)
if not minetest.localplayer then return end
local ctl = minetest.localplayer:get_control()
if version == "pre5.4" then
if ctl.RMB and not rmbpress then
rmbclicks = rmbclicks + 1
end
rmbpress = ctl.RMB
else
if ctl.place and not rmbpress then
rmbclicks = rmbclicks + 1
end
rmbpress = ctl.place
end
minetest.localplayer:hud_change(rmbcps, "text", "RMB CPS: " .. rmbclicks)
rmbtimer = rmbtimer + dtime
if rmbtimer >= 1 then
rmbclicks = 0
rmbtimer = 0
end
end)
local lmbclicks = 0
local lmbpress = false
local lmbtimer = 0
minetest.register_globalstep(function(dtime)
if not minetest.localplayer then return end
local ctl = minetest.localplayer:get_control()
if version == "pre5.4" then
if ctl.LMB and not lmbpress then
lmbclicks = lmbclicks + 1
end
lmbpress = ctl.LMB
else
if ctl.dig and not lmbpress then
lmbclicks = lmbclicks + 1
end
lmbpress = ctl.dig
end
minetest.localplayer:hud_change(lmbcps, "text", "LMB CPS: " .. lmbclicks)
lmbtimer = lmbtimer + dtime
if lmbtimer >= 1 then
lmbclicks = 0
lmbtimer = 0
end
end)
minetest.register_globalstep(function()
if minetest.localplayer then
local player = minetest.localplayer
local controls = player:get_control()
for _, key in ipairs(keys) do
if controls[key] and not before[key] then
minetest.localplayer:hud_change(huds[key], "text", image_press[key])
before[key] = true
elseif not controls[key] and before[key] then
minetest.localplayer:hud_change(huds[key], "text", image_normal[key])
before[key] = false
end
end
end
end)