1
0

Debuggers: Added commands to investigate item's custom Lua properties.

This commit is contained in:
Mattes D 2016-11-26 20:45:01 +01:00
parent 56f8dedb6b
commit 12071bc51a
3 changed files with 61 additions and 2 deletions

View File

@ -7930,7 +7930,7 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
Type = "cItem", Type = "cItem",
}, },
}, },
Notes = "Returns the currently selected item from the hotbar. Note that the returned item is read-only", Notes = "Returns the currently selected item from the hotbar. Note that the returned item is read-only. Also note that the returned item is bound to the actual inventory slot - if a player moves another item into the slot, this object will update to the new item. Use a {{cItem}} constructor to make a copy if you need to store the contents of the slot.",
}, },
GetEquippedLeggings = GetEquippedLeggings =
{ {

View File

@ -1031,6 +1031,28 @@ end
function HandleGetPropCmd(a_Split, a_Player)
local item = a_Player:GetInventory():GetEquippedItem()
if not(item.m_DebuggersCustomProp) then
a_Player:SendMessage("The custom property is not set.")
return true
end
local dispValue = string.gsub(item.m_DebuggersCustomProp, ".",
function(a_Char)
if (a_Char < " ") then
return string.byte(a_Char)
end
return a_Char
end
)
a_Player:SendMessage(string.format("The custom property value is %d bytes: %s", string.len(item.m_DebuggersCustomProp), dispValue))
return true
end
function HandleHungerCmd(a_Split, a_Player) function HandleHungerCmd(a_Split, a_Player)
a_Player:SendMessage("FoodLevel: " .. a_Player:GetFoodLevel()); a_Player:SendMessage("FoodLevel: " .. a_Player:GetFoodLevel());
a_Player:SendMessage("FoodSaturationLevel: " .. a_Player:GetFoodSaturationLevel()); a_Player:SendMessage("FoodSaturationLevel: " .. a_Player:GetFoodSaturationLevel());
@ -1109,6 +1131,31 @@ end
function HandleSetPropCmd(a_Split, a_Player, a_EntireCmd)
if not(a_Split[2]) then
a_Player:SendMessageFatal("Missing an argument: the property value to set");
return true
end
local valueToSet = a_EntireCmd:match("/setprop%s(.*)")
if not(valueToSet) then
a_Player:SendMessageFatal("Failed to extract the property value to set")
return true
end
valueToSet = valueToSet:gsub("\\([0-9][0-9][0-9])", string.char)
local inv = a_Player:GetInventory()
local slotNum = inv:GetEquippedSlotNum()
local item = inv:GetEquippedItem()
item.m_DebuggersCustomProp = valueToSet
inv:SetHotbarSlot(slotNum, item)
a_Player:SendMessage("Custom property set to " .. valueToSet)
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

@ -112,6 +112,12 @@ g_PluginInfo =
Handler = HandleGetLoreCmd, Handler = HandleGetLoreCmd,
HelpString = "Displays the exact Lore of currently held item (including non-printables)", HelpString = "Displays the exact Lore of currently held item (including non-printables)",
}, },
["/getprop"] =
{
Permission = "debuggers",
Handler = HandleGetPropCmd,
HelpString = "Displays the custom cItem property of the currently held item",
},
["/hunger"] = ["/hunger"] =
{ {
Permission = "debuggers", Permission = "debuggers",
@ -190,6 +196,12 @@ g_PluginInfo =
Handler = HandleSetLoreCmd, Handler = HandleSetLoreCmd,
HelpString = "Sets the lore for the item currently in hand", HelpString = "Sets the lore for the item currently in hand",
}, },
["/setprop"] =
{
Permission = "debuggers",
Handler = HandleSetPropCmd,
HelpString = "Sets the custom property for the item currently in hand",
},
["/spidey"] = ["/spidey"] =
{ {
Permission = "debuggers", Permission = "debuggers",