1
0
cuberite-2a/MCServer/Plugins/MagicCarpet/plugin.lua
Tiger Wang 25abfb9476 Updated MagicCarpet to use new API [SEE DESC]
Fixed non-teleportation upon falling through carpet due to use of
deprecated function.
Fixed spam of console upon falling through carpet.
Added descriptive upon-enable message.
2013-07-30 22:26:50 +01:00

84 lines
1.7 KiB
Lua

local PLUGIN = {}
local Carpets = {}
function Initialize( Plugin )
PLUGIN = Plugin
Plugin:SetName( "MagicCarpet" )
Plugin:SetVersion( 1 )
PluginManager = cRoot:Get():GetPluginManager()
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_MOVING)
PluginManager:AddHook(Plugin, cPluginManager.HOOK_DISCONNECT)
PluginManager:BindCommand("/mc", "magiccarpet", HandleCarpetCommand, " - Spawns a magical carpet");
LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
return true
end
function OnDisable()
LOG( PLUGIN:GetName() .. " v." .. PLUGIN:GetVersion() .. " is shutting down..." )
for i, Carpet in pairs( Carpets ) do
Carpet:remove()
end
end
function HandleCarpetCommand( Split, Player )
Carpet = Carpets[ Player ]
if( Carpet == nil ) then
Carpets[ Player ] = cCarpet:new()
Player:SendMessage("You're on a magic carpet!" )
Player:SendMessage("Look straight down to descend. Jump to ascend!" )
else
Carpet:remove()
Carpets[ Player ] = nil
Player:SendMessage("The carpet vanished!" )
end
return true
end
function OnDisconnect( Reason, Player )
local Carpet = Carpets[ Player ]
if( Carpet ~= nil ) then
Carpet:remove()
end
Carpets[ Player ] = nil
end
function OnPlayerMoving(Player)
local Carpet = Carpets[ Player ]
if( Carpet == nil ) then
return
end
if( Player:GetPitch() == 90 ) then
Carpet:moveTo( cLocation:new( Player:GetPosX(), Player:GetPosY() - 1, Player:GetPosZ() ) )
else
if( Player:GetPosY() < Carpet:getY() ) then
Player:TeleportToCoords(Player:GetPosX(), Carpet:getY(), Player:GetPosZ())
end
Carpet:moveTo( cLocation:new( Player:GetPosX(), Player:GetPosY(), Player:GetPosZ() ) )
end
end