common_cards = { {name = "card_default_tree", description = "Apple Tree Card\nMTG Card #1", on_use_item = "default:tree 5"}, {name = "card_default_acacia_tree", description = "Acacia Tree Card\nMTG Card #2", on_use_item = "default:acacia_tree 5"}, {name = "card_default_aspen_tree", description = "Aspen Tree Card\nMTG Card #3", on_use_item = "default:aspen_tree 5"}, {name = "card_default_jungle_tree", description = "Jungle Tree Card\nMTG Card #4", on_use_item = "default:jungle_tree 5"}, {name = "card_default_pine_tree", description = "Pine Tree Card\nMTG Card #5", on_use_item = "default:pine_tree 5"}, {name = "card_default_tool_stone_pickaxe", description = "Stone Pickaxe Card\nMTG Card #6", on_use_item = "default:tool_stone 1"}, {name = "card_default_tool_stone_axe", description = "Stone Axe Card\nMTG Card #7", on_use_item = "default:tool_stone 1"}, {name = "card_default_tool_stone_sword", description = "Stone Sword Card\nMTG Card #8", on_use_item = "default:tool_stone 1"}, {name = "card_default_tool_stone_shovel", description = "Stone Shovel Card\nMTG Card #9", on_use_item = "default:tool_stone 1"}, {name = "card_default_tool_wood_pickaxe", description = "Wood Pickaxe Card\nMTG Card #10", on_use_item = "default:tool_wood 1"}, {name = "card_default_tool_wood_axe", description = "Wood Axe Card\nMTG Card #11", on_use_item = "default:tool_wood 1"}, {name = "card_default_tool_wood_sword", description = "Wood Sword Card\nMTG Card #12", on_use_item = "default:tool_wood 1"}, {name = "card_default_tool_wood_shovel", description = "Wood Shovel Card\nMTG Card #13", on_use_item = "default:tool_wood 1"}, {name = "card_default_coal_lump", description = "Coal Card\nMTG Card #14", on_use_item = "default: 5"}, {name = "card_default_copper_lump", description = "Copper Card\nMTG Card #15", on_use_item = "default: 5"}, {name = "card_default_iron_lump", description = "Iron Card\nMTG Card #16", on_use_item = "default: 5"}, {name = "card_default_tin_lump", description = "Tin Card\nMTG Card #17", on_use_item = "default: 5"}, } uncommon_cards = { {name = "card_default_tool_bronze_pickaxe", description = "Bronze Pickaxe Card\nMTG Card #18"}, {name = "card_default_tool_bronze_axe", description = "Bronze Axe Card\nMTG Card #19"}, {name = "card_default_tool_bronze_sword", description = "Bronze Sword Card\nMTG Card #20"}, {name = "card_default_tool_bronze_shovel", description = "Bronze Shovel Tree Card\nMTG Card #21"}, {name = "card_default_gold_lump", description = "Gold Card\nMTG Card #22"}, } rare_cards = { {name = "card_default_mese_crystal", description = "Mese Crystal Card\nMTG Card #23"}, {name = "card_default_tool_steel_pickaxe", description = "Steel Pickaxe Card\nMTG Card #24"}, {name = "card_default_tool_steel_axe", description = "Steel Axe Card\nMTG Card #25"}, {name = "card_default_tool_steel_sword", description = "Steel Sword Card\nMTG Card #26"}, {name = "card_default_tool_steel_shovel", description = "Steel Shovel Tree Card\nMTG Card #27"}, } super_rare_cards = { {name = "card_default_tool_diamond_pickaxe", description = "Diamond Pickaxe Card\nMTG Card #28"}, {name = "card_default_tool_diamond_axe", description = "Diamond Axe Card\nMTG Card #29"}, {name = "card_default_tool_diamond_sword", description = "Diamond Sword Card\nMTG Card #30"}, {name = "card_default_tool_diamond_shovel", description = "Diamond Shovel Tree Card\nMTG Card #31"}, {name = "card_default_tool_mese_pickaxe", description = "Mese Pickaxe Card\nMTG Card #32"}, {name = "card_default_tool_mese_axe", description = "Mese Axe Card\nMTG Card #33"}, {name = "card_default_tool_mese_sword", description = "Mese Sword Card\nMTG Card #34"}, {name = "card_default_tool_mese_shovel", description = "Mese Shovel Tree Card\nMTG Card #35"}, {name = "card_default_diamond", description = "Diamond Card\nMTG Card #37"}, } function generate_cards(cards) for key,value in pairs(cards) do local card_id = "tradingcards:" .. cards[key]["name"] local card_image = cards[key]["name"] .. ".png" minetest.register_craftitem(card_id, { description = cards[key]["description"], inventory_image = card_image, on_use = function(itemstack, user, pointed_thing) minetest.chat_send_player(user:get_player_name(), "Used Item") end, }) end end function get_random_card(card_type) local card = card_type[ math.random( #card_type )] return "tradingcards:" .. card["name"] end function get_card_for_pack() -- 60% common -- 25% uncommon -- 10% rare -- 5% super rare local random_number = math.random(1, 100) local card = "" if random_number <= 60 then card = get_random_card(common_cards) elseif random_number <= 85 then card = get_random_card(uncommon_cards) elseif random_number <= 95 then card = get_random_card(rare_cards) else card = get_random_card(super_rare_cards) end print(card) return card end minetest.register_craftitem("tradingcards:card_pack", { description = "MTG Card Pack!", inventory_image = 'card_pack.png', on_use = function(itemstack, user, pointed_thing) local empty_count = 0 for k, v in pairs(user:get_inventory():get_list("main")) do if tostring(v) == 'ItemStack("")' then empty_count = empty_count + 1 end end print(empty_count) if empty_count < 3 then minetest.chat_send_player(user:get_player_name(),"You can only use this item if you have 3 open inventory slots") else itemstack:take_item() local card = get_card_for_pack() user:get_inventory():add_item("main", card) local card = get_card_for_pack() user:get_inventory():add_item("main", card) local card = get_card_for_pack() user:get_inventory():add_item("main", card) end --[[ itemstack:take_item() card = get_random_card(common_cards) user:get_inventory():add_item("main", card) card = get_random_card(common_cards) user:get_inventory():add_item("main", card) card = get_random_card(common_cards) print(user:get_inventory():room_for_item("main", card)) print(user:get_inventory():add_item("main", card)) print(user:get_inventory():get_size("main")) print(dump(user:get_inventory():get_list("main"))) ]]-- return itemstack end, }) generate_cards(common_cards) generate_cards(uncommon_cards) generate_cards(rare_cards) generate_cards(super_rare_cards)