60 lines
1.4 KiB
Lua
60 lines
1.4 KiB
Lua
local update_formspec = function(meta)
|
|
local amount = meta:get_int("amount")
|
|
meta:set_string("infotext", "Set score block: " .. amount .. " points")
|
|
|
|
meta:set_string("formspec", "size[8,2;]" ..
|
|
-- col 1
|
|
"field[0.2,0.5;8,1;amount;Amount;" .. amount .. "]" ..
|
|
|
|
-- col 2
|
|
"button_exit[0.1,1.5;8,1;save;Save]" ..
|
|
"")
|
|
end
|
|
|
|
minetest.register_node("epic_score:set", {
|
|
description = "Epic score set block",
|
|
tiles = {
|
|
"epic_node_bg.png",
|
|
"epic_node_bg.png",
|
|
"epic_node_bg.png",
|
|
"epic_node_bg.png",
|
|
"epic_node_bg.png",
|
|
"epic_node_bg.png^epic_dollar.png",
|
|
},
|
|
paramtype2 = "facedir",
|
|
groups = {cracky=3,oddly_breakable_by_hand=3,epic=1},
|
|
on_rotate = screwdriver.rotate_simple,
|
|
|
|
on_construct = function(pos)
|
|
local meta = minetest.get_meta(pos)
|
|
meta:set_int("amount", 1)
|
|
update_formspec(meta, pos)
|
|
end,
|
|
|
|
on_receive_fields = function(pos, _, fields, sender)
|
|
local meta = minetest.get_meta(pos);
|
|
|
|
if not sender or minetest.is_protected(pos, sender:get_player_name()) then
|
|
-- not allowed
|
|
return
|
|
end
|
|
|
|
if fields.save then
|
|
local amount = tonumber(fields.amount or "1")
|
|
meta:set_int("amount", amount)
|
|
update_formspec(meta, pos)
|
|
end
|
|
|
|
end,
|
|
|
|
epic = {
|
|
on_enter = function(_, meta, player, ctx)
|
|
local player_meta = player:get_meta()
|
|
local amount = meta:get_int("amount")
|
|
player_meta:set_int("epic_score", amount)
|
|
|
|
ctx.next()
|
|
end
|
|
}
|
|
})
|