Toggle Fly
Code
-- Imports
color = newInstance("#.wrappers.ChatColorWrapper", {plugin.getPlugin()})
-- A simple fly command
local flyCommand = plugin.addCommand({name="fly", permission="lukkit.command.fly"}, function(cmd)
local sender = cmd.getSender()
-- Make sure it's a player sending the command
if not cmd.isPlayerSender() then
sender:sendMessage(color.DARK_RED .. "Only players can fly, silly!")
return
end
-- If the player is flying the make them fly, otherwise make them fall
if sender:isFlying() then
sender:setFlying(false)
sender:setAllowFlight(false)
sender:sendMessage(color.RED .. "Fly off")
else
-- This allows the player to fly
sender:setAllowFlight(true)
sender:setFlying(true)
-- The player won't fly if it is on the ground, so we need to move them up a little
sender:teleport(sender:getLocation():add(0, 0.000001, 0))
sender:sendMessage(color.GREEN .. "Fly on")
end
end)Last updated