11-07-2011, 11:10 AM
Core needs a /give command.
Code:
function HandleGiveCommand( Split, Player )
if #Split < 3 then
Player:SendMessage( cChatColor.Green .. "Usage: /give [PlayerName] [ItemID/Name] <Amount>" )
return true
end
local World = cRoot:Get():GetWorld()
local GivePlayer = World:GetPlayer( Split[2] )
if GivePlayer == nil then
Player:SendMessage( cChatColor.Green .. "Player " ..Split[2].. " not found." )
return true
end
ItemID = Split[3]
ItemMeta = 0
sPos = string.find(Split[3], ":")
if (sPos ~= nil) then
ItemID = tonumber(string.sub(Split[3], 1, sPos-1))
ItemMeta = tonumber(string.sub(Split[3], sPos+1))
else
ItemID = tonumber(Split[3])
end
if( ItemID == nil or not isValidItem( ItemID ) ) then
Player:SendMessage( cChatColor.Green .. "Item " ..Split[3].. " not found." )
return true
end
ItemAmount = 1
if( #Split >= 4 ) then
ItemAmount = tonumber(Split[4])
if( ItemAmount == nil or ItemAmount < 1 or ItemAmount > 512 ) then
Player:SendMessage( cChatColor.Red .. "Invalid Amount !" )
return true
end
end
local NewItem = cItem( ItemID, ItemAmount , ItemMeta)
if( GivePlayer:GetInventory():AddItem(NewItem) == true ) then
Player:SendMessage( cChatColor.Green .. "Gave item ("..ItemID..":"..ItemMeta..") to "..Split[2].."." )
LOG("Gave " .. GivePlayer:GetName() .. " " .. ItemAmount .. " times " .. ItemID )
else
Player:SendMessage( cChatColor.Red .. "Not enough space in inventory !" )
end
return true
end