PDA

View Full Version : TrinityCore WotLK NPC get units in range.



LordSeaworth
07-18-2016, 07:23 PM
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.

Tommy
07-18-2016, 07:27 PM
Have you tried :GetNearObjects(range) (http://eluna.emudevs.com/WorldObject/GetNearObjects.html)? :GetAITargets() (http://eluna.emudevs.com/Creature/GetAITargets.html) returns units in the creature's threat list so that's probably why it is nil for you, if you are trying to get creatures normally.

LordSeaworth
07-18-2016, 07:33 PM
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

slp13at420
07-18-2016, 08:34 PM
there is also these 2:
unit:GetFriendlyUnitsInRange(x); (http://eluna.emudevs.com/Unit/GetFriendlyUnitsInRange.html)

unit:GetUnfriendlyUnitsInRange(x); (http://eluna.emudevs.com/Unit/GetUnfriendlyUnitsInRange.html)

these will return a table of all friendly or unfriendly units within range x.
then you could sift thru and filter out the player units.

dunno if those will help but its another route you could use as a fallback route.

can you post the block of code you are trying to get working?

Rochet2
07-18-2016, 09:21 PM
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.

LordSeaworth
07-19-2016, 09:13 PM
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
07-20-2016, 01:55 AM
yea a global method like
unit = GetUnitByGUID(guid); would be handy from time to time but I havnt seen anything .. yet...

LordSeaworth
07-20-2016, 09:41 AM
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?

LordSeaworth
07-20-2016, 03:14 PM
yea a global method like
unit = GetUnitByGUID(guid); would be handy from time to time but I havnt seen anything .. yet...

Seems that method isn't found? I'm looking on http://eluna.emudevs.com/

Rochet2
07-20-2016, 04:24 PM
There is no method to get a creature etc by database ID.
You can only search by guid, which is a different number for creatures in instances and possibly in normal maps as well.
However ingame if you have a creature spawned and get the creature's guid and then use that to search for it later, you should find it if it still exists in the world.

http://eluna.emudevs.com/Object/GetGUID.html
http://eluna.emudevs.com/Map/GetWorldObject.html

Foereaper
07-20-2016, 11:05 PM
yea a global method like
unit = GetUnitByGUID(guid); 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
07-20-2016, 11:28 PM
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...