P

PlayMUD.online

Lua Scripts

Automation

Lua scripts are shared helper libraries.

Enabled Scripts preload before Lua triggers and Lua aliases. They are the place for reusable functions and tables, not automatic lifecycle automation.

Library Pattern

function captureVitals(text)
  local hp, maxhp = string.match(text, "^Hp:(%d+)/(%d+)")
  if hp then
    state.hp = hp
    state.maxhp = maxhp
  end
end

function showTarget(name)
  echo("<cyan>Target:<reset> " .. tostring(name))
end

function delayedLook()
  return timer(5, [[ send("look") ]])
end

Compile validates a Script in restricted preload mode before it can be enabled. Top-level function and table definitions are allowed. Top-level send(), echo(), highlight(), widget changes, and variable/state writes are blocked.

Helper functions may create timers when a Lua trigger or Lua alias calls them. Timers are temporary browser-side automation and are not saved as profile settings.

Calling Helpers

-- Lua trigger code
captureVitals(line)

-- Lua alias code
showTarget(matches[2])

Lua triggers and Lua aliases load enabled Scripts first, then run their own code. Helper functions can send commands, echo text, highlight output, update variables, update state, and define widgets when called from a trigger or alias.

Structured Data

function currentRoomName()
  local room = batclient.mapper.current
  return room and room.shortName or ""
end

function currentHP()
  return gmcp.Char and gmcp.Char.Vitals and gmcp.Char.Vitals.hp
end

Scripts can read the latest gmcp, batclient, vars, and state snapshots while preloading. See GMCP and BatMUD Variables.

Shared Scope

function luashow(name)
  echo("<cyan>Lua:<reset> " .. tostring(name))
end

Every enabled Script is loaded before Lua triggers and Lua aliases run. This is the place for reusable functions such as luashow().

Function and table globals stay inside the Lua sandbox. Scalar globals such as strings, numbers, and booleans update persistent Variables only when assigned by a Lua trigger or Lua alias, not during Script preload.

Detached Sessions

Browser-side Lua automation does not run while the browser is detached, and replayed output does not fire triggers. Widgets retain their last browser value until fresh output updates state after resuming.