2013-05-24 03:30:39 -04:00
function HandleItemCommand ( Split , Player )
if ( ( # Split ~= 2 ) and ( # Split ~= 3 ) ) then
Player : SendMessage ( cChatColor.Green .. " Usage: /item [ItemType/Name:Dmg] <Amount> " ) ;
return true ;
2012-01-26 17:44:37 -05:00
end
2013-05-24 03:30:39 -04:00
local Item = cItem ( E_ITEM_EMPTY , 1 ) ;
local FoundItem = StringToItem ( Split [ 2 ] , Item ) ;
2012-01-26 17:44:37 -05:00
2013-05-24 03:30:39 -04:00
if not ( IsValidItem ( Item.m_ItemType ) ) then -- StringToItem does not check if item is valid
2012-09-08 17:41:17 -04:00
FoundItem = false
2012-01-26 17:44:37 -05:00
end
2013-05-24 03:30:39 -04:00
if not ( FoundItem ) then
2013-01-13 06:10:26 -05:00
Player : SendMessage ( cChatColor.Green .. " Invalid Item type / name ! " )
2012-01-26 17:44:37 -05:00
return true
end
2013-05-24 03:30:39 -04:00
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 ;
2012-01-26 17:44:37 -05:00
end
end
2013-05-24 03:30:39 -04:00
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 ) ;
2012-01-26 17:44:37 -05:00
else
2013-05-24 03:30:39 -04:00
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 ) ;
2012-01-26 17:44:37 -05:00
end
2013-05-24 03:30:39 -04:00
return true ;
2012-01-26 17:44:37 -05:00
end