User Tools

Site Tools


lua:scripting:examples:findtargets

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
lua:scripting:examples:findtargets [2024/07/04 21:32] – created astarklua:scripting:examples:findtargets [2024/07/04 21:36] (current) astark
Line 1: Line 1:
 +====== 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.
 +
 <code lua> <code lua>
 function getTargets() function getTargets()
Line 25: Line 29:
   end   end
 end end
 +
  
 </code> </code>
 +
 +====== 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.
 +
 +<code lua>
 +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
 +
 +</code>
 +
  
lua/scripting/examples/findtargets.1720128728.txt.gz · Last modified: 2024/07/04 21:32 by astark