User Tools

Site Tools


lua:scripting:examples:findtargets

This is an old revision of the document!


Targeting Characters

This function will loop through players in the room and look for a non-cleric/non-templar character to be assigned the 'target' or 'tank' role. Then it looks for a character who is a cleric or templar to assign them as the primary healer. The third character in the room will be assigned as the 'third' variable, allowing for easier targeting by the NPC.

function getTargets()
  -- Find a non-healer target to be the de-facto tank
  for _, player in ipairs(mob.room.players) do
    -- echo ("player = "..player.name)
    -- echo ("class = "..player.class)
    if not(player.class == "cleric" or player.class == "templar") and target == nil then
      target = player
      -- echo("chosen target = "..target.name)
    elseif target == nil then
      target = mob.room.players[1]
      -- echo("default target = "..target.name)
    end
    if player.class == "cleric" or player.class == "templar" and healer == nil then
      healer = player
      -- echo("healer = "..healer.name)
    else
      healer = nil
    end
    if not(healer == nil) and not(target == nil) and #mob.room.players> 2 then
      third = player
    else
      third = mob.room.players[2] or nil
    end
  end
end

Using the targets

lua/scripting/examples/findtargets.1720128860.txt.gz · Last modified: 2024/07/04 21:34 by astark