[Addon dev] How to get reference for targeted creature?

Have a really dumb question? Ask it here to get help from the experts (or those with too much time on their hands)

Moderator: Moderator

Post Reply
Message
Author
Eliont
Low Yeek
Posts: 9
Joined: Sat Sep 20, 2014 11:28 am

[Addon dev] How to get reference for targeted creature?

#1 Post by Eliont »

Hello and good time of day.
How in custom ability code get reference to creature that targeted by this ability?
And than get properties of that creature.

Thanks in advance.

0player
Uruivellas
Posts: 717
Joined: Fri May 24, 2013 4:27 pm

Re: [Addon dev] How to get reference for targeted creature?

#2 Post by 0player »

IIRC the syntax is calling the map, like game.map(x, y, ACTOR)

grayswandir
Uruivellas
Posts: 708
Joined: Wed Apr 30, 2008 5:55 pm

Re: [Addon dev] How to get reference for targeted creature?

#3 Post by grayswandir »

Code: Select all

local actor = game.level.map(x, y, Map.ACTOR)
This'll get the actor at the specified spot on the map. They're just big tables, so for instance actor.life would be how much life it has.

If you want to get multiple targets, a general way to do that is pass project a function instead of a damage type.

Code: Select all

-- A radius 1 ball attack with range 3.
local tg = {type = 'ball', range = 3, radius = 1,}
-- Get the player to select an x/y location, showing an overlay for a radius 1 ball.
local x, y = self:getTarget(tg)
-- Cancel out without taking an action if the player cancelled.
if not x or not y then return end
-- This does 2 things. First, it picks a closer square if the targeted square is out of range (3, in this case).
-- Second, if we target a wall, this'll give us the coordinates one tile before the wall, as that's where ball attacks blow up.
-- The second and third returns are the actual wall coordinates (or the same if there's no wall in the first place).
local _, _, _, x, y = self:canProject(tg, x, y) 
-- This sends out the actual effects to all targeted.
self:project(tg, x, y, function(x, y)
  -- Get the targeted actor.
  local actor = game.level.map(x, y, Map.ACTOR)
  -- Cancel if there's nothing there.
  if not actor then return end
  -- Do whatever with the actor.
  actor:die()
end)

You can also just collect all the targets in a table and then do something with them later.

Code: Select all

local targets = {}
self:project(tg, x, y, function(x, y)
  local actor = game.level.map(x, y, Map.ACTOR)
  table.insert(targets, actor)
end)
-- Do something with targets here.
Addons: Arcane Blade Tweaks, Fallen Race, Monk Class, Weapons Pack
Currently working on Elementals. It's a big project, so any help would be appreciated. :)

Eliont
Low Yeek
Posts: 9
Joined: Sat Sep 20, 2014 11:28 am

Re: [Addon dev] How to get reference for targeted creature?

#4 Post by Eliont »

Thanks, theese:

Code: Select all

	
action = function(self, t)
        local tg = {type="bolt", range=self:getTalentRange(t), talent=t}
        local x, y, target = self:getTarget(tg)
works for me. "target" contains targeted creature object.

Another question - is there any way to target skill in skill list window, or altering binding window?
And is somewhere exists a complete reference?

grayswandir
Uruivellas
Posts: 708
Joined: Wed Apr 30, 2008 5:55 pm

Re: [Addon dev] How to get reference for targeted creature?

#5 Post by grayswandir »

That'll get you whatever the player clicked on, even if it's out of range.
Addons: Arcane Blade Tweaks, Fallen Race, Monk Class, Weapons Pack
Currently working on Elementals. It's a big project, so any help would be appreciated. :)

Post Reply