1
0
forked from MTSR/mapserver

complete mapserver objects

This commit is contained in:
NatureFreshMilk 2019-01-24 14:13:24 +01:00
parent 1648f28d3e
commit 25dac69598
6 changed files with 224 additions and 1 deletions

View File

@ -1 +1,2 @@
default default
digiline?

View File

@ -0,0 +1,107 @@
local update_formspec = function(meta)
local inv = meta:get_inventory()
local active = meta:get_int("active") == 1
local state = "Inactive"
if active then
state = "Active"
end
local channel = meta:get_string("channel")
local message = meta:get_string("message")
meta:set_string("infotext", "Digimessage: Channel=" .. channel .. ", Message=" .. message .. " (" .. state .. ")")
meta:set_string("formspec", "size[8,2;]" ..
-- col 1
"field[0,1;8,1;channel;Channel;" .. channel .. "]" ..
-- col 3
"button_exit[0,2;4,1;save;Save]" ..
"button_exit[4,2;4,1;toggle;Toggle]" ..
"")
end
minetest.register_node("mapserver:digimessage", {
description = "Mapserver Digiline Message",
tiles = {
"tileserver_digimessage.png",
"tileserver_digimessage.png",
"tileserver_digimessage.png",
"tileserver_digimessage.png",
"tileserver_digimessage.png",
"tileserver_digimessage.png"
},
groups = {cracky=3,oddly_breakable_by_hand=3},
sounds = default.node_sound_glass_defaults(),
digiline = {
receptor = {action = function() end},
effector = {
action = function(pos, _, channel, msg)
local meta = minetest.env:get_meta(pos)
local set_channel = meta:get_string("channel")
if channel == set_channel and type(msg) == "string" then
meta:set_string("message", msg)
end
end
},
},
can_dig = function(pos, player)
local meta = minetest.env:get_meta(pos)
local owner = meta:get_string("owner")
return player and player:get_player_name() == owner
end,
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name() or "")
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
last_index = last_index + 5
meta:set_string("channel", "digimessage")
meta:set_string("message", "")
meta:set_int("active", 1)
update_formspec(meta)
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
local playername = sender:get_player_name()
if playername == meta:get_string("owner") then
-- owner
if fields.save then
last_line = fields.line
meta:set_string("channel", fields.channel)
end
if fields.toggle then
if meta:get_int("active") == 1 then
meta:set_int("active", 0)
else
meta:set_int("active", 1)
end
end
else
-- non-owner
end
update_formspec(meta)
end
})

View File

@ -3,7 +3,14 @@ mapserver = {
} }
local MP = minetest.get_modpath("mapserver") local MP = minetest.get_modpath("mapserver")
local has_digiline_mod = minetest.get_modpath("digiline")
dofile(MP.."/poi.lua") dofile(MP.."/poi.lua")
dofile(MP.."/train.lua")
print("[OK] Mapserver mod") if has_digiline_mod then
dofile(MP.."/digimessage.lua")
end
print("[OK] Mapserver")

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

View File

@ -0,0 +1,108 @@
local last_index = 0
local last_line = ""
local update_formspec = function(meta)
local inv = meta:get_inventory()
local active = meta:get_int("active") == 1
local state = "Inactive"
if active then
state = "Active"
end
local line = meta:get_string("line")
local station = meta:get_string("station")
local index = meta:get_string("index")
meta:set_string("infotext", "Train: Line=" .. line .. ", Station=" .. station .. " (" .. state .. ")")
meta:set_string("formspec", "size[8,3;]" ..
-- col 1
"field[0,1;4,1;line;Line;" .. line .. "]" ..
"button_exit[4,1;4,1;save;Save]" ..
-- col 2
"field[0,2.5;4,1;station;Station;" .. station .. "]" ..
"field[4,2.5;4,1;index;Index;" .. index .. "]" ..
-- col 3
"button_exit[4,3;4,1;toggle;Toggle]" ..
"")
end
minetest.register_node("mapserver:train", {
description = "Mapserver Train",
tiles = {
"tileserver_train.png",
"tileserver_train.png",
"tileserver_train.png",
"tileserver_train.png",
"tileserver_train.png",
"tileserver_train.png"
},
groups = {cracky=3,oddly_breakable_by_hand=3},
sounds = default.node_sound_glass_defaults(),
can_dig = function(pos, player)
local meta = minetest.env:get_meta(pos)
local owner = meta:get_string("owner")
return player and player:get_player_name() == owner
end,
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name() or "")
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
last_index = last_index + 5
meta:set_string("station", "")
meta:set_string("line", last_line)
meta:set_int("active", 1)
meta:set_int("index", last_index)
update_formspec(meta)
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
local playername = sender:get_player_name()
if playername == meta:get_string("owner") then
-- owner
if fields.save then
last_line = fields.line
meta:set_string("line", fields.line)
meta:set_string("station", fields.station)
local index = tonumber(fields.index)
if index ~= nil then
last_index = index
meta:set_int("index", index)
end
end
if fields.toggle then
if meta:get_int("active") == 1 then
meta:set_int("active", 0)
else
meta:set_int("active", 1)
end
end
else
-- non-owner
end
update_formspec(meta)
end
})