-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.lua
69 lines (59 loc) · 2.59 KB
/
util.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
--for lack of a better name...
local player_alert_status = {}
local function handle_player_entry_event(player, node_pos)
local node_name = minetest.get_node(node_pos).name
if(node_name == "block_alert:notifier") then
notifier.handle_player_event(player, node_pos, "entered")
elseif node_name == "block_alert:recorder" then
recorder.handle_player_event(player,node_pos,"entered")
end
end
local function handle_player_exit_event(player, node_pos)
local node_name = minetest.get_node(node_pos).name
if(node_name == "block_alert:notifier") then
notifier.handle_player_event(player, node_pos, "exited")
elseif node_name == "block_alert:recorder" then
recorder.handle_player_event(player,node_pos,"exited")
end
end
function util.check_permission(pos, pname)
local reinf = ct.get_reinforcement(pos)
if reinf then
local player_id = pm.get_player_by_name(pname).id
if pm.get_player_group(player_id, reinf.ctgroup_id) then return true else return false end
else return true
end
return false
end
function util.find_nodes(center_pos, search_radius, block_type)
local bound1 = vector.subtract(center_pos, {x = search_radius, y=search_radius , z= search_radius})
local bound2 = vector.add(center_pos, {x = search_radius, y=search_radius , z= search_radius})
local nodeList = minetest.find_nodes_in_area(bound1, bound2, block_type)
return nodeList
end
function util.check_new_player_move(player)
local player_name = player:get_player_name()
local old_alert_list = player_alert_status[player_name]
if old_alert_list == nil then old_alert_list = {} end
local new_alert_list = util.find_nodes(player:get_pos(), 5, {"block_alert:notifier","block_alert:recorder"})
local lookup_table_new = {}
local lookup_table_old = {}
for _, node_pos in pairs(new_alert_list) do
local string_pos = minetest.pos_to_string(node_pos)
lookup_table_new[string_pos] = true
end
for _, node_pos in pairs(old_alert_list) do
local string_pos = minetest.pos_to_string(node_pos)
if(lookup_table_new[string_pos]==nil) then
handle_player_exit_event(player, node_pos)
end
lookup_table_old[string_pos] = true
end
for _, node_pos in pairs(new_alert_list) do
local string_pos = minetest.pos_to_string(node_pos)
if(lookup_table_old[string_pos]==nil) then
handle_player_entry_event(player, node_pos)
end
end
player_alert_status[player_name] = new_alert_list
end