Home / Music

Player music API

Control the background soundtrack on one online player from a Farkit Lua plugin.

Methods

MethodBehavior
p:playMusic(trackId)Play a bundled music track on the player. The track ID is its filename without the extension, for example Farlands or calm1. Playback is one-shot; automatic music may resume after it finishes.
p:stopMusic()Stop background music and pause automatic soundtrack selection for that player.
p:resumeMusic()Resume the automatic randomized soundtrack.

Example

on("join", function(event)
  event.player:playMusic("Farlands")
end)

command("music-off", function(sender)
  if sender.isPlayer then
    sender:stopMusic()
    sender:send("Music stopped.")
  else
    sender:send("Run this command in-game.")
  end
  return true
end)

Track IDs and requirements

IDs are case-insensitive and may contain only letters, numbers, underscores, and hyphens. The client must have the matching OGG file bundled under resources/music/ or resources/newmusic/; the standard bundle includes calm1–calm3, hal1–hal4, nuance1–nuance2, piano1–piano3, and Farlands.

To add a track to a client build, put its OGG file in orig/jars/resources/music/ and rebuild the client with orig/conf/build-client.sh. Update both the Faraway server and client; stock or older clients do not support the music control packet and may disconnect if sent it.

Return values

The methods return true when the command was sent to an online player, and false if the player is offline. This does not confirm that the client has that track ID or that its music volume is enabled.

Farlands distance weighting

The bundled Farlands track also participates in automatic music selection. Its chance starts at the same odds as one individual track within 100 blocks of (0, 0), rises by one percentage point per 75 blocks up to 1,000 blocks, then smoothly reaches 25% at 10,000 blocks and remains capped. Distance uses max(abs(X), abs(Z)).