1
0
cuberite-2a/MCServer/Plugins/Core/item.lua
madmaxoft@gmail.com cf87169737 Refactored cInventory to use cItemGrid for the actual Storage
This makes the API more orthogonal and is easier to use in the plugins. Also changes in the inventory are now propagated to the needed places (armor updates to BroadcastEntityEquipment etc.) even when the inventory is changed by a plugin.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1503 0a769ca7-a7f5-676a-18bf-c427514a06d6
2013-05-24 07:30:39 +00:00

39 lines
1.4 KiB
Lua

function HandleItemCommand(Split, Player)
if ((#Split ~= 2) and (#Split ~=3)) then
Player:SendMessage(cChatColor.Green .. "Usage: /item [ItemType/Name:Dmg] <Amount>");
return true;
end
local Item = cItem(E_ITEM_EMPTY, 1);
local FoundItem = StringToItem(Split[2], Item);
if not(IsValidItem(Item.m_ItemType)) then -- StringToItem does not check if item is valid
FoundItem = false
end
if not(FoundItem) then
Player:SendMessage( cChatColor.Green .. "Invalid Item type / name !" )
return true
end
local ItemAmount = 1;
if (#Split == 3) then
ItemAmount = tonumber(Split[3]);
if ((ItemAmount == nil) or (ItemAmount < 1) or (ItemAmount > 512)) then
Player:SendMessage(cChatColor.Green .. "Invalid Amount!");
return true;
end
end
Item.m_ItemCount = ItemAmount;
local ItemsGiven = Player:GetInventory():AddItem(Item);
if (ItemsGiven == ItemAmount) then
Player:SendMessage( cChatColor.Green .. "There you go !");
LOG("Gave " .. Player:GetName() .. " " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage);
else
Player:SendMessage(cChatColor.Green .. "Not enough space in inventory, only gave " .. ItemsGiven);
LOG("Player " .. Player:GetName() .. " asked for " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage ..", but only could fit " .. ItemsGiven);
end
return true;
end