summaryrefslogtreecommitdiffstats
path: root/Plugins/NewTest/item.lua
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-26 23:44:37 +0100
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-26 23:44:37 +0100
commit45e286fdcd64e4a68c616d705ec5ae5e2f9e00bf (patch)
treeea33c19161f5885896c21937204c21afaeba5eb9 /Plugins/NewTest/item.lua
parentNo longer hard coded Lua files in new plugin system (diff)
downloadcuberite-45e286fdcd64e4a68c616d705ec5ae5e2f9e00bf.tar
cuberite-45e286fdcd64e4a68c616d705ec5ae5e2f9e00bf.tar.gz
cuberite-45e286fdcd64e4a68c616d705ec5ae5e2f9e00bf.tar.bz2
cuberite-45e286fdcd64e4a68c616d705ec5ae5e2f9e00bf.tar.lz
cuberite-45e286fdcd64e4a68c616d705ec5ae5e2f9e00bf.tar.xz
cuberite-45e286fdcd64e4a68c616d705ec5ae5e2f9e00bf.tar.zst
cuberite-45e286fdcd64e4a68c616d705ec5ae5e2f9e00bf.zip
Diffstat (limited to 'Plugins/NewTest/item.lua')
-rw-r--r--Plugins/NewTest/item.lua65
1 files changed, 65 insertions, 0 deletions
diff --git a/Plugins/NewTest/item.lua b/Plugins/NewTest/item.lua
new file mode 100644
index 000000000..942fa8ce6
--- /dev/null
+++ b/Plugins/NewTest/item.lua
@@ -0,0 +1,65 @@
+function HandleItemCommand( Split, Player )
+ if( #Split ~= 2 and #Split ~=3 ) then
+ Player:SendMessage( cChatColor.Green .. "Usage: /item [ItemID/Name:Dmg] <Amount>" )
+ return true
+ end
+
+ local FoundItem = false
+
+ local ItemSyntax = Split[2] -- Contains item string with optional metadata
+ local ItemData = StringSplit( Split[2], ":" )
+
+ -- Default item values
+ local ItemID = 0
+ local ItemMeta = 0
+ local ItemAmount = 1
+
+ if( #ItemData > 0 ) then
+ ItemID = ItemData[1]
+ end
+
+ if( tonumber(ItemID) ~= nil ) then -- Definitely a number
+ ItemID = tonumber(ItemID)
+ if( IsValidItem( ItemID ) ) then
+ FoundItem = true
+ end
+ end
+
+ if( FoundItem == false ) then
+ if ( HAVE_ITEM_NAMES == true ) then
+ local Item = ItemsTable[ ItemID ]
+ if( Item ~= nil ) then
+ ItemID = Item.m_ItemID
+ ItemMeta = Item.m_ItemHealth
+ FoundItem = true
+ end
+ end
+ end
+
+ -- Override metadata from item in list, if metadata was given
+ if( #ItemData > 1 and tonumber( ItemData[2] ) ~= nil ) then -- Metadata is given, and is a number
+ ItemMeta = tonumber( ItemData[2] )
+ end
+
+ if( FoundItem == false ) then
+ Player:SendMessage( cChatColor.Green .. "Invalid Item ID / 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
+ end
+ end
+
+ local NewItem = cItem( ItemID, ItemAmount, ItemMeta )
+ if( Player:GetInventory():AddItem( NewItem ) == true ) then
+ Player:SendMessage( cChatColor.Green .. "There you go !" )
+ LOG("Gave " .. Player:GetName() .. " " .. ItemAmount .. " times " .. ItemID .. ":" .. ItemMeta)
+ else
+ Player:SendMessage( cChatColor.Green .. "Not enough space in inventory !" )
+ end
+ return true
+end \ No newline at end of file