Updated Core plugin to allow spawning items with damage/metadata, the damage/metadata can also be specified in items.ini
Incremented version number of Core :P git-svn-id: http://mc-server.googlecode.com/svn/trunk@170 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
ce11c6b2bd
commit
b8046a8e9d
@ -5,6 +5,7 @@ SHOW_PLUGIN_NAMES = true -- If true, plugin name will be shown before commands
|
|||||||
|
|
||||||
local BannedPlayersIni = {}
|
local BannedPlayersIni = {}
|
||||||
local WhiteListIni = {}
|
local WhiteListIni = {}
|
||||||
|
local ItemsTable = {}
|
||||||
|
|
||||||
CorePlugin = {}
|
CorePlugin = {}
|
||||||
CorePlugin.__index = CorePlugin
|
CorePlugin.__index = CorePlugin
|
||||||
@ -24,7 +25,7 @@ end
|
|||||||
|
|
||||||
function CorePlugin:Initialize()
|
function CorePlugin:Initialize()
|
||||||
self:SetName( "Core" )
|
self:SetName( "Core" )
|
||||||
self:SetVersion( 6 )
|
self:SetVersion( 7 )
|
||||||
|
|
||||||
PluginManager = cRoot:Get():GetPluginManager()
|
PluginManager = cRoot:Get():GetPluginManager()
|
||||||
PluginManager:AddHook( self, cPluginManager.E_PLUGIN_PLAYER_JOIN )
|
PluginManager:AddHook( self, cPluginManager.E_PLUGIN_PLAYER_JOIN )
|
||||||
@ -73,9 +74,32 @@ function CorePlugin:Initialize()
|
|||||||
SHOW_PLUGIN_NAMES = IniFile:GetValueB("HelpPlugin", "ShowPluginNames", true )
|
SHOW_PLUGIN_NAMES = IniFile:GetValueB("HelpPlugin", "ShowPluginNames", true )
|
||||||
end
|
end
|
||||||
|
|
||||||
itemsINI = cIniFile("items.ini")
|
local itemsINI = cIniFile("items.ini")
|
||||||
if ( itemsINI:ReadFile() == true ) then
|
if ( itemsINI:ReadFile() == true ) then
|
||||||
LOGINFO("Core: loaded " .. itemsINI:GetNumValues('Items') .. " item names.")
|
local KeyID = itemsINI:FindKey('Items')
|
||||||
|
|
||||||
|
LOGINFO("Core: loaded " .. itemsINI:GetNumValues( KeyID ) .. " item names.")
|
||||||
|
|
||||||
|
for i = 0, itemsINI:GetNumValues('Items') do
|
||||||
|
local ItemName = itemsINI:GetValueName( KeyID, i )
|
||||||
|
local ItemSyntax = itemsINI:GetValue(KeyID, i, "0")
|
||||||
|
|
||||||
|
local ItemData = StringSplit(ItemSyntax, ":") -- [1] = ID, [2] = perhaps meta/dmg
|
||||||
|
--LOGINFO( "#ItemData: " .. #ItemData )
|
||||||
|
if( #ItemData > 0 ) then
|
||||||
|
--LOGINFO("ItemData[0]: "..ItemData[1])
|
||||||
|
local ItemID = tonumber( ItemData[1] )
|
||||||
|
if( ItemID > 0 ) then
|
||||||
|
local ItemMeta = 0
|
||||||
|
if( #ItemData > 1 ) then
|
||||||
|
ItemMeta = tonumber( ItemData[2] )
|
||||||
|
end
|
||||||
|
ItemsTable[ ItemName ] = cItem( ItemID, 1, ItemMeta )
|
||||||
|
LOGINFO("Got item: " .. ItemName .. "-> " .. ItemsTable[ ItemName ].m_ItemID ..":" .. ItemsTable[ ItemName ].m_ItemHealth )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
HAVE_ITEM_NAMES = true
|
HAVE_ITEM_NAMES = true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -342,51 +366,64 @@ end
|
|||||||
|
|
||||||
function HandleItemCommand( Split, Player )
|
function HandleItemCommand( Split, Player )
|
||||||
if( #Split ~= 2 and #Split ~=3 ) then
|
if( #Split ~= 2 and #Split ~=3 ) then
|
||||||
Player:SendMessage( cChatColor.Green .. "Usage: /item [ItemID/Name] <Amount>" )
|
Player:SendMessage( cChatColor.Green .. "Usage: /item [ItemID/Name:Dmg] <Amount>" )
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
foundItem = false
|
local FoundItem = false
|
||||||
|
|
||||||
ItemID = tonumber( Split[2] )
|
local ItemSyntax = Split[2] -- Contains item string with optional metadata
|
||||||
if( ItemID == nil or not IsValidItem( ItemID ) ) then
|
local ItemData = StringSplit( Split[2], ":" )
|
||||||
-- nothing
|
|
||||||
else
|
-- Default item values
|
||||||
foundItem = true
|
local ItemID = 0
|
||||||
|
local ItemMeta = 0
|
||||||
|
local ItemAmount = 1
|
||||||
|
|
||||||
|
if( #ItemData > 0 ) then
|
||||||
|
ItemID = ItemData[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
if not foundItem then
|
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
|
if ( HAVE_ITEM_NAMES == true ) then
|
||||||
itemValue = itemsINI:GetValueI('Items', ''..Split[2]..'', 0)
|
local Item = ItemsTable[ ItemID ]
|
||||||
if itemValue ~= 0 then
|
if( Item ~= nil ) then
|
||||||
ItemID = itemValue
|
ItemID = Item.m_ItemID
|
||||||
if( ItemID == nil or not IsValidItem( tonumber(itemValue) ) ) then
|
ItemMeta = Item.m_ItemHealth
|
||||||
-- nothing
|
FoundItem = true
|
||||||
else
|
|
||||||
foundItem = true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not foundItem then
|
-- 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 !" )
|
Player:SendMessage( cChatColor.Green .. "Invalid Item ID / Name !" )
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local Amount = 1
|
|
||||||
if( #Split == 3 ) then
|
if( #Split == 3 ) then
|
||||||
Amount = tonumber( Split[3] )
|
ItemAmount = tonumber( Split[3] )
|
||||||
if( Amount == nil or Amount < 1 or Amount > 512 ) then
|
if( ItemAmount == nil or ItemAmount < 1 or ItemAmount > 512 ) then
|
||||||
Player:SendMessage( cChatColor.Green .. "Invalid Amount !" )
|
Player:SendMessage( cChatColor.Green .. "Invalid Amount !" )
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local NewItem = cItem( ItemID, Amount )
|
local NewItem = cItem( ItemID, ItemAmount, ItemMeta )
|
||||||
if( Player:GetInventory():AddItem( NewItem ) == true ) then
|
if( Player:GetInventory():AddItem( NewItem ) == true ) then
|
||||||
Player:SendMessage( cChatColor.Green .. "There you go !" )
|
Player:SendMessage( cChatColor.Green .. "There you go !" )
|
||||||
LOG("Gave " .. Player:GetName() .. " " .. Amount .. " times " .. ItemID )
|
LOG("Gave " .. Player:GetName() .. " " .. ItemAmount .. " times " .. ItemID .. ":" .. ItemMeta)
|
||||||
else
|
else
|
||||||
Player:SendMessage( cChatColor.Green .. "Not enough space in inventory !" )
|
Player:SendMessage( cChatColor.Green .. "Not enough space in inventory !" )
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user