• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

TrinityCore WotLK NPC get units in range.

Hey,
I'm new to TrinityCore and ElunaLua.
I'm wondering how to get a list of units (players,other npcs) of a certain npc's range.

I've both tried GetAITarget and GetAITargets but both of them return nill.

Could anyone point me in the right direction on how to get units in range of a certain NPC.
 
I've tried the :GetAITargets but gives a empty table.

I'm trying to get all the units in the distance of the npc i'm running the code from. With units i don't mean players but other NPC that are close to the npc.


PS: I come from arcemu in the past so with arcemu i could use pUnit:GetInRangeUnits().
Trying to find the equalivant for TrinityCore
 
Last edited:

Rochet2

Moderator / Eluna Dev
if what slp suggested doesnt work, then try what tommy said about nearobjects (it is so flexible that you should be able to do this with it) or try to get all creatures in range and get all players in range and join these two results (or loop them separately or whatever).
GetAItarget probably doesnt work because it has to do with threat list and your NPC might not be aggroed by the units you try to get.
 
slp13at420, Thank you those two functions were what i was looking for.

BTW: Just random question. Is there a way to get a CreatureObject form a spawned npc with a certain id?
Something like

GetCreatureObject(NPCID/NPCSPAWNID/NPCDATABASEID?)

So that you could get a creature object globally outside a certain function?
 

slp13at420

Mad Scientist
yea a global method like
Code:
[COLOR="#808080"]unit = GetUnitByGUID(guid);[/COLOR]
would be handy from time to time but I havnt seen anything .. yet...
 
Thanks again xP

Have to say only recently changed to TrinityCore since I used to use arcemu back in the day when i was working on my project. But since that is dead I decided to change to TrinityCore. The compiling was perfect. No issues whatsoever. Installed the lua engine en now i finnaly can work on my long awaited project.
This community is very helpfull i'll stay around on these forums.
Just wanted to say that.

PS: I'll have alot of questions while i'm working on the thing i'm working on.
What is the suggested way on this forum.

Create one help topic in the forum and ask questions in that one topic.
Or for each question i might come up with start a new topic?
 
Last edited:

Rochet2

Moderator / Eluna Dev

Foereaper

Founder
yea a global method like
Code:
[COLOR="#808080"]unit = GetUnitByGUID(guid);[/COLOR]
would be handy from time to time but I havnt seen anything .. yet...

Problem with this is object access safety, and you cannot be sure that the creature is actually loaded whenever you try to access it by its guid.
 

slp13at420

Mad Scientist
Problem with this is object access safety, and you cannot be sure that the creature is actually loaded whenever you try to access it by its guid.

oh yea I totally agree . if the map isn't loaded you can have all sorts of problems trying to just spawn an npc or gob in an unloaded map let alone trying to call it or w/e lol

- - - Updated - - -

:rofl: I learned that the hard way with my willow-the-wisp capture the flags . when it would spawn where a map wasn't loaded that's the reason for the spawned checks on them...
 
Top