2013-06-15 10:26:21 -04:00
|
|
|
local Carpets = {}
|
2013-12-23 21:58:39 -05:00
|
|
|
local PLUGIN
|
2013-06-15 10:26:21 -04:00
|
|
|
|
|
|
|
function Initialize( Plugin )
|
|
|
|
Plugin:SetName( "MagicCarpet" )
|
2013-10-02 17:01:01 -04:00
|
|
|
Plugin:SetVersion( 2 )
|
2013-06-15 10:26:21 -04:00
|
|
|
|
2013-08-21 16:03:50 -04:00
|
|
|
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_MOVING, OnPlayerMoving)
|
|
|
|
cPluginManager.AddHook(cPluginManager.HOOK_DISCONNECT, OnDisconnect)
|
2013-06-15 10:26:21 -04:00
|
|
|
|
2013-10-02 17:01:01 -04:00
|
|
|
local PluginManager = cPluginManager:Get()
|
2013-06-15 10:26:21 -04:00
|
|
|
PluginManager:BindCommand("/mc", "magiccarpet", HandleCarpetCommand, " - Spawns a magical carpet");
|
2013-12-23 21:58:39 -05:00
|
|
|
|
|
|
|
PLUGIN = Plugin
|
|
|
|
|
2013-10-02 17:01:01 -04:00
|
|
|
LOG( "Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
|
2013-06-15 10:26:21 -04:00
|
|
|
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 ]
|
2013-10-08 16:52:12 -04:00
|
|
|
|
2013-06-15 10:26:21 -04:00
|
|
|
if( Carpet == nil ) then
|
|
|
|
Carpets[ Player ] = cCarpet:new()
|
2013-10-04 17:22:01 -04:00
|
|
|
SendMessageSuccess(Player, "You're on a magic carpet!")
|
|
|
|
SendMessage(Player, "Look straight down to descend. Jump to ascend.")
|
2013-06-15 10:26:21 -04:00
|
|
|
else
|
|
|
|
Carpet:remove()
|
|
|
|
Carpets[ Player ] = nil
|
2013-10-04 17:22:01 -04:00
|
|
|
SendMessageSuccess(Player, "The carpet vanished!")
|
2013-06-15 10:26:21 -04:00
|
|
|
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
|
2013-08-02 08:48:59 -04:00
|
|
|
Player:TeleportToCoords(Player:GetPosX(), Carpet:getY() + 0.2, Player:GetPosZ())
|
2013-06-15 10:26:21 -04:00
|
|
|
end
|
|
|
|
Carpet:moveTo( cLocation:new( Player:GetPosX(), Player:GetPosY(), Player:GetPosZ() ) )
|
|
|
|
end
|
2013-12-23 21:58:39 -05:00
|
|
|
end
|