2019-11-10 20:12:29 +00:00
|
|
|
|
|
|
|
-- Repair command
|
|
|
|
local function cmd_repair(name, params, splitparams)
|
|
|
|
local player = minetest.get_player_by_name(name)
|
|
|
|
local commit = 0
|
|
|
|
|
|
|
|
if splitparams[1] == name and splitparams[2] == "all" then
|
|
|
|
splitparams[1] = "all"
|
|
|
|
end
|
|
|
|
|
2019-11-10 21:15:22 +00:00
|
|
|
if #splitparams > 0 then
|
|
|
|
if splitparams[1] == "all" then
|
|
|
|
if not ess.priv_match(name, "ess.tools.repairall") then
|
|
|
|
return ess.reject_permission()
|
|
|
|
end
|
|
|
|
-- Repair all tools
|
|
|
|
commit = 2
|
|
|
|
elseif splitparams[2] == "all" and minetest.get_player_by_name(splitparams[1]) then
|
|
|
|
if not ess.priv_match(name, "ess.tools.repairall.other") then
|
|
|
|
return ess.reject_permission()
|
|
|
|
end
|
|
|
|
player = minetest.get_player_by_name(splitparams[1])
|
|
|
|
-- Repair all of a player's tools
|
|
|
|
commit = 2
|
|
|
|
elseif splitparams[1] ~= name and minetest.get_player_by_name(splitparams[1]) then
|
|
|
|
if not ess.priv_match(name, "ess.tools.repair.other") then
|
|
|
|
return ess.reject_permission()
|
|
|
|
end
|
|
|
|
player = minetest.get_player_by_name(splitparams[1])
|
|
|
|
-- Repair a player's held tool
|
|
|
|
commit = 1
|
2019-11-10 20:12:29 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
-- Repair my own tool
|
|
|
|
commit = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if commit == 1 and player then
|
|
|
|
local held = player:get_wielded_item()
|
|
|
|
if held:get_wear() > 0 then
|
|
|
|
held:set_wear(0)
|
|
|
|
end
|
|
|
|
player:set_wielded_item(held)
|
|
|
|
return true, "Successfully repaired the held tool!"
|
|
|
|
elseif commit == 2 and player then
|
|
|
|
local inv = player:get_inventory()
|
|
|
|
local list = inv:get_list("main")
|
|
|
|
for _,stack in pairs(list) do
|
|
|
|
if stack:get_wear() > 0 then
|
|
|
|
stack:set_wear(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
inv:set_list("main", list)
|
|
|
|
return true, "Successfully repaired all tools!"
|
|
|
|
end
|
|
|
|
|
|
|
|
return false,"Invalid parameters."
|
|
|
|
end
|
|
|
|
|
|
|
|
local commands = {
|
|
|
|
["repair"] = {
|
|
|
|
description = "Repair currently held tool.",
|
|
|
|
aliases = {"fix"},
|
|
|
|
privs = {
|
|
|
|
["ess.tools.repair"] = true,
|
|
|
|
["ess.tools.repair.other"] = true,
|
|
|
|
["ess.tools.repairall"] = true,
|
|
|
|
["ess.tools.repairall.other"] = true,
|
|
|
|
},
|
|
|
|
params = "[<playername>] [all]",
|
|
|
|
func = cmd_repair
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ess.autoregister(commands, "tools")
|