DISPLAY
function()
  if aura_env.errorFlag == 0 then
    if aura_env.triggerState == 1 then
      local tt = math.floor((GetTime() - aura_env.startTime) * 10)
      local nameplateindex = {}
      local pointer = 1
      if aura_env.target == 0 then
        for i = 1, 40 do
          if UnitIsPlayer("nameplate" .. i) and UnitIsFriend("player", "nameplate" .. i) then
            nameplateindex[pointer] = i
            pointer = pointer + 1
          end
        end
      end
      if aura_env.target == 1 then
        for i = 1, 40 do
          if UnitIsPlayer("nameplate" .. i) and UnitIsEnemy("player", "nameplate" .. i) then
            nameplateindex[pointer] = i
            pointer = pointer + 1
          end
        end
      end
      if aura_env.target == 2 then
        for i = 1, 40 do
          if UnitIsPlayer("nameplate" .. i) then
            nameplateindex[pointer] = i
            pointer = pointer + 1
          end
        end
      end
      if nameplateindex[1] == nil then
        nameplateindex[1] = UnitName("player")
      end
      if tt ~= aura_env.lastTime and tt % aura_env.tickRate == 0 then
        DoEmote(aura_env.emoteToken, "nameplate" .. nameplateindex[aura_env.pointer2])
        aura_env.pointer2 = aura_env.pointer2 + 1
        aura_env.lastTime = tt
      end
      if aura_env.pointer2 >= pointer then
        aura_env.pointer2 = 1
      end
    end
  end
end

CHAT_MSG_WHISPER
function(_,msg,sender)
  if aura_env.errorFlag == 0 then
    sender = string.match(sender, "%a+")
    if aura_env.caseSensitive == 0 then
      msg = msg:lower()
      aura_env.triggerOn = aura_env.triggerOn:lower()
      aura_env.triggerOff = aura_env.triggerOff:lower()
    end
    if sender == UnitName("player") and msg == aura_env.triggerOn and aura_env.triggerState == 0 then
      aura_env.triggerState = 1
      print("ENABLED")
    end
    if sender == UnitName("player") and msg == aura_env.triggerOff and aura_env.triggerState == 1 then
      aura_env.triggerState = 0
      print("DISABLED")
    end
  end
end

INIT AND SHOW
--Word to turn on
aura_env.triggerOn = "on"
--Word to turn off
aura_env.triggerOff = "off"
--Case sensitive input?
aura_env.caseSensitive = 0
--Tick interval with 10 being 1 second; must not be <1
aura_env.tickRate = 5
--Emote
aura_env.emoteToken = "wave"
--0 for friendlies, 1 for enemies, 2 for both
aura_env.target = 0

--Do NOT change anything from code below
--For info, questions, feedback or anything alike mail Pinkiepiie on Felsong
aura_env.startTime = GetTime()
aura_env.pointer2 = 1
aura_env.lastTime = 0
aura_env.triggerState = 0
aura_env.errorFlag = 0

if aura_env.triggerOn == "" then
  print("|cFFFF0000ERROR::|cFFFFFFFF triggerOn must not be empty!")
  aura_env.errorFlag = 1
end
if aura_env.triggerOff == "" then
  print("|cFFFF0000ERROR::|cFFFFFFFF triggerOff must not be empty!")
  aura_env.errorFlag = 1
end
if aura_env.caseSensitive ~= 0 and aura_env.caseSensitive ~= 1 then
  print("|cFFFF0000ERROR::|cFFFFFFFF caseSensitive must be 1 or 0!")
  aura_env.errorFlag = 1
end
if aura_env.target ~= 0 and aura_env.target ~= 1 and aura_env.target ~= 2 then
  print("|cFFFF0000ERROR::|cFFFFFFFF target must be either 0, 1 or 2!")
  aura_env.errorFlag = 1
end
if aura_env.tickRate < 1 then
  print("|cFFFF0000ERROR::|cFFFFFFFF tickRate must be > 1!")
  aura_env.errorFlag = 1
end
if aura_env.emoteToken == "" then
  print("|cFFFF0000ERROR::|cFFFFFFFF emoteToken must not be empty!")
  aura_env.errorFlag = 1
end
if aura_env.errorFlag == 0 then
  print("-------------------------------------------------------------")
  print("Dave's emote spam bonanza extravaganza!")
  print("|cFFFF7F7FNAMEPATES MUST BE ENABLED FOR THIS TO WORK!!")
  print("~~only works on players~~")
  print("Whisper yourself |cFF00FF00" .. aura_env.triggerOn .. "|cFFFFFFFF to unleash mayhem!")
  print("To stop the spam whisper |cFFFF0000" .. aura_env.triggerOff .. "|cFFFFFFFF")
  print("Current emote is |cFF7F7FFF" .. aura_env.emoteToken .. "|cFFFFFFFF")
  if aura_env.target == 0 then
    print("Currently spamming |cFF7FFF7Ffriendlies!|cFFFFFFFF")
  end
  if aura_env.target == 1 then
    print("Currently spamming |cFFFF7F7Fenemies!|cFFFFFFFF")
  end
  if aura_env.target == 2 then
    print("Currently spamming |cFF7F7FFFboth!|cFFFFFFFF")
  end
  print("-------------------------------------------------------------")
end
