named cards

master
BuckarooBanzay 2019-10-25 13:42:12 +02:00
parent 534a7da5e8
commit 5b91bd8c2b
3 changed files with 81 additions and 19 deletions

30
cards.lua Normal file
View File

@ -0,0 +1,30 @@
minetest.register_craftitem("access_cards:access_card_1", {
description = "Access card",
inventory_image = "access_card_1.png",
stack_max = 1,
on_use = function(_, player)
access_cards.name_form(player)
end
})
minetest.register_craftitem("access_cards:access_card_1_colored", {
description = "Access card",
groups = {ud_param2_colorable = 1, not_in_creative_inventory = 1},
inventory_image = "access_card_1.png",
palette = "unifieddyes_palette_extended.png",
stack_max = 1,
paramtype2 = "color",
on_use = function(_, player)
access_cards.name_form(player)
end
})
unifieddyes.register_color_craft({
output = "access_cards:access_card_1_colored",
palette = "extended",
neutral_node = "access_cards:access_card_1",
recipe = { "NEUTRAL_NODE", "MAIN_DYE" },
type = "shapeless"
})

46
form.accesscard.lua Normal file
View File

@ -0,0 +1,46 @@
local FORMNAME = "access_card_name"
local function starts_with(str, start)
return str:sub(1, #start) == start
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
local parts = formname:split(";")
local name = parts[1]
if name ~= FORMNAME then
return
end
local stack = player:get_wielded_item()
if not starts_with(stack:get_name(), "access_cards") then
-- not an access card
return
end
local meta = stack:get_meta()
if meta:get_int("configured") == 1 then
-- already configured
return
end
meta:set_int("configured", 1)
meta:set_string("name", fields.name)
meta:set_string("description", "Access card: '" .. fields.name .. "'")
player:set_wielded_item(stack)
end)
access_cards.name_form = function(pos, player)
local formspec = "size[8,1;]" ..
"field[0,0.5;6,1;name;Name;]" ..
"button_exit[6,0.1;2,1;save;Save]"
minetest.show_formspec(player:get_player_name(),
FORMNAME .. ";" .. minetest.pos_to_string(pos),
formspec
)
end

View File

@ -1,22 +1,8 @@
local MP = minetest.get_modpath("missions")
minetest.register_craftitem("access_cards:access_card_1", {
description = "Access card",
inventory_image = "access_card_1.png"
})
access_cards = {}
minetest.register_craftitem("access_cards:access_card_1_colored", {
description = "Access card",
groups = {ud_param2_colorable = 1, not_in_creative_inventory = 1},
inventory_image = "access_card_1.png",
palette = "unifieddyes_palette_extended.png",
paramtype2 = "color",
})
dofile(MP.."/form.accesscard.lua")
dofile(MP.."/cards.lua")
unifieddyes.register_color_craft({
output = "access_cards:access_card_1_colored",
palette = "extended",
neutral_node = "access_cards:access_card_1",
recipe = { "NEUTRAL_NODE", "MAIN_DYE" },
type = "shapeless"
})
print("[OK] access_cards")