Repository navigation
Expand file tree
/
Copy pathrds.lua
More file actions
65 lines (56 loc) · 1.83 KB
/
Copy pathrds.lua
File metadata and controls
65 lines (56 loc) · 1.83 KB
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
function ham_radio.get_rds_messages(frequency, is_receiver_station)
local transmitters = ham_radio.find_transmitters(frequency)
local rds_messages = {}
for position, transmitter in pairs(transmitters) do
if transmitter.rds_message ~= "" and transmitter.rds_message ~= nil then
for rds_message_line in transmitter.rds_message:gmatch("[^\n]+") do
-- construct message
local message = table.concat({
'[ Radio | ',
transmitter.operated_by,
' ] ',
rds_message_line,
}, "")
if is_receiver_station then
message = table.concat({
'[ ',
transmitter.operated_by,
' ] ',
rds_message_line
}, "")
end
table.insert(rds_messages, 1, message)
end
end
end
return rds_messages
end
function ham_radio:update_rds(player)
local name = player:get_player_name()
local item = player:get_wielded_item()
if item:get_name() ~= "ham_radio:handheld_receiver" then
return
end
local meta = item:get_meta()
local frequency = meta:get_string("frequency")
local rds_disabled = meta:get_string("rds_disabled")
if frequency == "" then
return
end
if rds_disabled == "true" then
-- disabled receiving RDS messages
ham_radio.player_rds[name] = nil
return
end
if ham_radio.player_rds[name] == nil then
ham_radio.player_rds[name] = ham_radio.get_rds_messages(frequency)
end
local message = table.remove(ham_radio.player_rds[name])
if message ~= nil then
minetest.chat_send_player(player:get_player_name(), minetest.colorize(ham_radio.settings.rds_color, message))
-- when all RDS messages are shown, reload them again
if not next(ham_radio.player_rds[name]) then
ham_radio.player_rds[name] = ham_radio.get_rds_messages(frequency)
end
end
end