Improve player detector wrench menu

This commit is contained in:
Joachim Stolberg 2022-12-10 12:38:15 +01:00
parent ac01df763d
commit 4cb7ffe718
5 changed files with 60 additions and 12 deletions

View File

@ -128,9 +128,15 @@ TA4 Button/Switch=TA4 Schalter/Taster
Access=Zugriff
Button protection=Tastenschutz
Type=Typ
### button.lua ###
### button_2x.lua ###
### button_4x.lua ###
### player_detector.lua ###
Command=Kommando
Number=Nummer
Type=Typ
### button.lua ###
### cart_detector.lua ###
@ -163,10 +169,15 @@ TA4 2x Button=TA4 2x Taster
### button_4x.lua ###
Command to be sent (ignored for switches)=Zu sendender Befehl (wird für Schalter ignoriert)
Destination block number=Zielblocknummer
Label for the button=Beschriftung für die Taste
Momentary button or on/off switch=Taster oder Ein-/Ausschalter
### button_2x.lua ###
### button_4x.lua ###
### player_detector.lua ###
Destination block number=Zielblocknummer
### button_2x.lua ###
### button_4x.lua ###
### signallamp_2x.lua ###
@ -961,6 +972,8 @@ Plastic Granules=Plastikgranulat
### player_detector.lua ###
Command to send when player is detected=Befehl zum Senden, wenn ein Spieler erkannt wird
Command to send when player moves away=Befehl zum Senden, wenn sich der Spieler wegbewegt
Radius=Radius
Search radius=Suchradius
TA4 Player Detector=TA4 Spieler Detektor

View File

@ -128,9 +128,15 @@ TA4 Button/Switch=
Access=
Button protection=
Type=
### button.lua ###
### button_2x.lua ###
### button_4x.lua ###
### player_detector.lua ###
Command=
Number=
Type=
### button.lua ###
### cart_detector.lua ###
@ -163,10 +169,15 @@ TA4 2x Button=
### button_4x.lua ###
Command to be sent (ignored for switches)=
Destination block number=
Label for the button=
Momentary button or on/off switch=
### button_2x.lua ###
### button_4x.lua ###
### player_detector.lua ###
Destination block number=
### button_2x.lua ###
### button_4x.lua ###
### signallamp_2x.lua ###
@ -961,6 +972,8 @@ Plastic Granules=
### player_detector.lua ###
Command to send when player is detected=
Command to send when player moves away=
Radius=
Search radius=
TA4 Player Detector=

View File

@ -68,10 +68,7 @@ local function switch_on(pos)
elseif name == "techage:ta4_button_off" then
logic.swap_node(pos, "techage:ta4_button_on")
end
local meta = M(pos)
local s = meta:contains("command") and meta:get_string("command") or "on"
local command, payload = unpack(string.split(s, " ", false, 1))
logic.send_cmnd(pos, M(pos), command, payload, cycle_time)
logic.send_cmnd(pos, "command", "on", cycle_time)
minetest.sound_play("techage_button", {
pos = pos,
gain = 0.5,

View File

@ -67,13 +67,16 @@ function techage.logic.send_on(pos, meta, time)
return own_num == numbers
end
function techage.logic.send_cmnd(pos, meta, cmnd, payload, time)
function techage.logic.send_cmnd(pos, ident, default, time)
local meta = M(pos)
local s = meta:contains(ident) and meta:get_string(ident) or default
local command, payload = unpack(string.split(s, " ", false, 1))
local own_num = meta:get_string("node_number") or ""
local numbers = meta:get_string("numbers") or ""
if time and time > 0 then
minetest.get_node_timer(pos):start(time)
end
techage.send_multi(own_num, numbers, cmnd, payload)
techage.send_multi(own_num, numbers, command, payload)
end
function techage.logic.send_off(pos, meta)

View File

@ -29,17 +29,39 @@ local WRENCH_MENU = {
tooltip = S("Search radius"),
default = "4",
},
{
type = "numbers",
name = "numbers",
label = S("Number"),
tooltip = S("Destination block number"),
default = "",
check = techage.check_numbers,
},
{
type = "ascii",
name = "command1",
label = "On " .. S("Command"),
tooltip = S("Command to send when player is detected"),
default = "on",
},
{
type = "ascii",
name = "command2",
label = "Off " .. S("Command"),
tooltip = S("Command to send when player moves away"),
default = "off",
},
}
local function switch_on(pos, stage)
if logic.swap_node(pos, "techage:ta"..stage.."_playerdetector_on") then
logic.send_on(pos, M(pos))
logic.send_cmnd(pos, "command1", "on")
end
end
local function switch_off(pos, stage)
if logic.swap_node(pos, "techage:ta"..stage.."_playerdetector_off") then
logic.send_off(pos, M(pos))
logic.send_cmnd(pos, "command2", "off")
end
end