]> git.lizzy.rs Git - Crafter.git/blob - mods/redstone/player_detector.lua
8c0cb359b461f5ebaa502f339aaf18e5fa5cd10e
[Crafter.git] / mods / redstone / player_detector.lua
1 --detects players and outputs accordingly
2 for i = 0,9  do
3 minetest.register_node("redstone:player_detector_"..i, {
4         description = "Redstone Player Detector",
5         --inventory_image = "redstone_torch.png",
6         --wield_image = "redstone_torch.png",
7         --wield_scale = {x = 1, y = 1, z = 1 + 2/16},
8         drawtype = "normal",
9         tiles = {"player_detector.png"},
10         paramtype = "light",
11         paramtype2 = "none",
12         power = 9,
13         --sunlight_propagates = true,
14         drop = "redstone:player_detector_0",
15         --walkable = false,
16         light_source = i,
17         groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4, torch=1,redstone=1,redstone_torch=1,redstone_power=i, redstone_player_detection = 1},
18         legacy_wallmounted = true,
19         
20         on_construct = function(pos)
21                 redstone.collect_info(pos)
22         end,
23         after_destruct = function(pos, oldnode)
24                 redstone.collect_info(pos)
25         end,
26         sounds = main.stoneSound(),
27 })
28 end
29
30 minetest.register_abm{
31     label = "Redstone Player Detection",
32         nodenames = {"group:redstone_player_detection"},
33         --neighbors = {"group:water"},
34         interval = 0.2,
35         chance = 1,
36         action = function(pos)
37                 local found_player = false
38                 for _,object in ipairs(minetest.get_objects_inside_radius(pos, 9)) do
39                         if object:is_player() and object:get_hp() > 0 then
40                                 local level = minetest.get_node_group(minetest.get_node(pos).name, "redstone_power")
41                                 found_player = true
42                                 local pos2 = object:get_pos()
43                                 local distance = math.floor(vector.distance(pos2,pos))
44                                 distance = math.abs(distance - 9)
45                                 if level ~= distance then
46                                         minetest.set_node(pos,{name="redstone:player_detector_"..distance})
47                                         redstone.collect_info(pos)
48                                         --print(distance)
49                                 end
50                         end
51                 end
52                 if found_player == false then
53                         minetest.set_node(pos,{name="redstone:player_detector_0"})
54                         redstone.collect_info(pos)
55                 end
56         end,
57 }