mirror of
https://github.com/minetest-mods/MoreMesecons.git
synced 2025-01-09 17:30:24 +01:00
change a bit more code
meta:get_string isn't nil, and minetest. Swap node keeps meta l think
This commit is contained in:
parent
1b68f9b8ce
commit
e0a29b1027
@ -27,9 +27,6 @@ local function object_detector_on_receive_fields(pos, formname, fields)
|
||||
if r then
|
||||
meta:set_int("radius", r)
|
||||
end
|
||||
if not meta:get_string("formspec") then
|
||||
make_formspec(meta)
|
||||
end
|
||||
end
|
||||
|
||||
-- returns true if player was found, false if not
|
||||
@ -61,7 +58,7 @@ local object_detector_digiline = {
|
||||
return
|
||||
end
|
||||
meta:set_string("scanname", msg)
|
||||
if not meta:get_string("formspec") then
|
||||
if meta:get_string("formspec") ~= "" then
|
||||
make_formspec(meta)
|
||||
end
|
||||
end,
|
||||
@ -69,7 +66,7 @@ local object_detector_digiline = {
|
||||
}
|
||||
|
||||
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"},
|
||||
tiles = {"default_steel_block.png", "default_steel_block.png", "moremesecons_player_detector_off.png"},
|
||||
paramtype = "light",
|
||||
walkable = true,
|
||||
groups = {cracky=3},
|
||||
@ -85,7 +82,7 @@ minetest.register_node("moremesecons_adjustable_player_detector:player_detector_
|
||||
})
|
||||
|
||||
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"},
|
||||
tiles = {"default_steel_block.png", "default_steel_block.png", "moremesecons_player_detector_on.png"},
|
||||
paramtype = "light",
|
||||
walkable = true,
|
||||
groups = {cracky=3,not_in_creative_inventory=1},
|
||||
@ -108,8 +105,8 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_abm(
|
||||
{nodenames = {"moremesecons_adjustable_player_detector:player_detector_off"},
|
||||
minetest.register_abm({
|
||||
nodenames = {"moremesecons_adjustable_player_detector:player_detector_off"},
|
||||
interval = 1.0,
|
||||
chance = 1,
|
||||
action = function(pos)
|
||||
@ -120,8 +117,8 @@ minetest.register_abm(
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_abm(
|
||||
{nodenames = {"moremesecons_adjustable_player_detector:player_detector_on"},
|
||||
minetest.register_abm({
|
||||
nodenames = {"moremesecons_adjustable_player_detector:player_detector_on"},
|
||||
interval = 1.0,
|
||||
chance = 1,
|
||||
action = function(pos)
|
||||
|
@ -1,24 +1,22 @@
|
||||
local MAX_DISTANCE = 8
|
||||
|
||||
local sayer_activate = function(pos)
|
||||
local players = minetest.get_connected_players()
|
||||
local text = minetest.get_meta(pos):get_string("text")
|
||||
for index, player in pairs(players) do
|
||||
local distance = vector.distance(pos, player:getpos())
|
||||
if distance <= MAX_DISTANCE then
|
||||
minetest.chat_send_player(player:get_player_name(), "Sayer at pos "
|
||||
..tostring(pos.x)..","
|
||||
..tostring(pos.y)..","
|
||||
..tostring(pos.z)
|
||||
.." says : "
|
||||
..text)
|
||||
local function sayer_activate(pos)
|
||||
local tab = {
|
||||
"Sayer at pos",
|
||||
nil,
|
||||
"says : "..minetest.get_meta(pos):get_string("text")
|
||||
}
|
||||
for _,player in pairs(minetest.get_connected_players()) do
|
||||
if vector.distance(pos, player:getpos()) <= MAX_DISTANCE then
|
||||
tab[2] = minetest.pos_to_string(pos)
|
||||
minetest.chat_send_player(player:get_player_name(), table.concat(tab, " "))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("moremesecons_sayer:sayer", {
|
||||
description = "sayer",
|
||||
tiles = {"mesecons_noteblock.png", "default_wood.png", "default_wood.png", "default_wood.png", "default_wood.png", "default_wood.png"},
|
||||
tiles = {"mesecons_noteblock.png", "default_wood.png"},
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
node_box = {
|
||||
@ -27,12 +25,12 @@ minetest.register_node("moremesecons_sayer:sayer", {
|
||||
},
|
||||
groups = {dig_immediate = 2},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec", "field[text;text;${text}]")
|
||||
minetest.get_meta(pos):set_string("formspec", "field[text;text;${text}]")
|
||||
end,
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("text", fields.text)
|
||||
on_receive_fields = function(pos, _, fields)
|
||||
if fields.text then
|
||||
minetest.get_meta(pos):set_string("text", fields.text)
|
||||
end
|
||||
end,
|
||||
mesecons = {effector = {
|
||||
action_on = sayer_activate
|
||||
|
@ -16,18 +16,20 @@ end
|
||||
|
||||
-- Functions that are called after the delay time
|
||||
|
||||
local temporarygate_activate = function(pos, node)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
local meta = minetest.get_meta(pos)
|
||||
local time = tonumber(meta:get_string("time"))
|
||||
if time ~= nil then
|
||||
minetest.swap_node(pos, {name = "moremesecons_temporarygate:temporarygate_on", param2 = node.param2})
|
||||
local function temporarygate_activate(pos, node)
|
||||
-- using a meta string allows writing the time in hexadecimals
|
||||
local time = tonumber(minetest.get_meta(pos):get_string("time"))
|
||||
if not time then
|
||||
return
|
||||
end
|
||||
node.name = "moremesecons_temporarygate:temporarygate_on"
|
||||
minetest.swap_node(pos, node)
|
||||
mesecon.receptor_on(pos)
|
||||
minetest.after(time, function(pos, node)
|
||||
mesecon.receptor_off(pos)
|
||||
minetest.swap_node(pos, {name = "moremesecons_temporarygate:temporarygate_off", param2 = node.param2})
|
||||
node.name = "moremesecons_temporarygate:temporarygate_off"
|
||||
minetest.swap_node(pos, node)
|
||||
end, pos, node)
|
||||
end
|
||||
end
|
||||
|
||||
boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab
|
||||
@ -62,12 +64,12 @@ mesecon.register_node("moremesecons_temporarygate:temporarygate", {
|
||||
is_ground_content = true,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec", "field[time;time;${time}]")
|
||||
minetest.get_meta(pos):set_string("formspec", "field[time;time;${time}]")
|
||||
end,
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("time", fields.time)
|
||||
if fields.time then
|
||||
minetest.get_meta(pos):set_string("time", fields.time)
|
||||
end
|
||||
end
|
||||
},{
|
||||
tiles = {
|
||||
|
Loading…
Reference in New Issue
Block a user