User Tag List

Results 1 to 1 of 1

Thread: Target a random non-tank player

  1. #1
    Respected Member
    Join Date
    Sep 2013
    Thanked 0 Times in 0 Posts

    [SOLVED] Target a random non-tank player

    Hello friends, I'm trying make my creature target a player that is not a tank.

    local targets = creature:GetAITargets()
    	local target = creature:GetAITarget(1, true, math.random(2, CountTargets(targets)))
    function CountTargets(t)
    	local count = 0
    	for _, v in pairs(t) do count = count + 1 end
        return count
    What I did here is select all targets from top aggro to bottom. In this case there were 3 targets counted in total. Index starts at 1 so skipping the top aggro tank I start at 2 with math.random. I printed it and it returns either 2 or 3. For some reason it sometimes finds a target and else its nil but when it does find it, it appears to always be the same player there are 2 non-tanks in this case. Am I missing something here?

    PS I know of the GetAITargetsCount method but it returns a userdata (don't know this datatype) not a number and it doesn't convert with tonumber so can't be used in math.random.
    Last edited by GanjaNoodle; 02-15-2016 at 06:01 PM. Reason: Oops, as tables start with index 1 I thought position would too for some reason, changing it to 1 skipping 0 fixed it.
    1 year registered Member Level XV

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