User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 7 of 12

Thread: NPC get units in range.

  1. #1
    Member
    Join Date
    Jul 2016
    Posts
    15
    XP
    176
    Level
    2
    Thanks
    0
    Thanked 1 Time in 1 Post

    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.

  2. #2
    Founder <span style='color: #FF4500'>Tommy</span>'s Avatar
    Join Date
    Apr 2013
    Posts
    7,391
    XP
    3,449,104
    Level
    378
    Thanks
    889
    Thanked 1,856 Times in 1,119 Posts
    Have you tried :GetNearObjects(range)? :GetAITargets() 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.

  3. #3
    Original Poster
    Member
    Join Date
    Jul 2016
    Posts
    15
    XP
    176
    Level
    2
    Thanks
    0
    Thanked 1 Time in 1 Post
    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 by LordSeaworth; 07-18-2016 at 07:35 PM.
    Achievements:
    Member 7 days registered Level II

  4. #4
    Mad Scientist <span style='color: #008000'><span class='glow_006400'>slp13at420</span></span>'s Avatar



    Join Date
    Dec 2013
    Location
    Idaho
    Posts
    2,480
    XP
    20,134,655
    Level
    500
    Thanks
    1,086
    Thanked 329 Times in 211 Posts
    there is also these 2:
    unit:GetFriendlyUnitsInRange(x);

    unit:GetUnfriendlyUnitsInRange(x);

    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?
    Last edited by slp13at420; 07-18-2016 at 09:09 PM.
    Achievements:
    Shopper Got a Sticky! Member 1 year registered Level XL Level D
    Awards:
    Pot Head LOL Raffle Winner Top Tagger Donator Hangman Scripter Repacker Drunk Support Member of Staff Da Bomb!
    "Cuz PvP's better with a bag 'o' weed"
    !! King Spade !!

    -Guild Plot System-
    Grumbo'z Guild Warz


    -VIP System-
    Grumbo'z VIP System

  5. #5
    Moderator / Eluna Dev <span style='color: #FF0000'><span class='glow_8B0000'>Rochet2</span></span>'s Avatar
    Join Date
    Apr 2013
    Location
    Finland
    Posts
    1,859
    XP
    13,487
    Level
    35
    Thanks
    95
    Thanked 591 Times in 418 Posts
    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.
    Awards:
    Support LOL Scripter Facepalm! Raffle Winner
    rochet2.github.io - Home of great codes

  6. #6
    Original Poster
    Member
    Join Date
    Jul 2016
    Posts
    15
    XP
    176
    Level
    2
    Thanks
    0
    Thanked 1 Time in 1 Post
    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?

  7. The Following User Says Thank You to LordSeaworth For This Useful Post:


  8. #7
    Mad Scientist <span style='color: #008000'><span class='glow_006400'>slp13at420</span></span>'s Avatar



    Join Date
    Dec 2013
    Location
    Idaho
    Posts
    2,480
    XP
    20,134,655
    Level
    500
    Thanks
    1,086
    Thanked 329 Times in 211 Posts
    yea a global method like
    Code:
    unit = GetUnitByGUID(guid);
    would be handy from time to time but I havnt seen anything .. yet...
    Achievements:
    Shopper Got a Sticky! Member 1 year registered Level XL Level D
    Awards:
    Pot Head LOL Raffle Winner Top Tagger Donator Hangman Scripter Repacker Drunk Support Member of Staff Da Bomb!
    "Cuz PvP's better with a bag 'o' weed"
    !! King Spade !!

    -Guild Plot System-
    Grumbo'z Guild Warz


    -VIP System-
    Grumbo'z VIP System

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •