Add the "adjustable player detector" node

This commit is contained in:
palige 2015-09-03 18:54:10 +02:00
parent ca782ba995
commit d256885757
5 changed files with 118 additions and 0 deletions

View File

@ -9,6 +9,7 @@ MoreMesecons is a mod for minetest wich add some mesecons items.
### New items
* `Adjustable Blinky plant` : Like a mesecons blinky plant, but... adjustable. Right-click to change the interval.
* `Adjustable Player Detector` : Like a mesecons player detector, but you can change its detection radius by right-click.
* `Craftable Command Block` : A command block with just some commands accepted. The admin can change the accepted command (first line of the init.lua), default "tell". Only "@nearest" can be used in the commands, and the admin can change the maximum distance of "@nearest" (default 8 blocks).
* `Dual Delayer` : If it receives a mesecons signal, port 1 turns on immediatly and port 2 turns on 0.4 seconds later. At the end of the signal, port 2 turns off immediatly and port 1 turns off 0.4 secondes later. For example, this is useful for double extenders.
* `Player Killer` : This block kills the nearest player (with a maximal distance of 8 blocks by default) (if this player isn't its owner) when it receives a mesecons signal.

View File

@ -0,0 +1 @@
mesecons

View File

@ -0,0 +1,116 @@
-- Adjustable Player Detector
-- Detects players in a certain radius
-- The radius can be changes by right-click (by default 6)
local object_detector_make_formspec = function (pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "size[9,5]" ..
"field[0.3, 0;9,2;scanname;Name of player to scan for (empty for any):;${scanname}]"..
"field[0.3,1.5;4,2;digiline_channel;Digiline Channel (optional):;${digiline_channel}]"..
"field[0.3,3;2,2;radius;Detection radius:;${radius}]"..
"button_exit[3.5,3.5;2,3;;Save]")
end
local object_detector_on_receive_fields = function(pos, formname, fields)
if not fields.scanname or not fields.digiline_channel then return end;
local meta = minetest.get_meta(pos)
meta:set_string("scanname", fields.scanname)
meta:set_string("digiline_channel", fields.digiline_channel)
if tonumber(fields.radius) then meta:set_int("radius", tonumber(fields.radius)) end
object_detector_make_formspec(pos)
end
-- returns true if player was found, false if not
local object_detector_scan = function (pos)
local meta = minetest.get_meta(pos)
local radius = meta:get_int("radius")
if radius == 0 then radius = 6 end
local objs = minetest.get_objects_inside_radius(pos, radius)
for k, obj in pairs(objs) do
local isname = obj:get_player_name() -- "" is returned if it is not a player; "" ~= nil!
local scanname = meta:get_string("scanname")
if (isname == scanname and isname ~= "") or (isname ~= "" and scanname == "") then -- player with scanname found or not scanname specified
return true
end
end
return false
end
-- set player name when receiving a digiline signal on a specific channel
local object_detector_digiline = {
effector = {
action = function (pos, node, channel, msg)
local meta = minetest.get_meta(pos)
local active_channel = meta:get_string("digiline_channel")
if channel == active_channel then
meta:set_string("scanname", msg)
object_detector_make_formspec(pos)
end
end,
}
}
minetest.register_node("moremesecons_adjustable_player_detector:player_detector_off", {
tiles = {"default_steel_block.png", "default_steel_block.png", "moremesecons_player_detector_off.png", "moremesecons_player_detector_off.png", "moremesecons_player_detector_off.png", "moremesecons_player_detector_off.png"},
paramtype = "light",
walkable = true,
groups = {cracky=3},
description="Adjustable Player Detector",
mesecons = {receptor = {
state = mesecon.state.off,
rules = mesecon.rules.pplate
}},
on_construct = object_detector_make_formspec,
on_receive_fields = object_detector_on_receive_fields,
sounds = default.node_sound_stone_defaults(),
digiline = object_detector_digiline
})
minetest.register_node("moremesecons_adjustable_player_detector:player_detector_on", {
tiles = {"default_steel_block.png", "default_steel_block.png", "moremesecons_player_detector_on.png", "moremesecons_player_detector_on.png", "moremesecons_player_detector_on.png", "moremesecons_player_detector_on.png"},
paramtype = "light",
walkable = true,
groups = {cracky=3,not_in_creative_inventory=1},
drop = 'mesecons_detector:object_detector_off',
mesecons = {receptor = {
state = mesecon.state.on,
rules = mesecon.rules.pplate
}},
on_construct = object_detector_make_formspec,
on_receive_fields = object_detector_on_receive_fields,
sounds = default.node_sound_stone_defaults(),
digiline = object_detector_digiline
})
minetest.register_craft({
output = 'moremesecons_player_detector:player_detector_off',
recipe = {
{"mesecons_detector:object_detector_off"},
{"default:mese_crystal_fragment"}
}
})
minetest.register_abm(
{nodenames = {"moremesecons_adjustable_player_detector:player_detector_off"},
interval = 1.0,
chance = 1,
action = function(pos)
if object_detector_scan(pos) then
minetest.swap_node(pos, {name = "moremesecons_adjustable_player_detector:player_detector_on"})
mesecon.receptor_on(pos, mesecon.rules.pplate)
end
end,
})
minetest.register_abm(
{nodenames = {"moremesecons_adjustable_player_detector:player_detector_on"},
interval = 1.0,
chance = 1,
action = function(pos)
if not object_detector_scan(pos) then
minetest.swap_node(pos, {name = "moremesecons_adjustable_player_detector:player_detector_off"})
mesecon.receptor_off(pos, mesecon.rules.pplate)
end
end,
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 714 B