initial fork upload
commit
220016c643
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,228 @@
|
|||
|
||||
toolranks = {
|
||||
colors = {
|
||||
grey = minetest.get_color_escape_sequence("#9d9d9d"),
|
||||
green = minetest.get_color_escape_sequence("#1eff00"),
|
||||
gold = minetest.get_color_escape_sequence("#ffdf00"),
|
||||
white = minetest.get_color_escape_sequence("#ffffff")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function toolranks.create_description(name, uses, level)
|
||||
|
||||
return toolranks.colors.green .. (name or "") .. "\n"
|
||||
.. toolranks.colors.gold .. "Level: " .. (level or 1) .. "\n"
|
||||
.. toolranks.colors.grey .. "Used: " .. (uses or 0) .. " times"
|
||||
end
|
||||
|
||||
|
||||
function toolranks.get_level(uses)
|
||||
|
||||
if uses < 200 then
|
||||
return 1
|
||||
elseif uses < 400 then
|
||||
return 2
|
||||
elseif uses < 1000 then
|
||||
return 3
|
||||
elseif uses < 2000 then
|
||||
return 4
|
||||
elseif uses < 3200 then
|
||||
return 5
|
||||
else
|
||||
return 6
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function toolranks.new_afteruse(itemstack, user, node, digparams)
|
||||
|
||||
-- Get tool metadata and number of times used
|
||||
local itemmeta = itemstack:get_meta()
|
||||
local dugnodes = tonumber(itemmeta:get_string("dug")) or 0
|
||||
|
||||
-- Only count nodes that spend the tool
|
||||
if digparams.wear > 0 then
|
||||
|
||||
dugnodes = dugnodes + 1
|
||||
itemmeta:set_string("dug", dugnodes)
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
-- Get tool description and last level
|
||||
local itemdef = itemstack:get_definition()
|
||||
local itemdesc = itemdef.original_description or itemdef.description or "Tool"
|
||||
local lastlevel = tonumber(itemmeta:get_string("lastlevel")) or 1
|
||||
local name = user:get_player_name()
|
||||
|
||||
-- Warn player when tool is almost broken
|
||||
if itemstack:get_wear() > 60100 then
|
||||
|
||||
minetest.chat_send_player(name,
|
||||
toolranks.colors.gold .. "Your tool is almost broken!")
|
||||
|
||||
minetest.sound_play("default_tool_breaks", {
|
||||
to_player = name,
|
||||
gain = 2.0,
|
||||
})
|
||||
end
|
||||
|
||||
local level = toolranks.get_level(dugnodes)
|
||||
|
||||
-- Alert player when tool has leveled up
|
||||
if lastlevel < level then
|
||||
|
||||
minetest.chat_send_player(name, "Your "
|
||||
.. toolranks.colors.green .. itemdesc
|
||||
.. toolranks.colors.white .. " just leveled up!")
|
||||
|
||||
minetest.sound_play("toolranks_levelup", {
|
||||
to_player = name,
|
||||
gain = 1.0,
|
||||
})
|
||||
|
||||
itemmeta:set_string("lastlevel", level)
|
||||
end
|
||||
|
||||
local newdesc = toolranks.create_description(itemdesc, dugnodes, level)
|
||||
|
||||
-- Set new meta
|
||||
itemmeta:set_string("description", newdesc)
|
||||
|
||||
local wear = digparams.wear
|
||||
|
||||
-- Set wear level
|
||||
if level > 1 then
|
||||
wear = digparams.wear / (1 + level / 4)
|
||||
end
|
||||
|
||||
itemstack:add_wear(wear)
|
||||
|
||||
return itemstack
|
||||
end
|
||||
|
||||
|
||||
-- Sword
|
||||
minetest.override_item("default:sword_wood", {
|
||||
original_description = "Wooden Sword",
|
||||
description = toolranks.create_description("Wooden Sword"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:sword_stone", {
|
||||
original_description = "Stone Sword",
|
||||
description = toolranks.create_description("Stone Sword"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:sword_steel", {
|
||||
original_description = "Steel Sword",
|
||||
description = toolranks.create_description("Steel Sword"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:sword_bronze", {
|
||||
original_description = "Bronze Sword",
|
||||
description = toolranks.create_description("Bronze Sword"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:sword_mese", {
|
||||
original_description = "Mese Sword",
|
||||
description = toolranks.create_description("Mese Sword"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:sword_diamond", {
|
||||
original_description = "Diamond Sword",
|
||||
description = toolranks.create_description("Diamond Sword"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
-- Pickaxe
|
||||
minetest.override_item("default:pick_wood", {
|
||||
original_description = "Wooden Pickaxe",
|
||||
description = toolranks.create_description("Wooden Pickaxe"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:pick_stone", {
|
||||
original_description = "Stone Pickaxe",
|
||||
description = toolranks.create_description("Stone Pickaxe"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:pick_steel", {
|
||||
original_description = "Steel Pickaxe",
|
||||
description = toolranks.create_description("Steel Pickaxe"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:pick_bronze", {
|
||||
original_description = "Bronze Pickaxe",
|
||||
description = toolranks.create_description("Bronze Pickaxe"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:pick_mese", {
|
||||
original_description = "Mese Pickaxe",
|
||||
description = toolranks.create_description("Mese Pickaxe"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:pick_diamond", {
|
||||
original_description = "Diamond Pickaxe",
|
||||
description = toolranks.create_description("Diamond Pickaxe"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
-- Axe
|
||||
minetest.override_item("default:axe_wood", {
|
||||
original_description = "Wooden Axe",
|
||||
description = toolranks.create_description("Wooden Axe"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:axe_stone", {
|
||||
original_description = "Stone Axe",
|
||||
description = toolranks.create_description("Stone Axe"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:axe_steel", {
|
||||
original_description = "Steel Axe",
|
||||
description = toolranks.create_description("Steel Axe"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:axe_bronze", {
|
||||
original_description = "Bronze Axe",
|
||||
description = toolranks.create_description("Bronze Axe"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:axe_mese", {
|
||||
original_description = "Mese Axe",
|
||||
description = toolranks.create_description("Mese Axe"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:axe_diamond", {
|
||||
original_description = "Diamond Axe",
|
||||
description = toolranks.create_description("Diamond Axe"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
-- Shovel
|
||||
minetest.override_item("default:shovel_wood", {
|
||||
original_description = "Wooden Shovel",
|
||||
description = toolranks.create_description("Wooden Shovel"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:shovel_stone", {
|
||||
original_description = "Stone Shovel",
|
||||
description = toolranks.create_description("Stone Shovel"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:shovel_steel", {
|
||||
original_description = "Steel Shovel",
|
||||
description = toolranks.create_description("Steel Shovel"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:shovel_bronze", {
|
||||
original_description = "Bronze Shovel",
|
||||
description = toolranks.create_description("Bronze Shovel"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:shovel_mese", {
|
||||
original_description = "Mese Shovel",
|
||||
description = toolranks.create_description("Mese Shovel"),
|
||||
after_use = toolranks.new_afteruse})
|
||||
|
||||
minetest.override_item("default:shovel_diamond", {
|
||||
original_description = "Diamond Shovel",
|
||||
description = toolranks.create_description("Diamond Shovel"),
|
||||
after_use = toolranks.new_afteruse})
|
Binary file not shown.
Loading…
Reference in New Issue