User Tools

Site Tools


lua:scripting:examples:findtargets

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

FIrst we call the 'getTarget()' function to assign our targets. We set variables to find the % of HP our target and healers have. We re-target occasionally (rand 20) to ensure that we're fighting the desired target, and that they weren't rescud by someone else. Last, we have some fighting logic to determine which abilities to use and when.

getTargets()
 
if target then
  targetHp = target.hp / target.maxhp * 100
end
 
if healer then
  healerHp = healer.hp / healer.maxhp * 100
end
 
-- Re-target in case of rescue
if rand(20) and not(target == nil) then
  mdo("kill "..target.name)
end
 
if targetHp <20 or healerHp <20 then
  mdo("shield "..healer.name)
  mdo("shield "..third.name)
  lag = lag + 2
  return
elseif targetHp <90 then
  mdo("fatal "..target.name)
end
lua/scripting/examples/findtargets.txt · Last modified: 2024/07/04 21:36 by astark