Page 1 of 1
[Addon dev] How to get reference for targeted creature?
Posted: Sat Sep 20, 2014 1:06 pm
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.
Re: [Addon dev] How to get reference for targeted creature?
Posted: Sat Sep 20, 2014 3:14 pm
by 0player
IIRC the syntax is calling the map, like game.map(x, y, ACTOR)
Re: [Addon dev] How to get reference for targeted creature?
Posted: Sat Sep 20, 2014 4:43 pm
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.
Re: [Addon dev] How to get reference for targeted creature?
Posted: Sat Sep 20, 2014 6:08 pm
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?
Re: [Addon dev] How to get reference for targeted creature?
Posted: Sat Sep 20, 2014 7:00 pm
by grayswandir
That'll get you whatever the player clicked on, even if it's out of range.