1
0

Debuggers: Added commands to investigate item's custom name.

This commit is contained in:
Mattes D 2016-11-26 19:24:24 +01:00
parent 3872e813f3
commit 56f8dedb6b
2 changed files with 60 additions and 1 deletions

View File

@ -987,6 +987,28 @@ end;
function HandleGetCustomNameCmd(a_Split, a_Player)
local item = a_Player:GetInventory():GetEquippedItem()
if (not(item.m_CustomName) or (item.m_CustomName == "")) then
a_Player:SendMessage("The custom name is empty")
return true
end
local dispCN = string.gsub(item.m_CustomName, ".",
function(a_Char)
if (a_Char < " ") then
return string.byte(a_Char)
end
return a_Char
end
)
a_Player:SendMessage(string.format("The custom name is %d bytes: %s", string.len(item.m_CustomName), dispCN))
return true
end
function HandleGetLoreCmd(a_Split, a_Player) function HandleGetLoreCmd(a_Split, a_Player)
local item = a_Player:GetInventory():GetEquippedItem() local item = a_Player:GetInventory():GetEquippedItem()
if (not(item.m_Lore) or (item.m_Lore == "")) then if (not(item.m_Lore) or (item.m_Lore == "")) then
@ -1062,6 +1084,31 @@ end
function HandleSetCustomNameCmd(a_Split, a_Player, a_EntireCmd)
if not(a_Split[2]) then
a_Player:SendMessageFatal("Missing an argument: the custom name to set");
return true
end
local nameToSet = a_EntireCmd:match("/setcustomname%s(.*)")
if not(nameToSet) then
a_Player:SendMessageFatal("Failed to extract the custom name to set")
return true
end
nameToSet = nameToSet:gsub("\\([0-9][0-9][0-9])", string.char)
local inv = a_Player:GetInventory()
local slotNum = inv:GetEquippedSlotNum()
local item = cItem(inv:GetEquippedItem()) -- Make a copy of the item
item.m_CustomName = nameToSet
inv:SetHotbarSlot(slotNum, item)
a_Player:SendMessage("Custom name set to " .. nameToSet)
return true
end
function HandleSetLoreCmd(a_Split, a_Player, a_EntireCmd) function HandleSetLoreCmd(a_Split, a_Player, a_EntireCmd)
if not(a_Split[2]) then if not(a_Split[2]) then
a_Player:SendMessageFatal("Missing an argument: the lore to set"); a_Player:SendMessageFatal("Missing an argument: the lore to set");

View File

@ -100,11 +100,17 @@ g_PluginInfo =
Handler = HandleGCCmd, Handler = HandleGCCmd,
HelpString = "Activates the Lua garbage collector" HelpString = "Activates the Lua garbage collector"
}, },
["/getcustomname"] =
{
Permission = "debuggers",
Handler = HandleGetCustomNameCmd,
HelpString = "Displays the exact custom name of currently held item (including non-printables)",
},
["/getlore"] = ["/getlore"] =
{ {
Permission = "debuggers", Permission = "debuggers",
Handler = HandleGetLoreCmd, Handler = HandleGetLoreCmd,
HelpString = "Displays the Lore of currently held item", HelpString = "Displays the exact Lore of currently held item (including non-printables)",
}, },
["/hunger"] = ["/hunger"] =
{ {
@ -172,6 +178,12 @@ g_PluginInfo =
Handler = HandleSched, Handler = HandleSched,
HelpString = "Schedules a simple countdown using cWorld:ScheduleTask()" HelpString = "Schedules a simple countdown using cWorld:ScheduleTask()"
}, },
["/setcustomname"] =
{
Permission = "debuggers",
Handler = HandleSetCustomNameCmd,
HelpString = "Sets the custom name for the item currently in hand",
},
["/setlore"] = ["/setlore"] =
{ {
Permission = "debuggers", Permission = "debuggers",