mirror of
https://cheapiesystems.com/git/digistuff
synced 2024-11-25 00:24:00 +01:00
Add player detector
This commit is contained in:
parent
01d72237c3
commit
edd47f6239
5
README
5
README
@ -20,3 +20,8 @@ Note that the settings cannot be changed after setting - you must dig and re-pla
|
||||
|
||||
How to use digimese:
|
||||
It conducts digilines signals (like digilines) in all directions (like mese). That's about it, really.
|
||||
|
||||
|
||||
How to use the digilines player detector:
|
||||
Set a channel and radius (radius must be a number >0 and <10 - anything invalid will be ignored and "6" useid instead).
|
||||
Every second while a player is within the radius, a table listing the players in range will be sent via digilines on the chosen channel.
|
||||
|
57
init.lua
57
init.lua
@ -183,4 +183,61 @@ minetest.register_alias("digibutton:button_off","digistuff:button_off")
|
||||
minetest.register_alias("digibutton:button_on","digistuff:button_on")
|
||||
minetest.register_alias("digibutton:digimese","digistuff:digimese")
|
||||
|
||||
minetest.register_node("digistuff:detector", {
|
||||
tiles = {
|
||||
"digistuff_digidetector.png"
|
||||
},
|
||||
digiline =
|
||||
{
|
||||
receptor = {}
|
||||
},
|
||||
groups = {cracky=2},
|
||||
description = "Digilines Player Detector",
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec","size[8,4;]field[1,1;6,2;channel;Channel;${channel}]field[1,2;6,2;radius;Radius;${radius}]button_exit[2.25,3;3,1;submit;Save]")
|
||||
end,
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if fields.channel then meta:set_string("channel",fields.channel) end
|
||||
if fields.msg then meta:set_string("msg",fields.msg) end
|
||||
if fields.radius then meta:set_string("radius",fields.radius) end
|
||||
end,
|
||||
sounds = default.node_sound_stone_defaults()
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"digistuff:detector"},
|
||||
interval = 1.0,
|
||||
chance = 1,
|
||||
action = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local channel = meta:get_string("channel")
|
||||
local radius = meta:get_string("radius")
|
||||
local found_any = false
|
||||
local players_found = {}
|
||||
if not radius or not tonumber(radius) or tonumber(radius) < 1 or tonumber(radius) > 10 then radius = 6 end
|
||||
local objs = minetest.get_objects_inside_radius(pos, radius)
|
||||
if objs then
|
||||
local _,obj
|
||||
for _,obj in ipairs(objs) do
|
||||
if obj:is_player() then
|
||||
table.insert(players_found,obj:get_player_name())
|
||||
found_any = true
|
||||
end
|
||||
end
|
||||
if found_any then
|
||||
digiline:receptor_send(pos, digiline.rules.default, channel, players_found)
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "digistuff:detector",
|
||||
recipe = {
|
||||
{"mesecons_detector:object_detector_off"},
|
||||
{"mesecons_luacontroller:luacontroller0000"},
|
||||
{"digilines:wire_std_00000000"}
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user