Skip to content

/heal

This plugin adds a /heal command that fills your health bar. It's your first command that changes something about the player instead of just sending a message.

main.lua
plugin.addCommand({
    name = "heal",
    description = "Heal yourself",
    usage = "/heal"
}, function(event)
    local player = event.getSender()
    player:setHealth(20)
    player:sendMessage("Healed!")
end)

How it works

The command is set up exactly like /hello, and the only new part is player:setHealth(20). setHealth is a method that comes from Minecraft, so it's called with a colon, and 20 is a full health bar, since each heart is worth 2. We also named the variable player this time instead of sender, which shows that the name is up to you, so pick whatever makes your code easiest to read.

Run it as a player

/heal only works when a player runs it. The console isn't a player, so it has no health to fill.

Try it

Take some damage, then type /heal and watch your hearts fill back up.

Next: /feed.