summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins/Core/give.lua
diff options
context:
space:
mode:
authorbearbin <bearbin@gmail.com>2013-07-27 18:19:22 +0200
committerbearbin <bearbin@gmail.com>2013-07-27 18:19:22 +0200
commit1d0b57d8abf2297614659e1115b81d569612a402 (patch)
treedf7d0acb85b3ef5c4783f721a83908ddc5130ef7 /MCServer/Plugins/Core/give.lua
parentMerge pull request #7 from tigerw/master (diff)
parentMerge pull request #8 from mc-server/master (diff)
downloadcuberite-1d0b57d8abf2297614659e1115b81d569612a402.tar
cuberite-1d0b57d8abf2297614659e1115b81d569612a402.tar.gz
cuberite-1d0b57d8abf2297614659e1115b81d569612a402.tar.bz2
cuberite-1d0b57d8abf2297614659e1115b81d569612a402.tar.lz
cuberite-1d0b57d8abf2297614659e1115b81d569612a402.tar.xz
cuberite-1d0b57d8abf2297614659e1115b81d569612a402.tar.zst
cuberite-1d0b57d8abf2297614659e1115b81d569612a402.zip
Diffstat (limited to 'MCServer/Plugins/Core/give.lua')
-rw-r--r--MCServer/Plugins/Core/give.lua39
1 files changed, 39 insertions, 0 deletions
diff --git a/MCServer/Plugins/Core/give.lua b/MCServer/Plugins/Core/give.lua
new file mode 100644
index 000000000..d0fc026a6
--- /dev/null
+++ b/MCServer/Plugins/Core/give.lua
@@ -0,0 +1,39 @@
+function HandleGiveCommand(Split, Player)
+ if ((#Split ~= 2) and (#Split ~=3)) then
+ Player:SendMessage(cChatColor.Green .. "Usage: /give [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