Skip to content
Urguwno edited this page Jul 13, 2014 · 2 revisions

Entity

  • The Entity is the central game-object (often called UNIT too). Entities are returned by the EntityList or by some functions like Player:GetTarget().
  • The Entity object is a lua table itself and has several entries itself.

Accessing an Entity

  • Here we are calling the EntityList to give us the nearest object on the mesh within a maxdistance of 20 which we can attack. The 'd' - debug print into the console the ID of that Entity as well as the whole table with all attributes.
  • Example:
local el = EntityList("nearest,onmesh,attackable,maxdistance=20")
if ( el ) then
   local i,e = next(el)
   if (i~=nil and e~=nil) then
      -- the 'd' command is a global command for printing out information into the console
      d("EntityID: ".. tostring(i).. " Entity : "..tostring(e))
   end  
end
  • The returned Entity e is a lua table and the i is the EntityID.
  • The Entity attributes can be accessed like this:
-- the 'd' command is a global command for printing out information into the console
d(e.hp.percent)
-- returns the health percentage value of this entity 'e'
d(e.targetid)
-- returns the targetID of this 'e'
d(e.distance)
-- returns the distance to this entity 'e'

Entity Attributes

name
Returns Entity Name (string).
id
Returns Entity ID (number).
serverid
Returns Entity serverID (number).
type
Returns Entity UNIT_TYPE(number).
targetid
Returns the current targetID of the Entity.
contentid
Returns an unique ID for that type of Entity (number).
hp
Returns a lua table which holds health values (table).
```lua -- the 'd' command is a global command for printing out information into the console local hptable = Player.hp d(hptable.current) -- current Health d(hptable.max) -- max Health d(hptable.percent) -- Health percent ```
pos
Returns a lua table which holds the position of that Entity (table).
-- the 'd' command is a global command for printing out information into the console
local postable = Player.pos
d(postable.x) -- x position
d(postable.y) -- y position
d(postable.z) -- z position
d(postable.height) -- height of the unit
d(postable.facingangle) -- facing angle of the unit
distance
Returns (3D) distance to that Entity (number).
pathdistance
Returns path distance measured with the navigationsystem towards that Entity (number).
onmesh
Returns if this Entity is on the currently loaded navmesh (boolean).
onmeshexact
Returns if this Entity is on the currently loaded navmesh (boolean). This is a slightly more precise check
radius
Returns the size / radius of that Entity. (number).
aggro
Returns if Entity is aggro towards the player. (boolean).
aggropercentage
Returns a numeric value 0-100 which represents the amount of aggro the Entity has towards the player. (number).
attackable
Returns if the player can attack this Entity (includes a targetable check already) (boolean).
targetable
Returns if the player can target this Entity (boolean).
killable
Returns if the entity is killable
alive
Returns if the health of that Entity is larger 0 (boolean).
dead
Returns if the health of that Entity is 0 (boolean).
hostile
Returns if the Entity is hostile(boolean).
friendly
Returns if the Entity is friendly(boolean).
incombat
Returns if the Entity is incombat(boolean).
lineofsight
Returns if that Entity is in line of sight to the player (boolean).
class
Returns the classname
interacttype
Returns the interacttype
interactname
Returns the interact name
attitude
Returns the attitude towards the player
isvendor
Returns if the entity is a vendor

-- I'm too lazy, most are self explaining:

isswimming
isghost
isnpc
isswimming
iscritter
isstealthed
iswerewolf
isbossmonster
isfalling
stealthstate
iscasting
ischanneling
castinfo
Returns a lua table containing the current cast information.
.starttime .endtime .abilityid .ischanneling .name
Clone this wiki locally