From 9395013cde0c05677b841ac4db5e1b45b71147b1 Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Sun, 28 May 2023 04:49:25 +0200 Subject: [PATCH] Support setting teleport tube `can_receive` by digilines (#68) * allow setting can_receive flag by digilines basically also allows sending tables to change both or either the tp-channel and receive toggle * apply suggestions Co-authored-by: OgelGames --------- Co-authored-by: OgelGames --- teleport_tube.lua | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/teleport_tube.lua b/teleport_tube.lua index 2a87610..e888333 100644 --- a/teleport_tube.lua +++ b/teleport_tube.lua @@ -270,14 +270,29 @@ local function repair_tube(pos, node) update_meta(meta) end -local function digiline_action(pos, _, channel, msg) +local function digiline_action(pos, _, digiline_channel, msg) local meta = minetest.get_meta(pos) - if channel ~= meta:get_string("digiline_channel") or type(msg) ~= "string" then + if digiline_channel ~= meta:get_string("digiline_channel") then return end - local name = meta:get_string("owner") - local cr = meta:get_int("can_receive") - update_tube(pos, msg, cr, name) + local channel = meta:get_string("channel") + local can_receive = meta:get_int("can_receive") + if type(msg) == "string" then + channel = msg + elseif type(msg) == "table" then + if type(msg.channel) == "string" then + channel = msg.channel + end + if msg.can_receive == 1 or msg.can_receive == true then + can_receive = 1 + elseif msg.can_receive == 0 or msg.can_receive == false then + can_receive = 0 + end + else + return + end + local player_name = meta:get_string("owner") + update_tube(pos, channel, can_receive, player_name) update_meta(meta) end