2020-03-05 08:18:05 +01:00
|
|
|
local update_formspec = function(meta)
|
2020-03-05 11:44:40 +01:00
|
|
|
local amount = meta:get_int("amount")
|
2020-03-05 08:18:05 +01:00
|
|
|
meta:set_string("infotext", "Add 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:add", {
|
|
|
|
description = "Epic score add 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)
|
2020-03-05 11:44:40 +01:00
|
|
|
meta:set_int("amount", 1)
|
2020-03-05 08:18:05 +01:00
|
|
|
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")
|
2020-03-05 11:44:40 +01:00
|
|
|
meta:set_int("amount", amount)
|
2020-03-05 08:18:05 +01:00
|
|
|
update_formspec(meta, pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
end,
|
|
|
|
|
|
|
|
epic = {
|
|
|
|
on_enter = function(_, meta, player, ctx)
|
|
|
|
local player_meta = player:get_meta()
|
|
|
|
local add_amount = meta:get_int("amount")
|
|
|
|
local score = player_meta:get_int("epic_score")
|
|
|
|
score = score + add_amount
|
|
|
|
player_meta:set_int("epic_score", score)
|
|
|
|
|
|
|
|
ctx.next()
|
|
|
|
end
|
|
|
|
}
|
|
|
|
})
|