/fly¶
This plugin adds a /fly command that turns flying on and off each time you use it.
main.lua
plugin.addCommand({
name = "fly",
description = "Toggle flying",
usage = "/fly"
}, function(event)
local player = event.getSender()
local canFly = not player:getAllowFlight()
player:setAllowFlight(canFly)
if canFly then
player:sendMessage("Flying is on! Double-tap space to fly.")
else
player:sendMessage("Flying is off.")
end
end)
How it works¶
player:getAllowFlight() asks whether the player is allowed to fly right now, and the answer is either true or false. Putting not in front of it flips the answer, so true becomes false and the other way around, and we save that as canFly. Then player:setAllowFlight(canFly) applies it, which is why the command works as a switch.
The if part picks a message to send. If canFly is true the first message runs, and otherwise the one after else runs.
Try it in survival
In Creative mode you can always fly, so you won't notice a difference there. In Survival, type /fly and then double-tap the space bar.
Next: /rules.