diff options
author | Alexander Harkness <bearbin@gmail.com> | 2013-07-27 17:16:04 +0200 |
---|---|---|
committer | Alexander Harkness <bearbin@gmail.com> | 2013-07-27 17:16:04 +0200 |
commit | 0623a4f9be1c21651ea212f7b4d86136a67ddffe (patch) | |
tree | 5a96f13f72fa394bf74d10839a76ec7a1eac9275 /Core/give.lua | |
parent | Removed all the pre-exising core files. (diff) | |
download | cuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.tar cuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.tar.gz cuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.tar.bz2 cuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.tar.lz cuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.tar.xz cuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.tar.zst cuberite-0623a4f9be1c21651ea212f7b4d86136a67ddffe.zip |
Diffstat (limited to 'Core/give.lua')
-rw-r--r-- | Core/give.lua | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Core/give.lua b/Core/give.lua new file mode 100644 index 000000000..baabdf557 --- /dev/null +++ b/Core/give.lua @@ -0,0 +1,39 @@ +function HandleGiveCommand(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(); + 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 id or 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
\ No newline at end of file |