2013-07-27 16:24:03 +01:00
function HandleGiveCommand ( Split , Player )
if (( # Split ~= 2 ) and ( # Split ~= 3 )) then
2013-07-31 17:10:59 +01:00
Player : SendMessage ( cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /give [ItemType/Name:Dmg] <Amount>" );
2013-07-27 16:24:03 +01:00
return true ;
end
local Item = cItem ();
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
2013-07-31 17:10:59 +01:00
Player : SendMessage ( cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Invalid item id or name!" )
2013-07-27 16:24:03 +01:00
return true
end
local ItemAmount = 1 ;
if ( # Split == 3 ) then
ItemAmount = tonumber ( Split [ 3 ]);
if (( ItemAmount == nil ) or ( ItemAmount < 1 ) or ( ItemAmount > 512 )) then
2013-07-31 17:10:59 +01:00
Player : SendMessage ( cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Invalid amount!" );
2013-07-27 16:24:03 +01:00
return true ;
end
end
Item.m_ItemCount = ItemAmount ;
local ItemsGiven = Player : GetInventory (): AddItem ( Item );
if ( ItemsGiven == ItemAmount ) then
2013-07-31 17:10:59 +01:00
Player : SendMessage ( cChatColor.Green .. "[INFO] " .. cChatColor.White .. "There you go!" );
2013-07-27 16:24:03 +01:00
LOG ( "Gave " .. Player : GetName () .. " " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage );
else
2013-07-31 17:10:59 +01:00
Player : SendMessage ( cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Not enough space in inventory, only gave " .. ItemsGiven );
2013-07-27 16:24:03 +01:00
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