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.
[Addon dev] How to get reference for targeted creature?
Moderator: Moderator
Re: [Addon dev] How to get reference for targeted creature?
IIRC the syntax is calling the map, like game.map(x, y, ACTOR)
-
- Uruivellas
- Posts: 708
- Joined: Wed Apr 30, 2008 5:55 pm
Re: [Addon dev] How to get reference for targeted creature?
Code: Select all
local actor = game.level.map(x, y, Map.ACTOR)
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.
Currently working on Elementals. It's a big project, so any help would be appreciated.

Re: [Addon dev] How to get reference for targeted creature?
Thanks, theese:
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?
Code: Select all
action = function(self, t)
local tg = {type="bolt", range=self:getTalentRange(t), talent=t}
local x, y, target = self:getTarget(tg)
Another question - is there any way to target skill in skill list window, or altering binding window?
And is somewhere exists a complete reference?
-
- Uruivellas
- Posts: 708
- Joined: Wed Apr 30, 2008 5:55 pm
Re: [Addon dev] How to get reference for targeted creature?
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.
Currently working on Elementals. It's a big project, so any help would be appreciated.
