local table_to_string = function(table) local str = "" for k, v in pairs(table) do str = str .. k .. " (" .. v .. "), " end return str:sub(1, -3) end local gun_desc = function(def) local desc = "" if def._gun_ammunition and next(def._gun_ammunition) then desc = desc .. "\nAmmo: " for _, ammo in ipairs(def._gun_ammunition) do desc = desc .. ammo:get_name() .. " (" .. ammo:get_count() .. "), " end desc = desc:sub(1, -3) end if def._gun_damage and next(def._gun_damage) then desc = desc .. "\nDamage: " .. table_to_string(def._gun_damage) end local vals = { Velocity = def._gun_velocity, Accuracy = def._gun_accuracy, Magazine = def._gun_magazine } for k, v in pairs(vals) do if v then desc = desc .. "\n" .. k .. ": " .. v end end local cooldown = { Reload = def._gun_cooldown_reload, Magazine = def._gun_cooldown_magazine } for k, v in pairs(cooldown) do if v then desc = desc .. "\n" .. k .. " cooldown: " .. v end end return desc end tt.register_snippet(function(itemstring) if minetest.get_item_group(itemstring, "gun_automatic") == 1 then return "Automatic gun" .. gun_desc(minetest.registered_items[itemstring]) elseif minetest.get_item_group(itemstring, "gun_semi_automatic") == 1 then return "Semi-automatic gun" .. gun_desc(minetest.registered_items[itemstring]) elseif minetest.get_item_group(itemstring, "gun_single") == 1 then return "Single-shot gun" .. gun_desc(minetest.registered_items[itemstring]) end end) tt.register_snippet(function(itemstring) local desc = "" local def = minetest.registered_items[itemstring] if def._bullet_drop then desc = desc .. "\nBullet drop: " .. def._bullet_drop end if def._bullet_velocity then desc = desc .. "\nBullet velocity: " .. def._bullet_velocity end if def._bullet_damage and next(def._bullet_damage) then desc = desc .. "\nBullet damage: " .. table_to_string(def._bullet_damage) end if desc ~= "" then return desc:sub(2) end end)