From cf87169737fdeeee7d4b160688bbed7194e46147 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Fri, 24 May 2013 07:30:39 +0000 Subject: 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 --- MCServer/Plugins/Core/item.lua | 43 +++++++++++++++++--------------- MCServer/Plugins/Debuggers/Debuggers.lua | 8 +++--- 2 files changed, 27 insertions(+), 24 deletions(-) (limited to 'MCServer/Plugins') diff --git a/MCServer/Plugins/Core/item.lua b/MCServer/Plugins/Core/item.lua index 00a6aa790..30e8820a9 100644 --- a/MCServer/Plugins/Core/item.lua +++ b/MCServer/Plugins/Core/item.lua @@ -1,36 +1,39 @@ -function HandleItemCommand( Split, Player ) - if( #Split ~= 2 and #Split ~=3 ) then - Player:SendMessage( cChatColor.Green .. "Usage: /item [ItemType/Name:Dmg] " ) - return true +function HandleItemCommand(Split, Player) + if ((#Split ~= 2) and (#Split ~=3)) then + Player:SendMessage(cChatColor.Green .. "Usage: /item [ItemType/Name:Dmg] "); + return true; end - local Item = cItem(E_ITEM_EMPTY, 1) - local FoundItem = StringToItem( Split[2], Item ) + local Item = cItem(E_ITEM_EMPTY, 1); + local FoundItem = StringToItem(Split[2], Item); - if( IsValidItem( Item.m_ItemType ) == false ) then -- StringToItem does not check if item is valid + if not(IsValidItem(Item.m_ItemType)) then -- StringToItem does not check if item is valid FoundItem = false end - if( FoundItem == false ) then + if not(FoundItem) then Player:SendMessage( cChatColor.Green .. "Invalid Item type / name !" ) return true end - 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 - else - Item.m_ItemCount = ItemAmount + 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 - if( Player:GetInventory():AddItem( Item ) == true ) then - Player:SendMessage( cChatColor.Green .. "There you go !" ) - LOG("Gave " .. Player:GetName() .. " " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage) + 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 !" ) + 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 + return true; end \ No newline at end of file diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 21cc4bb86..3f6dcfb7e 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -456,10 +456,10 @@ end function HandleWoolCmd(Split, Player) local Wool = cItem(E_BLOCK_WOOL, 1, E_META_WOOL_BLUE); - Player:GetInventory():SetSlot(5, Wool); - Player:GetInventory():SetSlot(6, Wool); - Player:GetInventory():SetSlot(7, Wool); - Player:GetInventory():SetSlot(8, Wool); + Player:GetInventory():SetArmorSlot(0, Wool); + Player:GetInventory():SetArmorSlot(1, Wool); + Player:GetInventory():SetArmorSlot(2, Wool); + Player:GetInventory():SetArmorSlot(3, Wool); Player:SendMessage("You have been bluewooled :)"); return true; end \ No newline at end of file -- cgit v1.2.3