2019-08-28 23:47:53 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2020-01-31 21:55:10 +03:00
|
|
|
Copyright (C) 2017-2020 Joachim Stolberg
|
2019-08-28 23:47:53 +03:00
|
|
|
|
2020-10-19 20:09:17 +03:00
|
|
|
AGPL v3
|
2019-08-28 23:47:53 +03:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
2020-03-16 01:50:15 +03:00
|
|
|
TA3 & TA4 Player Detector
|
2019-08-28 23:47:53 +03:00
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local M = minetest.get_meta
|
|
|
|
local S = techage.S
|
2020-03-16 01:50:15 +03:00
|
|
|
local NDEF = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}) end
|
2019-08-28 23:47:53 +03:00
|
|
|
|
|
|
|
local logic = techage.logic
|
|
|
|
local CYCLE_TIME = 1
|
|
|
|
|
2020-03-16 01:50:15 +03:00
|
|
|
local function switch_on(pos, stage)
|
|
|
|
if logic.swap_node(pos, "techage:ta"..stage.."_playerdetector_on") then
|
2019-08-28 23:47:53 +03:00
|
|
|
logic.send_on(pos, M(pos))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-16 01:50:15 +03:00
|
|
|
local function switch_off(pos, stage)
|
|
|
|
if logic.swap_node(pos, "techage:ta"..stage.."_playerdetector_off") then
|
2019-08-28 23:47:53 +03:00
|
|
|
logic.send_off(pos, M(pos))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function scan_for_player(pos)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2019-08-28 23:47:53 +03:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local names = meta:get_string("names") or ""
|
|
|
|
for _, object in pairs(minetest.get_objects_inside_radius(pos, 4)) do
|
|
|
|
if object:is_player() then
|
|
|
|
if names == "" then
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.player_name = object:get_player_name()
|
2019-08-28 23:47:53 +03:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
for _,name in ipairs(string.split(names, " ")) do
|
|
|
|
if object:get_player_name() == name then
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.player_name = name
|
2019-08-28 23:47:53 +03:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.player_name = nil
|
2019-08-28 23:47:53 +03:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local function formspec_help()
|
|
|
|
return "size[8,6]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
"label[3,0;Player Detector Help]"..
|
|
|
|
"label[0,1;Input the number(s) of the destination node(s).\n"..
|
|
|
|
"Separate numbers via blanks, like '123 234'.\n\n"..
|
|
|
|
"Input the player name(s) separated by blanks,\nor empty for all players.]"..
|
|
|
|
"button_exit[3,5;2,1;exit;close]"
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function formspec(meta)
|
|
|
|
local numbers = meta:get_string("numbers") or ""
|
|
|
|
local names = meta:get_string("names") or ""
|
|
|
|
return "size[7,4]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
"field[0.3,0.6;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
|
|
|
|
"field[0.3,2;7,1;names;Insert player name(s) (optional):;"..names.."]" ..
|
|
|
|
"button[0.9,3;2.5,1;help;help]"..
|
|
|
|
"button_exit[3.5,3;2.5,1;exit;Save]"
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_receive_fields(pos, formname, fields, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if fields.exit == "Save" then
|
|
|
|
if techage.check_numbers(fields.numbers, player:get_player_name()) then
|
|
|
|
meta:set_string("numbers", fields.numbers)
|
2020-03-16 01:50:15 +03:00
|
|
|
logic.infotext(M(pos), NDEF(pos).description)
|
2019-08-28 23:47:53 +03:00
|
|
|
end
|
2019-09-26 23:32:37 +03:00
|
|
|
meta:set_string("names", fields.names)
|
2019-08-28 23:47:53 +03:00
|
|
|
meta:set_string("formspec", formspec(meta))
|
|
|
|
elseif fields.help ~= nil then
|
|
|
|
meta:set_string("formspec", formspec_help())
|
|
|
|
elseif fields.exit == "close" then
|
|
|
|
meta:set_string("formspec", formspec(meta))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("techage:ta3_playerdetector_off", {
|
|
|
|
description = S("TA3 Player Detector"),
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta3.png^techage_frame_ta3_top.png",
|
|
|
|
"techage_filling_ta3.png^techage_frame_ta3_top.png",
|
|
|
|
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_playerdetector.png",
|
|
|
|
},
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = M(pos)
|
|
|
|
logic.after_place_node(pos, placer, "techage:ta3_playerdetector_off", S("TA3 Player Detector"))
|
|
|
|
logic.infotext(meta, S("TA3 Player Detector"))
|
|
|
|
meta:set_string("formspec", formspec(meta))
|
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_receive_fields = on_receive_fields,
|
|
|
|
|
|
|
|
on_timer = function (pos, elapsed)
|
|
|
|
if scan_for_player(pos) then
|
2020-03-16 01:50:15 +03:00
|
|
|
switch_on(pos, 3)
|
2019-08-28 23:47:53 +03:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
|
|
|
|
techage_set_numbers = function(pos, numbers, player_name)
|
|
|
|
local meta = M(pos)
|
|
|
|
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Player Detector"))
|
|
|
|
meta:set_string("formspec", formspec(meta))
|
|
|
|
return res
|
|
|
|
end,
|
|
|
|
|
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
2020-06-14 00:32:00 +03:00
|
|
|
techage.remove_node(pos, oldnode, oldmetadata)
|
2020-01-31 21:55:10 +03:00
|
|
|
techage.del_mem(pos)
|
2019-08-28 23:47:53 +03:00
|
|
|
end,
|
|
|
|
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2},
|
|
|
|
is_ground_content = false,
|
2020-03-16 01:50:15 +03:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2019-08-28 23:47:53 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("techage:ta3_playerdetector_on", {
|
|
|
|
description = "TA3 Player Detector",
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta3.png^techage_frame_ta3_top.png",
|
|
|
|
"techage_filling_ta3.png^techage_frame_ta3_top.png",
|
|
|
|
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_playerdetector_on.png",
|
|
|
|
},
|
|
|
|
on_receive_fields = on_receive_fields,
|
|
|
|
|
|
|
|
on_timer = function (pos, elapsed)
|
|
|
|
if not scan_for_player(pos) then
|
2020-03-16 01:50:15 +03:00
|
|
|
switch_off(pos, 3)
|
2019-08-28 23:47:53 +03:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
|
|
|
|
techage_set_numbers = function(pos, numbers, player_name)
|
|
|
|
local meta = M(pos)
|
|
|
|
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Player Detector"))
|
|
|
|
meta:set_string("formspec", formspec(meta))
|
|
|
|
return res
|
|
|
|
end,
|
|
|
|
|
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
2020-06-14 00:32:00 +03:00
|
|
|
techage.remove_node(pos, oldnode, oldmetadata)
|
2020-01-31 21:55:10 +03:00
|
|
|
techage.del_mem(pos)
|
2019-08-28 23:47:53 +03:00
|
|
|
end,
|
|
|
|
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
drop = "techage:ta3_playerdetector_off"
|
|
|
|
})
|
|
|
|
|
2020-03-16 01:50:15 +03:00
|
|
|
minetest.register_node("techage:ta4_playerdetector_off", {
|
|
|
|
description = S("TA4 Player Detector"),
|
|
|
|
inventory_image = 'techage_smartline_detector_inv.png',
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_smartline.png",
|
|
|
|
"techage_smartline.png",
|
|
|
|
"techage_smartline.png",
|
|
|
|
"techage_smartline.png",
|
|
|
|
"techage_smartline.png",
|
|
|
|
"techage_smartline.png^techage_smartline_detector.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{ -6/32, -6/32, 14/32, 6/32, 6/32, 16/32},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = M(pos)
|
|
|
|
logic.after_place_node(pos, placer, "techage:ta4_playerdetector_off", S("TA4 Player Detector"))
|
|
|
|
logic.infotext(meta, S("TA4 Player Detector"))
|
|
|
|
meta:set_string("formspec", formspec(meta))
|
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_receive_fields = on_receive_fields,
|
|
|
|
|
|
|
|
on_timer = function (pos, elapsed)
|
|
|
|
if scan_for_player(pos) then
|
|
|
|
switch_on(pos, 4)
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
|
|
|
|
techage_set_numbers = function(pos, numbers, player_name)
|
|
|
|
local meta = M(pos)
|
|
|
|
local res = logic.set_numbers(pos, numbers, player_name, S("TA4 Player Detector"))
|
|
|
|
meta:set_string("formspec", formspec(meta))
|
|
|
|
return res
|
|
|
|
end,
|
|
|
|
|
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
2020-06-14 00:32:00 +03:00
|
|
|
techage.remove_node(pos, oldnode, oldmetadata)
|
2020-03-16 01:50:15 +03:00
|
|
|
techage.del_mem(pos)
|
|
|
|
end,
|
|
|
|
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_metal_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("techage:ta4_playerdetector_on", {
|
|
|
|
description = "TA4 Player Detector",
|
|
|
|
inventory_image = 'techage_smartline_detector_inv.png',
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_smartline.png",
|
|
|
|
"techage_smartline.png",
|
|
|
|
"techage_smartline.png",
|
|
|
|
"techage_smartline.png",
|
|
|
|
"techage_smartline.png",
|
|
|
|
"techage_smartline.png^techage_smartline_detector_on.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{ -6/32, -6/32, 14/32, 6/32, 6/32, 16/32},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
on_receive_fields = on_receive_fields,
|
|
|
|
|
|
|
|
on_timer = function (pos, elapsed)
|
|
|
|
if not scan_for_player(pos) then
|
|
|
|
switch_off(pos, 4)
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
|
|
|
|
techage_set_numbers = function(pos, numbers, player_name)
|
|
|
|
local meta = M(pos)
|
|
|
|
local res = logic.set_numbers(pos, numbers, player_name, S("TA4 Player Detector"))
|
|
|
|
meta:set_string("formspec", formspec(meta))
|
|
|
|
return res
|
|
|
|
end,
|
|
|
|
|
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
2020-06-14 00:32:00 +03:00
|
|
|
techage.remove_node(pos, oldnode, oldmetadata)
|
2020-03-16 01:50:15 +03:00
|
|
|
techage.del_mem(pos)
|
|
|
|
end,
|
|
|
|
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_metal_defaults(),
|
|
|
|
drop = "techage:ta4_playerdetector_off"
|
|
|
|
})
|
|
|
|
|
2019-08-28 23:47:53 +03:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:ta3_playerdetector_off",
|
|
|
|
recipe = {
|
|
|
|
{"", "group:wood", "default:mese_crystal"},
|
|
|
|
{"", "default:copper_ingot", "techage:vacuum_tube"},
|
|
|
|
{"", "group:wood", ""},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-03-16 01:50:15 +03:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:ta4_playerdetector_off",
|
|
|
|
recipe = {
|
|
|
|
{"", "techage:aluminum", "dye:blue"},
|
|
|
|
{"", "default:copper_ingot", "techage:ta4_wlanchip"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
techage.register_node({
|
|
|
|
"techage:ta3_playerdetector_off", "techage:ta3_playerdetector_on",
|
|
|
|
"techage:ta4_playerdetector_off", "techage:ta4_playerdetector_on"
|
|
|
|
}, {
|
|
|
|
on_recv_message = function(pos, src, topic, payload)
|
|
|
|
if topic == "name" then
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
return nvm.player_name or ""
|
2020-07-24 19:20:26 +03:00
|
|
|
elseif topic == "state" then
|
|
|
|
local node = techage.get_node_lvm(pos)
|
|
|
|
if node.name == "techage:ta3_playerdetector_on" or
|
|
|
|
node.name == "techage:ta4_playerdetector_on" then
|
|
|
|
return "on"
|
|
|
|
else
|
|
|
|
return "off"
|
|
|
|
end
|
2020-03-16 01:50:15 +03:00
|
|
|
else
|
|
|
|
return "unsupported"
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_node_load = function(pos)
|
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
)
|
2019-08-28 23:47:53 +03:00
|
|
|
|