2012-02-01 14:19:51 -05:00
|
|
|
local PLUGIN = {}
|
|
|
|
local Carpets = {}
|
|
|
|
|
|
|
|
function Initialize( Plugin )
|
|
|
|
PLUGIN = Plugin
|
|
|
|
|
|
|
|
Plugin:SetName( "MagicCarpet" )
|
|
|
|
Plugin:SetVersion( 1 )
|
|
|
|
|
|
|
|
PluginManager = cRoot:Get():GetPluginManager()
|
2013-02-01 15:11:12 -05:00
|
|
|
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_MOVING)
|
|
|
|
PluginManager:AddHook(Plugin, cPluginManager.HOOK_DISCONNECT)
|
2012-02-01 14:19:51 -05:00
|
|
|
|
2013-02-01 15:11:12 -05:00
|
|
|
PluginManager:BindCommand("/mc", "magiccarpet", HandleCarpetCommand, " - Spawns a magical carpet");
|
2012-02-01 14:19:51 -05:00
|
|
|
|
|
|
|
Log( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-02-01 15:11:12 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-01 14:19:51 -05:00
|
|
|
function OnDisable()
|
|
|
|
Log( PLUGIN:GetName() .. " v." .. PLUGIN:GetVersion() .. " is shutting down..." )
|
|
|
|
for i, Carpet in pairs( Carpets ) do
|
|
|
|
Carpet:remove()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-01 15:11:12 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-01 14:19:51 -05:00
|
|
|
function HandleCarpetCommand( Split, Player )
|
|
|
|
Carpet = Carpets[ Player ]
|
|
|
|
if( Carpet == nil ) then
|
|
|
|
Carpets[ Player ] = cCarpet:new()
|
|
|
|
Player:SendMessage("You're on a magic carpet!" )
|
|
|
|
else
|
|
|
|
Carpet:remove()
|
|
|
|
Carpets[ Player ] = nil
|
|
|
|
Player:SendMessage("The carpet vanished!" )
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-02-01 15:11:12 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-01 14:19:51 -05:00
|
|
|
function OnDisconnect( Reason, Player )
|
|
|
|
local Carpet = Carpets[ Player ]
|
|
|
|
if( Carpet ~= nil ) then
|
|
|
|
Carpet:remove()
|
|
|
|
end
|
|
|
|
Carpets[ Player ] = nil
|
|
|
|
end
|
|
|
|
|
2013-02-01 15:11:12 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function OnPlayerMoving(Player)
|
2012-02-01 14:19:51 -05:00
|
|
|
local Carpet = Carpets[ Player ]
|
|
|
|
if( Carpet == nil ) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if( Player:GetPitch() == 90 ) then
|
2013-02-01 15:11:12 -05:00
|
|
|
Carpet:moveTo( cLocation:new( Player:GetPosX(), Player:GetPosY() - 1, Player:GetPosZ() ) )
|
2012-02-01 14:19:51 -05:00
|
|
|
else
|
|
|
|
if( Player:GetPosY() < Carpet:getY() ) then
|
|
|
|
LOGINFO("Fell tru mc!")
|
|
|
|
Player:TeleportTo( Player:GetPosX(), Carpet:getY(), Player:GetPosZ() )
|
|
|
|
end
|
|
|
|
Carpet:moveTo( cLocation:new( Player:GetPosX(), Player:GetPosY(), Player:GetPosZ() ) )
|
|
|
|
end
|
2013-02-01 15:11:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|