Lynx Lua scripting

Guide

Example, Mobile Legends

The mlbb namespace exposes the entity snapshot and the room. This script reads mlbb.entities() and logs each visible enemy with its health and distance from the local hero, once a second.

Mobile Legends has no per-game events, so the work runs in paint and throttles itself with client.timestamp (milliseconds).

local next_log = 0

client.set_event_callback("paint", function()
  local now = client.timestamp()
  if now < next_log then return end
  next_log = now + 1000

  local snapshot = mlbb.entities()
  if not snapshot.ready or not snapshot.local_player then return end

  local me = snapshot.local_player.position
  for index, enemy in ipairs(snapshot.enemies) do
    if enemy.visible and not enemy.dead and enemy.position then
      local hp = enemy.health or 0
      local max = enemy.maximum_health or 0
      client.log(string.format(
        "enemy %d: %d/%d hp, %.1f away",
        index, hp, max, vector.distance(me, enemy.position)
      ))
    end
  end
end)

Notes

  • snapshot.ready is false outside a match. local_player is absent until the local hero spawns.
  • A field on an entity is absent when the game did not expose it that frame, so read health and maximum_health with a default.
  • enemy.position is a vec3; vector.distance accepts two vec3 tables and is always available.
  • mlbb.room() returns the lobby or match room with every player’s hero, rank and score. Outside a room it returns nil and a reason string.

See the mlbb reference for the field lists.