Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2014
1,250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 55.88 KB | None | 0 0
  1. if PQR_Addon_Loaded == nil then
  2.     PQR_Addon_Loaded = true
  3.     --PQR
  4.     --These are functions that are expected to be loaded prior to general bot functionality.
  5.     function PQR_Debug(strText, debugLevel)
  6.    
  7.         if PQR_DebugLevel == "Disabled" then
  8.             return
  9.         end
  10.  
  11.         if debugLevel == nil then
  12.             debugLevel = ""
  13.         end
  14.  
  15.         if PQR_DebugLevel == "Profile" then
  16.             --ONLY display information on the profile level debug.
  17.             if debugLevel == "Profile" then
  18.                 PQR_WriteToChat(strText, "Debug")
  19.             end
  20.         elseif PQR_DebugLevel == "Basic" then
  21.             --Display all debug info that doesn't have "Advanced" tag.
  22.             if debugLevel ~= "Advanced" then
  23.                 PQR_WriteToChat(strText, "Debug")
  24.             end
  25.         elseif PQR_DebugLevel == "Advanced" then
  26.             --Display ALL data.
  27.             PQR_WriteToChat(strText, "Debug")
  28.         else
  29.             --Do nothing.
  30.         end
  31.  
  32.     end
  33.  
  34.     function PQR_DebugP(strText)
  35.         PQR_Debug(strText, "Profile")
  36.     end
  37.  
  38.     function PQR_SetDebug(enabled)
  39.         if enabled == true then
  40.             PQR_DebugEnabled = true
  41.         else
  42.             PQR_DebugEnabled = false
  43.         end
  44.     end
  45.  
  46.     function PQR_WriteToChat(strText, strSuffix)
  47.         if PQR_ShowChat == true then
  48.             if strSuffix == nil then
  49.                 print("|cffff7d0a<|r|cffffd200PQR|r|cffff7d0a>|r "..strText)
  50.             else
  51.                 print("|cffff7d0a<|r|cffffd200PQR "..strSuffix.."|r|cffff7d0a>|r "..strText)
  52.             end
  53.         end
  54.     end
  55.  
  56.     function PQR_LoadLua(fileName, forceRefresh)
  57.         if fileName == nil then
  58.             return false
  59.         end
  60.  
  61.         if forceRefresh == true then
  62.             --user wants to force re-run the Lua file.
  63.             if PQR_LuaTable[fileName] ~= nil then
  64.                 PQR_Debug("Loading Lua File: "..fileName)
  65.                 PQR_LuaLoadedTable[fileName] = true
  66.                 PQR_LuaTable[fileName]()
  67.                 return true
  68.             else
  69.                 return false
  70.             end
  71.         else
  72.             --user only wants to run the Lua file once per session.
  73.             if PQR_LuaTable[fileName] ~= nil then
  74.                 if PQR_LuaLoadedTable[fileName] == true then
  75.                     --we have already loaded the selected file.
  76.                     return true
  77.                 else
  78.                     --we need to run the lua file
  79.                     PQR_LuaLoadedTable[fileName] = true
  80.                     PQR_Debug("Loading Lua File: "..fileName)
  81.                     PQR_LuaTable[fileName]()
  82.                     return true
  83.                 end
  84.             else
  85.                 return false
  86.             end
  87.         end
  88.  
  89.         --if we somehow got here...
  90.         return false
  91.     end
  92.  
  93.     --Setup the update frames.
  94.     --This is considered the 'engine' of the bot, and is constantly being called every frame draw.
  95.     --The bot supports 2 concurrent rotations, the normal 1-4 rotation and an interrupt rotation.
  96.  
  97.     function PQR_EventSend_OnUpdate(self, elapsed)
  98.         PQR_EventSendElapsed = PQR_EventSendElapsed + elapsed
  99.  
  100.         while (PQR_EventSendElapsed > 0.1) do
  101.             PQR_EventSendElapsed = PQR_EventSendElapsed - 0.1
  102.             if PQR_SendEvents then
  103.                 PQR_SendEvents()
  104.             end
  105.         end
  106.     end
  107.  
  108.     function PQR_StopRotation()
  109.         PQR_ChangeRotation = true
  110.     end
  111.  
  112.     function PQR_SwapRotation(newRotation, setRotation)
  113.         local currentRotation = PQR_CurrentRotationNumber
  114.         if currentRotation == nil then
  115.             currentRotation = 0
  116.         end
  117.        
  118.         if setRotation ~= nil then
  119.             currentRotation = setRotation
  120.         end
  121.  
  122.         if tonumber(newRotation) == nil then
  123.             --swap by name
  124.             if newRotation == nil then
  125.                 return false
  126.             end
  127.  
  128.             if strtrim(newRotation) == "" then
  129.                 return false
  130.             end
  131.            
  132.  
  133.             if PQR_Rotations[newRotation] == nil then
  134.                 return false
  135.             else
  136.                 local rotationName = strtrim(newRotation)
  137.                 local tblRotationName = { strsplit(" ", rotationName) }
  138.                 local lbound = 0
  139.                 local ubound = 0
  140.                 rotationName = ""
  141.                 for i=1,100 do
  142.                     --find the last ( and the last )
  143.                     if tblRotationName[i] == nil then
  144.                         break
  145.                     end
  146.  
  147.                     if strfind(tblRotationName[i], "[(]") then
  148.                         lbound = i
  149.                     end
  150.                 end
  151.                 if lbound > 1 then
  152.                     for i=1,lbound -1 do
  153.                         rotationName = rotationName.." "..tblRotationName[i]
  154.                     end
  155.                 end
  156.                 if PQR_RotationName == "* "..strtrim(rotationName) then
  157.                     return false
  158.                 end
  159.  
  160.                 if currentRotation == 0 then
  161.                     PQR_RotationName = "* "..strtrim(rotationName)
  162.                     PQR_ChangeRotation = true
  163.                     PQR_SwappedRotation = true
  164.                 end
  165.                 PQR[currentRotation] = PQR_Rotations[newRotation]
  166.                 return true
  167.             end
  168.  
  169.         else
  170.             --swap by number
  171.             if newRotation < 1 or newRotation > 4 then
  172.                 return false
  173.             end
  174.  
  175.             local rotationName = loadstring("return PQR_Rotation"..newRotation)()
  176.             if rotationName == nil then
  177.                 return false
  178.             end
  179.  
  180.             local tblRotationName = { strsplit(" ", rotationName) }
  181.             local lbound = 0
  182.             local ubound = 0
  183.             rotationName = ""
  184.             for i=1,100 do
  185.                 --find the last ( and the last )
  186.                 if tblRotationName[i] == nil then
  187.                     break
  188.                 end
  189.  
  190.                 if strfind(tblRotationName[i], "[(]") then
  191.                     lbound = i
  192.                 end
  193.             end
  194.             if lbound > 1 then
  195.                 for i=1,lbound -1 do
  196.                     rotationName = rotationName.." "..tblRotationName[i]
  197.                 end
  198.             end
  199.             if PQR_RotationName == "* "..strtrim(rotationName) then
  200.                     return false
  201.             end
  202.             if currentRotation == 0 then
  203.                 PQR_SwappedRotation = true
  204.                 PQR_RotationName = strtrim(rotationName)
  205.                 PQR_ChangeRotation = true
  206.             end
  207.             PQR[currentRotation] = PQR[newRotation]
  208.             return true
  209.         end
  210.  
  211.  
  212.     end
  213.  
  214.     function PQR_EventFrame_OnUpdate(self, elapsed)
  215.         if UnitName == nil then
  216.             --Not ingame, don't do anything.
  217.             PQR_totalElapsed1 = 0
  218.             PQR_totalElapsed2 = 0
  219.             return
  220.         end
  221.  
  222.        
  223.         --Rotation mode
  224.         PQR_totalElapsed1 = PQR_totalElapsed1 + elapsed
  225.  
  226.         while (PQR_totalElapsed1 > PQR_UpdateInterval1) do
  227.             PQR_totalElapsed1 = PQR_totalElapsed1 - PQR_UpdateInterval1
  228.             --Code here executes every Xms (default 100ms, set by user)
  229.             local castManual = tonumber(PQR_CastManual())
  230.             if castManual > 0 then
  231.                 PQR_RegisterMovement(PQR_totalElapsed1)
  232.                 PQR_ManualLoaded = true
  233.                 PQR_ExecuteRotation(castManual)
  234.             end
  235.  
  236.             if PQR_ChangeRotation == true then
  237.                 PQR_ChangeRotation = false
  238.  
  239.                 if PQR_RotationName == PQR_RunningRotationName then
  240.                     --we were passed a change request from the currently running profile.
  241.                     if PQR_RotationEnabled == true then
  242.                         PlaySound(PQR_soundStopRotation, "Master")
  243.                         PQR_Event("PQR_RotationChanged")
  244.                         PQR_WriteToChat(PQR_RotationName.." Disabled.")
  245.                         PQR_RotationEnabled = false
  246.                         PQR_RunningRotationName = ""
  247.                     else
  248.                         --Start rotation
  249.                         PlaySound(PQR_soundStartRotation, "Master")
  250.                         PQR_Event("PQR_RotationChanged", PQR_RotationName)
  251.                         PQR_WriteToChat(PQR_RotationName.." Enabled.")
  252.                         PQR_RunningRotationName = PQR_RotationName
  253.                         PQR_RotationEnabled = true
  254.  
  255.                         --set the flag for profiles
  256.                         PQR_RotationStarted = true
  257.                     end
  258.                 else
  259.                     --we were passed a change request with a new profile name.
  260.  
  261.                     if PQR_RunningRotationName ~= "" then
  262.                         if PQR_SwappedRotation ~= true then
  263.                             PQR_WriteToChat(PQR_RunningRotationName.." Disabled.")
  264.                             PlaySound(PQR_soundChangeRotation, "Master")
  265.                         end
  266.                        
  267.                     else
  268.                         PlaySound(PQR_soundStartRotation, "Master")
  269.                     end
  270.                     PQR_Event("PQR_RotationChanged", PQR_RotationName)
  271.                     PQR_WriteToChat(PQR_RotationName.." Enabled.")
  272.                     if PQR_SwappedRotation ~= true then
  273.                         PQR_RunningRotationName = PQR_RotationName
  274.                     end
  275.                     PQR_RotationEnabled = true
  276.  
  277.                     --set the flag for profiles
  278.                     PQR_ResetMovementTime = 0.5
  279.                     PQR_SpellAvailableTime = 0.125
  280.                     PQR_RotationStarted = true
  281.                     PQR_SwappedRotation = false
  282.                 end
  283.             end
  284.  
  285.             if PQR_RotationEnabled then
  286.                 PQR_RegisterMovement(PQR_totalElapsed1)
  287.                 PQR_ExecuteRotation(0)
  288.             end
  289.         end
  290.    
  291.         --Interrupt mode
  292.         PQR_totalElapsed2 = PQR_totalElapsed2 + elapsed
  293.         while (PQR_totalElapsed2 > PQR_UpdateInterval2) do
  294.             PQR_RegisterMovement(PQR_totalElapsed2)
  295.             PQR_totalElapsed2 = PQR_totalElapsed2 - PQR_UpdateInterval2
  296.             --Code here executes every 50ms.
  297.             if PQR_ChangeInterrupt == true then
  298.                 PQR_ChangeInterrupt = false
  299.                 if PQR_InterruptName == PQR_RunningInterruptName then
  300.                     --we were passed a change request from the currently running profile.
  301.                     if PQR_InterruptEnabled == true then
  302.                         PlaySound(PQR_soundStopInterrupt, "Master")
  303.                         PQR_Event("PQR_InterruptChanged")
  304.                         PQR_WriteToChat(PQR_InterruptName.." Disabled.", "Interrupt")
  305.                         PQR_InterruptEnabled = false
  306.                         PQR_RunningInterruptName = ""
  307.                     else
  308.                         PlaySound(PQR_soundStartInterrupt, "Master")
  309.                         PQR_Event("PQR_InterruptChanged", PQR_InterruptName)
  310.                         PQR_WriteToChat(PQR_InterruptName.." Enabled.", "Interrupt")
  311.                         PQR_RunningInterruptName = PQR_InterruptName
  312.                         PQR_InterruptEnabled = true
  313.  
  314.                         --set the flag for profiles
  315.                         PQR_InterruptStarted = true
  316.                     end
  317.                 else
  318.                     --we were passed a change request with a new profile name.
  319.                     if PQR_RunningInterruptName ~= "" then
  320.                         PQR_WriteToChat(PQR_RunningInterruptName.." Disabled.", "Interrupt")
  321.                     end
  322.                     PlaySound(PQR_soundStartInterrupt, "Master")
  323.                     PQR_Event("PQR_InterruptChanged", PQR_InterruptName)
  324.                     PQR_WriteToChat(PQR_InterruptName.." Enabled.", "Interrupt")
  325.                     PQR_RunningInterruptName = PQR_InterruptName
  326.                     PQR_InterruptEnabled = true
  327.  
  328.                     --set the flag for profiles
  329.                     PQR_InterruptStarted = true
  330.                 end
  331.             end
  332.             if PQR_InterruptEnabled then
  333.                 --Cast next interrupt.
  334.                 PQR_ExecuteInterrupt()
  335.             end
  336.         end
  337.     end
  338.  
  339.     function PQR_SetupInterruptTable()
  340.         if PQR == nil then
  341.             PQR = {}
  342.         end
  343.         PQR.interruptTable = {}
  344.        
  345.         PQR.interruptTable.spell = {}
  346.         PQR.interruptPriorityTable = {}
  347.         PQR.interruptPriorityTable.index = {}
  348.         PQR.interruptPriorityTable.ability = {}
  349.         PQR.interruptPriorityTable.spellid = {}
  350.         PQR.interruptPriorityTable.target = {}
  351.         PQR.interruptPriorityTable.actions = {}
  352.         PQR.interruptPriorityTable.lua = {}
  353.         PQR.interruptPriorityTable.recast = {}
  354.         PQR.interruptPriorityTable.delay = {}
  355.         PQR.interruptPriorityTable.cancelChannel = {}
  356.         PQR.interruptPriorityTable.skipUnknown = {}
  357.         PQR.interruptPriorityTable.requireCombat = true
  358.     end
  359.  
  360.     function PQR_SetupTables()
  361.         --Creates a clean priorityTable
  362.         if PQR == nil then
  363.             PQR = {}
  364.         end
  365.  
  366.         for i=0,4 do
  367.             PQR[i] = {}
  368.            
  369.             PQR[i].priorityTable = {}
  370.             PQR[i].priorityTable.index = {}
  371.             PQR[i].priorityTable.ability = {}
  372.             PQR[i].priorityTable.spellid = {}
  373.             PQR[i].priorityTable.target = {}
  374.             PQR[i].priorityTable.actions = {}
  375.             PQR[i].priorityTable.lua = {}
  376.             PQR[i].priorityTable.recast = {}
  377.             PQR[i].priorityTable.delay = {}
  378.             PQR[i].priorityTable.cancelChannel = {}
  379.             PQR[i].priorityTable.skipUnknown = {}
  380.             PQR[i].priorityTable.requireCombat = true
  381.         end
  382.  
  383.         --delayTable is used to pause the rotation on UNIT_SPELLCAST_SENT/FAILED so a player spamming an ability can cast that ability
  384.         --ex: Divine Shield would be on the delayTable since it is on GCD and the bot spamming it would prevent it.
  385.         PQR.delayTable = {}
  386.         PQR.delayTable.spell = {}
  387.         PQR.delayTable.item = {}
  388.         PQR.delayTable.delay = {}
  389.         PQR.delayTable.delayTime = {}
  390.  
  391.         PQR.losTable = {}
  392.         PQR.losTable.name = {}
  393.         PQR.losTable.time = {}
  394.  
  395.         PQR_Rotations = {}
  396.        
  397.         PQR_Rotations.priorityTable = {}
  398.         PQR_Rotations.priorityTable.index = {}
  399.         PQR_Rotations.priorityTable.ability = {}
  400.         PQR_Rotations.priorityTable.spellid = {}
  401.         PQR_Rotations.priorityTable.target = {}
  402.         PQR_Rotations.priorityTable.actions = {}
  403.         PQR_Rotations.priorityTable.lua = {}
  404.         PQR_Rotations.priorityTable.recast = {}
  405.         PQR_Rotations.priorityTable.delay = {}
  406.         PQR_Rotations.priorityTable.cancelChannel = {}
  407.         PQR_Rotations.priorityTable.skipUnknown = {}
  408.         PQR_Rotations.priorityTable.requireCombat = true
  409.         PQR_Rotations.priorityTable.rotationName = true
  410.     end
  411.  
  412.     function PQR_EventFrame_OnEvent(self, event, ...)
  413.     --  PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  414.     --  PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_SENT")
  415.  
  416.         if event == "PLAYER_ENTERING_WORLD" then
  417.             PQR_EventFrame:Show()
  418.         elseif event == "PLAYER_LOGOUT" then
  419.             --Clean up when we are logging out.
  420.             PQR_RotationEnabled = false
  421.             PQR_InterruptEnabled = false
  422.             PQR_RunningInterruptName = ""
  423.             PQR_RunningRotationName = ""
  424.             PQR_SetupTables()
  425.             PQR_SetupInterruptTable()
  426.         elseif event == "UNIT_SPELLCAST_SUCCEEDED" then
  427.             local unitCaster, unitSpell, _, _, unitSpellID = ...
  428.             if unitCaster ~= "player" then
  429.                 return
  430.             end
  431.             PQR_SetRecastDelay(unitSpellID)
  432.  
  433.             --REMOVE DELAY CODING
  434.             local spell = PQR.delayTable.spell[unitSpell]
  435.             if spell ~= nil then
  436.                 --just remove the delay, this message indicates casting succeeded.
  437.                 PQR_Debug("DELAY: Removed "..unitSpell.." as the cast was successful.")
  438.                 PQR.delayTable.delayTime[unitSpell] = 0
  439.             end
  440.         elseif event == "UNIT_SPELLCAST_START" then
  441.             local unitCaster, unitSpell, _, _, unitSpellID = ...
  442.             if unitCaster ~= "player" then
  443.                 return
  444.             end
  445.             PQR_SetRecastDelay(unitSpellID, true)
  446.         elseif event == "UNIT_SPELLCAST_INTERRUPTED" then
  447.             local unitCaster, unitSpell, _, _, unitSpellID = ...
  448.             if unitCaster ~= "player" then
  449.                 return
  450.             end
  451.             PQR_ResetRecastDelay(unitSpellID)
  452.         elseif event == "UNIT_SPELLCAST_FAILED" or event == "UNIT_SPELLCAST_FAILED_QUIET" then
  453.             local unitCaster, unitSpell, _, _, unitSpellID = ...
  454.             if unitCaster ~= "player" then
  455.                 return
  456.             end
  457.  
  458.             --DELAY CODING
  459.             local incrementDelay = PQR.delayTable.delay[unitSpell]
  460.             local item = PQR.delayTable.item[unitSpell]
  461.             if incrementDelay ~= nil then
  462.                 --This spell has a delay associated with it.
  463.                 if item == nil or item == "" or item == 0 then
  464.                     --no item ID to check.. check if the spell is on cooldown.
  465.                     local spellStart, spellDuration = GetSpellCooldown(unitSpellID)
  466.                     local spellCooldown = spellStart - GetTime() + spellDuration
  467.                     local gcdSpell = PQR_GCDSpellID()
  468.                     local gcdStartTime, gcdDuration = GetSpellCooldown(gcdSpell)
  469.                     local gcdTimeLeft = gcdStartTime + gcdDuration - GetTime()
  470.                     if gcdTimeLeft < 0 then
  471.                         gcdTimeLeft = 0
  472.                     end
  473.                     spellCooldown = spellCooldown - gcdTimeLeft
  474.                     if spellCooldown > 0 then
  475.                         --This spell is on cooldown, remove it's delay
  476.                         PQR_Debug("DELAY: "..unitSpell.." was not added. Spell is on cooldown > GCD.")
  477.                         PQR.delayTable.delayTime[unitSpell] = 0
  478.                     else
  479.                         --This spell is not on CD... increment it's delay time.
  480.                         PQR_Debug("DELAY: "..unitSpell.." was added.")
  481.                         PQR.delayTable.delayTime[unitSpell] = GetTime() + incrementDelay
  482.                     end
  483.                 else
  484.                     --item ID to check
  485.                     local itemStart, itemDuration, itemEnabled = GetItemCooldown(item)
  486.                     local itemCooldown = itemStart - GetTime() + itemDuration
  487.                     if itemCooldown > 0 then
  488.                         PQR_Debug("DELAY: "..unitSpell.." was not added. Item is on cooldown.")
  489.                         --This item is on CD, remove it's delay.
  490.                         PQR.delayTable.delayTime[unitSpell] = 0
  491.                     else
  492.                         --This item is not on CD, increment it's delay time.
  493.                         PQR_Debug("DELAY: "..unitSpell.." was added.")
  494.                         PQR.delayTable.delayTime[unitSpell] = GetTime() + incrementDelay
  495.                     end
  496.                 end
  497.             end
  498.         elseif event == "UI_ERROR_MESSAGE" then
  499.             local errorMessage = ...
  500.             PQR_LastUIError[errorMessage] = GetTime()
  501.             if errorMessage == SPELL_FAILED_NOT_BEHIND then
  502.                 PQR_BehindTime = GetTime()
  503.             elseif errorMessage == SPELL_FAILED_LINE_OF_SIGHT then
  504.                 --code here for LOS failure.
  505.                 if PQR_LastTarget ~= "" then
  506.                     if PQR_LastCastTime > GetTime() - 1 then
  507.                         PQR.losTable.name[PQR_LastTarget] = PQR_LastTarget
  508.                         PQR.losTable.time[PQR_LastTarget] = PQR_LastCastTime
  509.                         PQR_Debug("Added LOS record for "..PQR_LastTarget..".", "Advanced")
  510.                         PQR_LastTarget = ""
  511.                         PQR_LastCastTime = 0
  512.                     end
  513.                 end
  514.             end
  515.         end
  516.     end
  517.  
  518.  
  519.     function PQR_ExecuteRotation(rotationNumber)
  520.         --Check if we are in combat.
  521.         local inCombat = UnitAffectingCombat("player")
  522.         if inCombat == nil then
  523.             inCombat = UnitAffectingCombat("pet")
  524.         end
  525.  
  526.         --Does this rotation require combat?
  527.         local requireCombat = PQR[rotationNumber].priorityTable.requireCombat
  528.  
  529.         --If we are not in combat and this rotation requires combat, and we are in auto-mode... cancel this.
  530.         if (requireCombat == true and inCombat ~= 1) and rotationNumber == 0 then
  531.             return
  532.         end
  533.  
  534.         local nextAbility = PQR_NextAbility(rotationNumber)
  535.  
  536.         if nextAbility ~= -1 then
  537.             --we have an ability to cast.
  538.             local abilityName = PQR[rotationNumber].priorityTable.ability[nextAbility]
  539.             local spellID = PQR[rotationNumber].priorityTable.spellid[nextAbility]
  540.             local spellTarget = PQR[rotationNumber].priorityTable.target[nextAbility]
  541.             local actions = PQR[rotationNumber].priorityTable.actions[nextAbility]
  542.             PQR_Event("PQR_ExecutingAbility", abilityName, spellID, rotationNumber)
  543.             PQR_CastAbility(abilityName, spellID, spellTarget, actions)
  544.         else
  545.             --Send empty ability
  546.             PQR_Event("PQR_ExecutingAbility", nil, nil, rotationNumber)
  547.         end
  548.     end
  549.  
  550.     function PQR_ExecuteInterrupt()
  551.  
  552.         --Check if we are in combat.
  553.         local inCombat = UnitAffectingCombat("player")
  554.         if inCombat == nil then
  555.             inCombat = UnitAffectingCombat("pet")
  556.         end
  557.  
  558.         --Does this rotation require combat?
  559.         local requireCombat = PQR.interruptPriorityTable.requireCombat
  560.         local playerChanneling = PQR_IsChanneling()
  561.  
  562.         for i=0,1023 do
  563.             if PQR.interruptPriorityTable.index[i] ~= nil then
  564.                 local abilityName = PQR.interruptPriorityTable.ability[i]
  565.                 local spellID = PQR.interruptPriorityTable.spellid[i]
  566.                 local spellTarget = PQR.interruptPriorityTable.target[i]
  567.                 local actions = PQR.interruptPriorityTable.actions[i]
  568.                 local skipUnknown = PQR.interruptPriorityTable.skipUnknown[i]
  569.                 if spellID == 0 then
  570.                     if (playerChanneling == PQR.interruptPriorityTable.cancelChannel[i]) or (playerChanneling == false) then
  571.                         PQR_CurrentRotationNumber = 5
  572.                         PQR_CurrentAbilityName = abilityName
  573.                         local testLua = PQR.interruptPriorityTable.lua[i]()
  574.                         PQR_CurrentAbilityName = nil
  575.                         PQR_CurrentRotationNumber = nil
  576.  
  577.                         if testLua == true then
  578.                             PQR_Event("PQR_ExecutingAbility", abilityName, spellID, 5)
  579.                             PQR_Debug("Ability "..abilityName.." returned true.")
  580.                             if actions ~= nil then
  581.                                 local tbl = { strsplit("|", actions) }
  582.                                 for i=1,100 do
  583.                                     if tbl[i] == nil then
  584.                                         break
  585.                                     end
  586.                                     if tbl[i] ~= "" then
  587.                                         PQR_Debug("Running Action "..abilityName.." ("..tbl[i]..")")
  588.                                         RunMacroText(tbl[i])
  589.                                     end
  590.                                 end
  591.                             end
  592.                         end
  593.                     end
  594.                 else
  595.                     local isSpellKnown = IsSpellKnown(spellID)
  596.                     if isSpellKnown == true or skipUnknown == false then
  597.                         if PQR_SpellAvailable(spellID) then
  598.                             --spell is available
  599.                             if PQR.interruptPriorityTable.delay[i] <= (GetTime() * 1000) then
  600.                                 --spell is not being delayed.
  601.                                 if (playerChanneling == PQR.interruptPriorityTable.cancelChannel[i]) or (playerChanneling == false) then
  602.                                     --player is not channeling or the spell allows cancel-channel
  603.                                     PQR_CurrentRotationNumber = 5
  604.                                    
  605.                                     PQR_CurrentAbilityName = abilityName
  606.                                     local testLua = PQR.interruptPriorityTable.lua[i]()
  607.                                     PQR_CurrentAbilityName = nil
  608.                                     PQR_CurrentRotationNumber = nil
  609.                                    
  610.                                     if testLua == true then
  611.                                         PQR_Debug("Ability "..abilityName.." returned true.")
  612.                                         --Ability returned true
  613.                                         if actions ~= nil then
  614.                                             --Perform any actions if necessary.
  615.                                             local tbl = { strsplit("|", actions) }
  616.                                             for i=1,100 do
  617.                                                 if tbl[i] == nil then
  618.                                                     break
  619.                                                 end
  620.                                                 if tbl[i] ~= "" then
  621.                                                     PQR_Debug("Running Action "..abilityName.." ("..tbl[i]..")")
  622.                                                     RunMacroText(tbl[i])
  623.                                                 end
  624.                                             end
  625.                                         end
  626.                                         --cast the spell.
  627.                                         PQR_CastAbility(abilityName, spellID, spellTarget, actions)
  628.                                         PQR_Event("PQR_ExecutingAbility", abilityName, spellID, 5)
  629.                                     end
  630.                                 end
  631.                             end
  632.                         end
  633.                     else
  634.                         PQR_Debug(abilityName.." is an unknown spell ID. SPELL SKIPPED.", "Advanced")
  635.                     end
  636.                 end
  637.             else
  638.                 --no more abilities in this rotation.
  639.                 break
  640.             end
  641.         end
  642.     end
  643.  
  644.     function PQR_CastAbility(abilityName, spellID, spellTarget, actions)
  645.        
  646.         if actions ~= nil and actions ~= "" then
  647.             --we have actions to send.
  648.             local tbl = { strsplit("|", actions) }
  649.             for i=1,100 do
  650.                 if tbl[i] == nil then
  651.                     break
  652.                 end
  653.                 if tbl[i] ~= "" then
  654.                     PQR_Debug("Running Action "..abilityName.." ("..tbl[i]..")")
  655.                     RunMacroText(tbl[i])
  656.                 end
  657.             end
  658.         end
  659.  
  660.         if spellID ~= 0 then
  661.             PQR_LastCastTime = GetTime()
  662.             local spellName = GetSpellInfo(spellID)
  663.             if spellTarget == "click" then
  664.                 PQR_Debug("Casting "..abilityName.." ("..spellName..") on MOUSE LOCATION")
  665.                 local friendPlates = GetCVar("nameplateShowFriends")
  666.                 local enemyPlates = GetCVar("nameplateShowEnemies")
  667.                 SetCVar("nameplateShowFriends", 0)
  668.                 SetCVar("nameplateShowEnemies", 0)
  669.                 local spellToCast = GetSpellInfo(spellID)
  670.                 CastSpellByName(spellToCast)
  671.                 --CastSpellByID(spellID)
  672.                
  673.                 local oldtargetName = UnitName("target")
  674.                 CameraOrSelectOrMoveStart()
  675.                 CameraOrSelectOrMoveStop()
  676.                 SetCVar("nameplateShowFriends", friendPlates)
  677.                 SetCVar("nameplateShowEnemies", enemyPlates)
  678.                 local newTargetName = UnitName("target")
  679.                 if oldTargetName ~= nil then
  680.                     if oldTargetName ~= newTargetName then
  681.                         TargetLastTarget()
  682.                     end
  683.                 else
  684.                     ClearTarget()
  685.                 end
  686.  
  687.             elseif spellTarget == "custom" then
  688.                 if UnitExists(PQR_CustomTarget) then
  689.                     PQR_Debug("Casting "..abilityName.." ("..spellName..") on "..UnitName(PQR_CustomTarget), "Advanced")
  690.                     PQR_LastTarget = UnitName(PQR_CustomTarget)
  691.                     local spellToCast = GetSpellInfo(spellID)
  692.                     --CastSpellByID(spellID, PQR_CustomTarget)
  693.                     CastSpellByName(spellToCast, PQR_CustomTarget)
  694.                 else
  695.                     if PQR_CustomTarget == nil then
  696.                         PQR_CustomTarget = "no_target_specified"
  697.                     end
  698.                     PQR_Debug("Custom target does not exist. ("..PQR_CustomTarget..")")
  699.                 end
  700.                 PQR_CustomTarget = ""
  701.             else
  702.                 PQR_Debug("Casting "..abilityName.." ("..spellName..") on "..spellTarget, "Advanced")
  703.                 if UnitExists(spellTarget) then
  704.                     PQR_LastTarget = UnitName(spellTarget)
  705.                 end
  706.                 local spellToCast = GetSpellInfo(spellID)
  707.                 --CastSpellByID(spellID, spellTarget)
  708.                 CastSpellByName(spellToCast, spellTarget)
  709.             end
  710.         end
  711.     end
  712.  
  713.     function PQR_NextAbility(rotationNumber)
  714.         --Find the next ability to cast in the indicated rotation.
  715.         local nextAbility = -1
  716.  
  717.         if PQR[rotationNumber] ~= nil then
  718.             --Loop through the PQR[i].priorityTable for the next ability to cast.
  719.             local playerChanneling = PQR_IsChanneling()
  720.  
  721.             --If a global pause has been set, don't do anything.
  722.             if PQR_IsRotationDelayed() then
  723.                 PQR_Debug("DELAY: Rotation is delayed. Spell or item use attemped.")
  724.             else
  725.                 for i=0,1023 do
  726.                     if PQR[rotationNumber].priorityTable.index[i] ~= nil then
  727.                         local spellID = PQR[rotationNumber].priorityTable.spellid[i]
  728.                         local skipUnknown = PQR[rotationNumber].priorityTable.skipUnknown[i]
  729.                         if spellID ~= 0 then
  730.                             --we have an ability with a spell ID attached to it, also do a PQR_SpellAvailable()
  731.                             local isSpellKnown = IsSpellKnown(spellID)
  732.                             if isSpellKnown == true or skipUnknown == false then
  733.                                 if PQR_SpellAvailable(spellID) then
  734.                                     --spell is available.
  735.                                     if PQR[rotationNumber].priorityTable.delay[i] <= (GetTime() * 1000) then
  736.                                         --spell isn't being delayed.
  737.                                         if (playerChanneling == PQR[rotationNumber].priorityTable.cancelChannel[i]) or (playerChanneling == false) then
  738.                                             --not channeling, or the spell is allowed to break channeling
  739.                                             PQR_CurrentRotationNumber = rotationNumber
  740.                                            
  741.                                             PQR_CurrentAbilityName = PQR[rotationNumber].priorityTable.ability[i]
  742.                                             local testLua = PQR[rotationNumber].priorityTable.lua[i]()
  743.                                             PQR_CurrentAbilityName = nil
  744.                                             PQR_CurrentRotationNumber = nil
  745.                                             if PQR_ChangeRotation == true then
  746.                                                 return -1
  747.                                             end
  748.                                             if testLua == true then
  749.                                                
  750.                                                 PQR_Debug(PQR[rotationNumber].priorityTable.ability[i].. " returned true. Executing ability.")
  751.                                                 return i
  752.                                             end
  753.                                         end
  754.                                     end
  755.                                 end
  756.                             else
  757.                                 PQR_Debug(PQR[rotationNumber].priorityTable.ability[i].." is an unknown spell ID. SPELL SKIPPED.", "Advanced")
  758.                             end
  759.                         else
  760.                             --0 spell ID....
  761.                             if (playerChanneling == PQR[rotationNumber].priorityTable.cancelChannel[i]) or (playerChanneling == false) then
  762.                                 PQR_CurrentRotationNumber = rotationNumber
  763.                                
  764.                                 PQR_CurrentAbilityName = PQR[rotationNumber].priorityTable.ability[i]
  765.                                 local testLua = PQR[rotationNumber].priorityTable.lua[i]()
  766.                                 PQR_CurrentAbilityName = nil
  767.                                 PQR_CurrentRotationNumber = nil
  768.                                 if PQR_ChangeRotation == true then
  769.                                     return -1
  770.                                 end
  771.                                 if testLua == true then
  772.                                     --test code returned true
  773.                                     PQR_Debug(PQR[rotationNumber].priorityTable.ability[i].. " returned true. Executing ability.")
  774.                                     return i
  775.                                 end
  776.                             end
  777.                         end
  778.                     else
  779.                         --no further abilities in this rotation
  780.                         break
  781.                     end
  782.                 end
  783.             end
  784.         end
  785.         return nextAbility
  786.     end
  787.  
  788.     function PQR_IsChanneling()
  789.         local _, _, _, _, _, playerChanneling = UnitChannelInfo("player")
  790.         local isPlayerChanneling = false
  791.  
  792.         if playerChanneling ~= nil then
  793.             local currentTime = GetTime() * 1000
  794.             if (playerChanneling - currentTime) > 100 then
  795.                 isPlayerChanneling = true
  796.             end
  797.         end
  798.  
  799.         return isPlayerChanneling
  800.     end
  801.  
  802.     function PQR_GCDSpellID()
  803.         local _, playerClass = UnitClass("player")
  804.  
  805.         if playerClass == "DEATHKNIGHT" then
  806.             return 52375
  807.         elseif playerClass == "DRUID" then
  808.             return 774
  809.         elseif playerClass == "HUNTER" then
  810.             return 56641
  811.         elseif playerClass == "MAGE" then
  812.             return 1459
  813.         elseif playerClass == "PALADIN" then
  814.             return 85256
  815.         elseif playerClass == "PRIEST" then
  816.             return 2050
  817.         elseif playerClass == "ROGUE" then
  818.             return 1752
  819.         elseif playerClass == "SHAMAN" then
  820.             return 45284
  821.         elseif playerClass == "WARLOCK" then
  822.             return 980
  823.         elseif playerClass == "WARRIOR" then
  824.             return 1715
  825.         elseif playerClass == "MONK" then
  826.             return 100780
  827.         else
  828.             return 0
  829.         end
  830.     end
  831.  
  832.     function PQR_SpellAvailable(spellID)
  833.         local gcdSpell = PQR_GCDSpellID()
  834.         local gcdStartTime, gcdDuration = GetSpellCooldown(gcdSpell)
  835.         local spellStartTime, spellDuration = GetSpellCooldown(spellID)
  836.         local spellUsable = IsUsableSpell(spellID)
  837.         local spellAvailable = false
  838.  
  839.         if spellUsable then
  840.             if spellStartTime ~= nil and gcdStartTime ~= nil then
  841.                 local spellTimeLeft = spellStartTime + spellDuration - GetTime()
  842.                 local gcdTimeLeft = gcdStartTime + gcdDuration - GetTime()
  843.                 if gcdTimeLeft <= 0 then
  844.                
  845.                     --Our GCD spell is not on CD.
  846.                     if spellTimeLeft <= PQR_SpellAvailableTime then
  847.                         --spell will be off CD within 50ms.
  848.                         spellAvailable = true
  849.                     end
  850.                 else
  851.                     --Out GCD spell is on CD.
  852.                     if spellTimeLeft <= gcdTimeLeft + PQR_SpellAvailableTime then
  853.                         --spell time left is less than GCD time left + 50ms.
  854.                         spellAvailable = true
  855.                     end
  856.                 end
  857.             end
  858.         end
  859.  
  860.         return spellAvailable
  861.     end
  862.  
  863.     function PQR_AddAllAbilities(rotationName, requireCombat, abilityName, spid, actn, testCode, recastDelay, targetCast, cancelChannel, skipUnknown)
  864.        
  865.         if PQR_Rotations[rotationName] == nil then
  866.             --setup this table
  867.             PQR_Rotations[rotationName] = {}
  868.             PQR_Rotations[rotationName].priorityTable = {}
  869.             PQR_Rotations[rotationName].priorityTable.index = {}
  870.             PQR_Rotations[rotationName].priorityTable.ability = {}
  871.             PQR_Rotations[rotationName].priorityTable.spellid = {}
  872.             PQR_Rotations[rotationName].priorityTable.target = {}
  873.             PQR_Rotations[rotationName].priorityTable.actions = {}
  874.             PQR_Rotations[rotationName].priorityTable.lua = {}
  875.             PQR_Rotations[rotationName].priorityTable.recast = {}
  876.             PQR_Rotations[rotationName].priorityTable.delay = {}
  877.             PQR_Rotations[rotationName].priorityTable.cancelChannel = {}
  878.             PQR_Rotations[rotationName].priorityTable.skipUnknown = {}
  879.             PQR_Rotations[rotationName].priorityTable.requireCombat = requireCombat
  880.             PQR_Rotations[rotationName].priorityTable.rotationName = rotationName
  881.         end
  882.        
  883.         for i=0,1023 do
  884.             if PQR_Rotations[rotationName].priorityTable.index[i] == nil then
  885.                 PQR_Debug("Added "..abilityName.." at index "..i.." in rotation "..rotationName, "Advanced")
  886.                 PQR_Rotations[rotationName].priorityTable.index[i] = i
  887.                 PQR_Rotations[rotationName].priorityTable.ability[i] = abilityName
  888.                 PQR_Rotations[rotationName].priorityTable.spellid[i] = spid
  889.                 PQR_Rotations[rotationName].priorityTable.target[i] = targetCast
  890.                 PQR_Rotations[rotationName].priorityTable.actions[i] = actn
  891.                 PQR_Rotations[rotationName].priorityTable.lua[i] = loadstring(testCode)
  892.                 PQR_Rotations[rotationName].priorityTable.recast[i] = recastDelay
  893.                 PQR_Rotations[rotationName].priorityTable.delay[i] = 0
  894.                 PQR_Rotations[rotationName].priorityTable.cancelChannel[i] = cancelChannel
  895.                 PQR_Rotations[rotationName].priorityTable.skipUnknown[i] = skipUnknown
  896.                 break
  897.             end
  898.         end
  899.     end
  900.  
  901.     function PQR_AddAbility(rotationNumber, abilityName, spid, actn, testCode, recastDelay, targetCast, cancelChannel, skipUnknown)
  902.         for i=0,1023 do
  903.             if PQR[rotationNumber].priorityTable.index[i] == nil then
  904.                 PQR_Debug("Added "..abilityName.." at index "..i.." in rotation "..rotationNumber)
  905.                 --create the function for this ability
  906.                 PQR[rotationNumber].priorityTable.index[i] = i
  907.                 PQR[rotationNumber].priorityTable.ability[i] = abilityName
  908.                 PQR[rotationNumber].priorityTable.spellid[i] = spid
  909.                 PQR[rotationNumber].priorityTable.target[i] = targetCast
  910.                 PQR[rotationNumber].priorityTable.actions[i] = actn
  911.                 PQR[rotationNumber].priorityTable.lua[i] = loadstring(testCode)
  912.                 PQR[rotationNumber].priorityTable.recast[i] = recastDelay
  913.                 PQR[rotationNumber].priorityTable.delay[i] = 0
  914.                 PQR[rotationNumber].priorityTable.cancelChannel[i] = cancelChannel
  915.                 PQR[rotationNumber].priorityTable.skipUnknown[i] = skipUnknown
  916.                 break
  917.             end
  918.         end
  919.     end
  920.  
  921.     function PQR_AddInterruptAbility(abilityName, spid, actn, testCode, recastDelay, targetCast, cancelChannel, skipUnknown)
  922.         for i=0,1023 do
  923.             if PQR.interruptPriorityTable.index[i] == nil then
  924.                 --create the function for this test.
  925.                 PQR.interruptPriorityTable.index[i] = i
  926.                 PQR.interruptPriorityTable.ability[i] = abilityName
  927.                 PQR.interruptPriorityTable.spellid[i] = spid
  928.                 PQR.interruptPriorityTable.target[i] = targetCast
  929.                 PQR.interruptPriorityTable.actions[i] = actn
  930.                 PQR.interruptPriorityTable.lua[i] = loadstring(testCode)
  931.                 PQR.interruptPriorityTable.recast[i] = recastDelay
  932.                 PQR.interruptPriorityTable.delay[i] = 0
  933.                 PQR.interruptPriorityTable.cancelChannel[i] = cancelChannel
  934.                 PQR.interruptPriorityTable.skipUnknown[i] = skipUnknown
  935.                 break
  936.             end
  937.         end
  938.     end
  939.  
  940.     function PQR_AddInterrupt(spellName)
  941.         if tonumber(spellName) ~= nil then
  942.             spellName = GetSpellInfo(spellName)
  943.         end
  944.         for i=0,1023 do
  945.             if PQR.interruptTable.spell[i] == spellName then
  946.                 PQR_Debug("Spell "..spellName.." was already on the interrupt list at position "..i)
  947.                 break
  948.             end
  949.             if PQR.interruptTable.spell[i] == nil then
  950.                 PQR_Debug("Added "..spellName.." to interrupt list at position "..i)
  951.                 PQR.interruptTable.spell[i] = spellName
  952.                 break
  953.             end
  954.         end
  955.     end
  956.  
  957.     function PQR_ResetInterruptList()
  958.         PQR.interruptTable.spell = {}
  959.     end
  960.  
  961.     function PQR_IsInterruptAll()
  962.         if PQR_InterruptAll == true then
  963.             return true
  964.         else
  965.             return false
  966.         end
  967.     end
  968.  
  969.     function PQR_IsOnInterruptList(spellName)
  970.         for i=0,1023 do
  971.             if PQR.interruptTable.spell[i] == nil then
  972.                 return false
  973.             end    
  974.             if PQR.interruptTable.spell[i] == spellName then
  975.                 return true
  976.             end
  977.         end
  978.         return false
  979.     end
  980.  
  981.     function UnitBuffID(unit, spellID, filter)
  982.         local spellName = GetSpellInfo(spellID)
  983.         if filter == nil then
  984.             return UnitBuff(unit, spellName)
  985.         else
  986.             local exactSearch = strfind(strupper(filter), "EXACT")
  987.             local playerSearch = strfind(strupper(filter), "PLAYER")
  988.  
  989.             if exactSearch then
  990.                 --using the index does not support filter.
  991.                 for i=1,40 do
  992.                     local _, _, _, _, _, _, _, buffCaster, _, _, buffSpellID = UnitBuff(unit, i)
  993.                     if buffSpellID ~= nil then
  994.                         if buffSpellID == spellID then
  995.                             if (not playerSearch) or (playerSearch and (buffCaster == "player")) then
  996.                                 return UnitBuff(unit, i)
  997.                             end
  998.                         end
  999.                     else
  1000.                         return nil
  1001.                     end
  1002.                 end
  1003.             else
  1004.                 --just pass the filter to UnitBuff and return.
  1005.                 return UnitBuff(unit, spellName, nil, filter)
  1006.             end
  1007.         end
  1008.     end
  1009.  
  1010.     function UnitDebuffID(unit, spellID, filter)
  1011.         local spellName = GetSpellInfo(spellID)
  1012.         if filter == nil then
  1013.             return UnitDebuff(unit, spellName)
  1014.         else
  1015.             local exactSearch = strfind(strupper(filter), "EXACT")
  1016.             local playerSearch = strfind(strupper(filter), "PLAYER")
  1017.  
  1018.             if exactSearch then
  1019.                 --using the index does not support filter.
  1020.                 for i=1,40 do
  1021.                     local _, _, _, _, _, _, _, buffCaster, _, _, buffSpellID = UnitDebuff(unit, i)
  1022.                     if buffSpellID ~= nil then
  1023.                         if buffSpellID == spellID then
  1024.                             if (not playerSearch) or (playerSearch and (buffCaster == "player")) then
  1025.                                 return UnitDebuff(unit, i)
  1026.                             end
  1027.                         end
  1028.                     else
  1029.                         return nil
  1030.                     end
  1031.                 end
  1032.             else
  1033.                 --just pass the filter to UnitDebuff and return.
  1034.                 return UnitDebuff(unit, spellName, nil, filter)
  1035.             end
  1036.         end
  1037.     end
  1038.  
  1039.  
  1040.     function PQR_UnitBuffID(unit, spellID, filter)
  1041.         local spellName = GetSpellInfo(spellID)
  1042.         if filter == nil then
  1043.             return UnitBuff(unit, spellName)
  1044.         else
  1045.             local exactSearch = strfind(strupper(filter), "EXACT")
  1046.             local playerSearch = strfind(strupper(filter), "PLAYER")
  1047.  
  1048.             if exactSearch then
  1049.                 --using the index does not support filter.
  1050.                 for i=1,40 do
  1051.                     local _, _, _, _, _, _, _, buffCaster, _, _, buffSpellID = UnitBuff(unit, i)
  1052.                     if buffSpellID ~= nil then
  1053.                         if buffSpellID == spellID then
  1054.                             if (not playerSearch) or (playerSearch and (buffCaster == "player")) then
  1055.                                 return UnitBuff(unit, i)
  1056.                             end
  1057.                         end
  1058.                     else
  1059.                         return nil
  1060.                     end
  1061.                 end
  1062.             else
  1063.                 --just pass the filter to UnitBuff and return.
  1064.                 return UnitBuff(unit, spellName, nil, filter)
  1065.             end
  1066.         end
  1067.     end
  1068.  
  1069.     function PQR_UnitDebuffID(unit, spellID, filter)
  1070.         local spellName = GetSpellInfo(spellID)
  1071.         if filter == nil then
  1072.             return UnitDebuff(unit, spellName)
  1073.         else
  1074.             local exactSearch = strfind(strupper(filter), "EXACT")
  1075.             local playerSearch = strfind(strupper(filter), "PLAYER")
  1076.  
  1077.             if exactSearch then
  1078.                 --using the index does not support filter.
  1079.                 for i=1,40 do
  1080.                     local _, _, _, _, _, _, _, buffCaster, _, _, buffSpellID = UnitDebuff(unit, i)
  1081.                     if buffSpellID ~= nil then
  1082.                         if buffSpellID == spellID then
  1083.                             if (not playerSearch) or (playerSearch and (buffCaster == "player")) then
  1084.                                 return UnitDebuff(unit, i)
  1085.                             end
  1086.                         end
  1087.                     else
  1088.                         return nil
  1089.                     end
  1090.                 end
  1091.             else
  1092.                 --just pass the filter to UnitDebuff and return.
  1093.                 return UnitDebuff(unit, spellName, nil, filter)
  1094.             end
  1095.         end
  1096.     end
  1097.  
  1098.     function PQR_ResetRecastDelay(spellID)
  1099.        
  1100.         if spellID == nil or spellID == 0 then
  1101.             return
  1102.         end
  1103.         local spellName = GetSpellInfo(spellID)
  1104.         PQR_Debug("ResetRecastDelay called for spell "..spellName, "Advanced")
  1105.         if PQR_InterruptEnabled then
  1106.             --interrupt enabled
  1107.             for i=0,1023 do
  1108.                 if PQR.interruptPriorityTable.index[i] == nil then
  1109.                     break
  1110.                 end
  1111.  
  1112.                 if PQR.interruptPriorityTable.spellid[i] == spellID then
  1113.                     PQR.interruptPriorityTable.delay[i] = 0
  1114.                 end
  1115.             end
  1116.         end
  1117.  
  1118.         if PQR_RotationEnabled then
  1119.             --auto mode
  1120.             for y=0,4 do
  1121.                 for i=0,1023 do
  1122.                     if PQR[y].priorityTable.index[i] == nil then
  1123.                         break
  1124.                     end
  1125.  
  1126.                     if PQR[y].priorityTable.spellid[i] == spellID then
  1127.                         PQR[y].priorityTable.delay[i] = 0
  1128.                     end
  1129.                 end
  1130.             end
  1131.         else
  1132.             --manual mode
  1133.             for y=1,4 do
  1134.                 for i=0,1023 do
  1135.                     if PQR[y].priorityTable.index[i] == nil then
  1136.                         break
  1137.                     end
  1138.  
  1139.                     if PQR[y].priorityTable.spellid[i] == spellID then
  1140.                         PQR[y].priorityTable.delay[i] = 0
  1141.                     end
  1142.                 end
  1143.             end
  1144.         end
  1145.     end
  1146.  
  1147.     function PQR_SetRecastDelay(spellID, addCastTime)
  1148.         if spellID == nil or spellID == 0 then
  1149.             return
  1150.         end
  1151.         local castingSpellName,_, _, _, _, _, castTime = GetSpellInfo(spellID)
  1152.         if castingSpellName == nil then
  1153.             return
  1154.         end
  1155.  
  1156.         PQR_Debug("SetRecastDelay called for "..castingSpellName, "Advanced")
  1157.  
  1158.         --Add delays to interrupt mode if necessary.
  1159.         if PQR_InterruptEnabled then
  1160.             for i=0,1023 do
  1161.                 if PQR.interruptPriorityTable.index[i] == nil then
  1162.                     break
  1163.                 end
  1164.            
  1165.                 if PQR.interruptPriorityTable.spellid[i] == spellID and PQR.interruptPriorityTable.recast[i] ~= 0 then
  1166.                     --set a delay
  1167.                     if addCastTime then
  1168.                         PQR.interruptPriorityTable.delay[i] = (GetTime() * 1000) + PQR.interruptPriorityTable.recast[i] + castTime
  1169.                     else
  1170.                         PQR.interruptPriorityTable.delay[i] = (GetTime() * 1000) + PQR.interruptPriorityTable.recast[i]
  1171.                     end
  1172.                 end
  1173.             end
  1174.         end
  1175.  
  1176.         if PQR_RotationEnabled then
  1177.             for y=0,4 do
  1178.                 for i=0,1023 do
  1179.                     if PQR[y].priorityTable.index[i] == nil then
  1180.                         break
  1181.                     end
  1182.  
  1183.                     if PQR[y].priorityTable.spellid[i] == spellID and PQR[y].priorityTable.recast[i] ~= 0 then
  1184.                         if addCastTime then
  1185.                             PQR[y].priorityTable.delay[i] = (GetTime() * 1000) + PQR[y].priorityTable.recast[i] + castTime
  1186.                         else
  1187.                             PQR[y].priorityTable.delay[i] = (GetTime() * 1000) + PQR[y].priorityTable.recast[i]
  1188.                         end
  1189.                        
  1190.                     end
  1191.                 end
  1192.             end
  1193.         else
  1194.             if PQR_ManualLoaded then
  1195.                 for y=1,4 do
  1196.                     for i=0,1023 do
  1197.                         if PQR[y].priorityTable.index[i] == nil then
  1198.                             break
  1199.                         end
  1200.  
  1201.                         if PQR[y].priorityTable.spellid[i] == spellID and PQR[y].priorityTable.recast[i] ~= 0 then
  1202.                             if addCastTime then
  1203.                                 PQR[y].priorityTable.delay[i] = (GetTime() * 1000) + PQR[y].priorityTable.recast[i] + castTime
  1204.                             else
  1205.                                 PQR[y].priorityTable.delay[i] = (GetTime() * 1000) + PQR[y].priorityTable.recast[i]
  1206.                             end
  1207.                         end
  1208.                     end
  1209.                 end
  1210.             end
  1211.         end
  1212.     end
  1213.  
  1214.     function PQR_Cast(rotationNumber)
  1215.  
  1216.         local cvarValue = GetCVar("PQR")
  1217.         if cvarValue == nil then
  1218.             cvarValue = 0
  1219.             RegisterCVar("PQR", cvarValue)
  1220.         end
  1221.  
  1222.         if rotationNumber >= 1 or rotationNumber <= 4 then
  1223.             cvarValue = rotationNumber
  1224.         end
  1225.  
  1226.         SetCVar("PQR", cvarValue)
  1227.     end
  1228.  
  1229.     function PQR_CastManual()
  1230.         local cvarValue = GetCVar("PQR")
  1231.         if cvarValue == nil then
  1232.             cvarValue = 0
  1233.             RegisterCVar("PQR", cvarValue)
  1234.         end
  1235.         SetCVar("PQR", 0)
  1236.         return cvarValue
  1237.     end
  1238.  
  1239.     function PQR_RegisterMovement(elapsed)
  1240.         local playerMovementSpeed = GetUnitSpeed("player")
  1241.  
  1242.         if playerMovementSpeed ~= 0 then
  1243.             PQR_CurrentMovingTime = PQR_CurrentMovingTime + elapsed
  1244.             PQR_CurrentStationaryTime = 0
  1245.         else
  1246.             if PQR_CurrentStationaryTime < PQR_ResetMovementTime then
  1247.                 PQR_CurrentStationaryTime = PQR_CurrentStationaryTime + elapsed
  1248.             end
  1249.             if PQR_CurrentStationaryTime > PQR_ResetMovementTime then
  1250.                 PQR_CurrentMovingTime = 0
  1251.             end
  1252.         end
  1253.     end
  1254.  
  1255.     function PQR_IsMoving(seconds)
  1256.         if seconds == nil then
  1257.             seconds = 1
  1258.         end
  1259.  
  1260.         local moltenFeathers = PQR_UnitBuffID("player", 98767)
  1261.        
  1262.         if PQR_CurrentMovingTime >= seconds and moltenFeathers == nil then
  1263.             return true
  1264.         else
  1265.             return false
  1266.         end
  1267.     end
  1268.  
  1269.     function PQR_IsCastingSpell(spellID)
  1270.         local spellName = GetSpellInfo(spellID)
  1271.         local spellCasting = UnitCastingInfo("player")
  1272.  
  1273.         if spellCasting == nil then
  1274.             spellCasting = UnitChannelInfo("player")
  1275.         end
  1276.         if spellCasting == spellName then
  1277.             return true
  1278.         else
  1279.             return false
  1280.         end
  1281.     end
  1282.  
  1283.  
  1284.     function PQR_NotBehindTarget(seconds)
  1285.         if seconds == nil then
  1286.             seconds = 1
  1287.         end
  1288.  
  1289.         if PQR_BehindTime + seconds > GetTime() then
  1290.             return true
  1291.         else
  1292.             return false
  1293.         end
  1294.     end
  1295.  
  1296.     function PQR_DelayRotation(seconds)
  1297.         if seconds == nil then
  1298.             seconds = 1
  1299.         end
  1300.  
  1301.         local newDelay = GetTime() + seconds
  1302.  
  1303.         PQR.delayTable.spell["custom"] = "custom"
  1304.         PQR.delayTable.item["custom"] = nil
  1305.         PQR.delayTable.delay["custom"] = seconds
  1306.         PQR.delayTable.delayTime["custom"] = newDelay
  1307.  
  1308.     end
  1309.  
  1310.     function PQR_AddToSpellDelayList(spell, item, seconds)
  1311.         if tonumber(spell) ~= nil then
  1312.             --spell ID
  1313.             spell = GetSpellInfo(spell)
  1314.         end
  1315.         if seconds == nil then
  1316.             seconds = 1
  1317.         end
  1318.  
  1319.         PQR.delayTable.spell[spell] = spell
  1320.         PQR.delayTable.item[spell] = item
  1321.         PQR.delayTable.delay[spell] = seconds
  1322.         PQR.delayTable.delayTime[spell] = 0
  1323.     end
  1324.  
  1325.     function PQR_IsRotationDelayed()
  1326.         --returns true if the rotation is delayed, false otherwise.
  1327.         for k,v in pairs(PQR.delayTable.delayTime) do
  1328.             if v > GetTime() then
  1329.                 return true
  1330.             end
  1331.         end
  1332.         return false
  1333.     end
  1334.  
  1335.     function PQR_IsOutOfSight(unit, seconds)
  1336.         if UnitExists(unit) then
  1337.             unit = UnitName(unit)
  1338.         else
  1339.             return false
  1340.         end
  1341.  
  1342.         local iceTombPlayer = UnitDebuffID("player", 104451)
  1343.         local iceTombUnit = UnitDebuffID(unit, 104451)
  1344.  
  1345.         if iceTombPlayer or iceTombUnit then
  1346.             return true
  1347.         end
  1348.  
  1349.         if seconds == nil then
  1350.             seconds = 3
  1351.         end
  1352.  
  1353.         for k,v in pairs(PQR.losTable.name) do
  1354.             if v == unit then
  1355.                 if PQR.losTable.time[v] > GetTime() - seconds then
  1356.                     return true
  1357.                 end
  1358.             end
  1359.         end
  1360.         return false
  1361.     end
  1362.  
  1363.     function PQR_Event(eventName, ...)
  1364.         if PQR_EventsEnabled ~= true then
  1365.             return
  1366.         end
  1367.         if eventName == nil then
  1368.             eventName = ""
  1369.         end
  1370.         eventName = strtrim(eventName)
  1371.         local cVarValue = GetCVar("PQREvent")
  1372.         if cVarValue == nil then
  1373.             RegisterCVar("PQREvent", "")
  1374.             cVarValue = ""
  1375.         end
  1376.         local tblArgs = { ... }
  1377.         local addCall = "if "..eventName.." then "..eventName.."("
  1378.  
  1379.         for i = 1,5 do
  1380.             local varArg = tblArgs[i]
  1381.             if i ~= 1 then
  1382.                 addCall = addCall..", "
  1383.             end
  1384.  
  1385.             if varArg == nil then
  1386.                 addCall = addCall.."nil"
  1387.             elseif tonumber(varArg) ~= nil then
  1388.                 addCall = addCall..varArg
  1389.             elseif tostring(varArg) ~= nil then
  1390.                 addCall = addCall.."\""..varArg.."\""
  1391.             else
  1392.                 addCall = addCall.."nil"
  1393.             end
  1394.         end
  1395.  
  1396.         addCall = addCall..") end"
  1397.        
  1398.  
  1399.         if cVarValue == "" then
  1400.             cVarValue = addCall
  1401.         else
  1402.             cVarValue = cVarValue.."|"..addCall
  1403.         end
  1404.         SetCVar("PQREvent", cVarValue)
  1405.  
  1406.     end
  1407.  
  1408.     function PQR_SendEvents()
  1409.         local cVarValue = GetCVar("PQREvent")
  1410.         if cVarValue ~= nil and cVarValue ~= "" then
  1411.             local tblEvents = { strsplit("|", cVarValue) }
  1412.             for k,v in pairs(tblEvents) do
  1413.                 loadstring(v)()
  1414.             end
  1415.             SetCVar("PQREvent", "")
  1416.         end
  1417.     end
  1418.  
  1419.     function PQR_EnableEvents()
  1420.         local eventsEnabled = GetCVar("PQREventsEnabled")
  1421.         if eventsEnabled == "1" then
  1422.             eventsEnabled = true
  1423.         end
  1424.         if eventsEnabled == true then
  1425.             PQR_EventSend:Show()
  1426.             PQR_EventsEnabled = true
  1427.         else
  1428.             PQR_EventSend:Hide()
  1429.             PQR_EventsEnabled = false
  1430.         end
  1431.     end
  1432.    
  1433.     function PQR_CastSpellByID(...)
  1434.         if PQR_CurrentAbilityName ~= nil then
  1435.             local spellID = select(1, ...)
  1436.             PQR_Event("PQR_ExecutingAbility", PQR_CurrentAbilityName, spellID, PQR_CurrentRotationNumber)
  1437.         end
  1438.     end
  1439.  
  1440.     function PQR_CastSpellByName(...)
  1441.         if PQR_CurrentAbilityName ~= nil then
  1442.             local spellID = PQR_GetSpellID(select(1, ...))
  1443.             if spellID ~= nil and spellID ~= 0 then
  1444.                 PQR_Event("PQR_ExecutingAbility", PQR_CurrentAbilityName, spellID, PQR_CurrentRotationNumber)
  1445.             end
  1446.         end
  1447.     end
  1448.  
  1449.     function PQR_GetSpellID(spellName, target)
  1450.         local spellID = 0;
  1451.         local i = 1
  1452.         if target == nil then
  1453.             target = "player"
  1454.         end
  1455.         while true do
  1456.             local sbSpellName, sbSpellSubName = GetSpellBookItemName(i, BOOKTYPE_SPELL)
  1457.             if sbSpellName == nil then
  1458.                 break
  1459.             end
  1460.             if sbSpellSubName == nil then
  1461.                 sbSpellSubName = ""
  1462.             end
  1463.             if spellName == sbSpellName or spellName == sbSpellName..sbSpellSubName or spellName == sbSpellName.." "..sbSpellSubName then
  1464.                 _, spellID = GetSpellBookItemInfo(i, target)
  1465.                 break
  1466.             end
  1467.    
  1468.             i = i + 1
  1469.         end
  1470.         return spellID
  1471.     end
  1472.  
  1473.     --create our CVars
  1474.     --Do not change values of CVars, their length is necessary because writing to WoW will cause
  1475.     --us to overwrite the end of the variable and start writing into the address space of other variables.
  1476.     --We define a big chunck so we have room to work with.
  1477.     local cVarTest = GetCVar("PQRCvarsLoaded")
  1478.     if cVarTest == nil then
  1479.         RegisterCVar("PQRCvarsLoaded", "true")
  1480.  
  1481.         local sETX = strchar(33)
  1482.         local cVarPlaceholderValue = "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          "..sETX
  1483.  
  1484.         local PQRCVars = { "BehindTarget", "FacingTarget", "DistanceTarget", "PQR_TargetX", "PQR_TargetY", "PQR_TargetZ"}
  1485.  
  1486.         for _,v in ipairs(PQRCVars) do RegisterCVar(v, sETX..cVarPlaceholderValue..v) end
  1487.  
  1488.         local value = "            " for i=1,20 do value=value..value end
  1489.  
  1490.         local objMgrValue = sETX..value
  1491.         RegisterCVar("PQR_ObjectManager", objMgrValue)
  1492.        
  1493.         RegisterCVar("PQR_TargetClick", "0")
  1494.  
  1495.     end
  1496.  
  1497.     function PQR_DistanceTarget()
  1498.         local distance = PQR_GetCVar("DistanceTarget")
  1499.         if distance == nil or distance == "" then
  1500.             return 0
  1501.         else
  1502.             return tonumber(distance)
  1503.         end
  1504.     end
  1505.  
  1506.     function PQR_PulseObjectManager(overrideTime)
  1507.         local timeOverride = tonumber(overrideTime)
  1508.         if timeOverride == nil then
  1509.             timeOverride = PQR_ObjMgrPulseTimer
  1510.         end
  1511.  
  1512.         if PQR_LastObjectManagerPulse < GetTime() - timeOverride then
  1513.             PQR_LastObjectManagerPulse = GetTime()
  1514.             local objMgr = PQR_GetCVar("PQR_ObjectManager")
  1515.             if objMgr == nil or objMgr == "" then
  1516.                 return nil
  1517.             else
  1518.                 loadstring(objMgr)()
  1519.             end
  1520.         end
  1521.     end
  1522.  
  1523.     function PQR_GUIDInfo(GUID)
  1524.         if PQR_LastObjectManagerPulse < GetTime() - PQR_ObjMgrPulseTimer then
  1525.             PQR_LastObjectManagerPulse = GetTime()
  1526.             local objMgr = PQR_GetCVar("PQR_ObjectManager")
  1527.             if objMgr == nil or objMgr == "" then
  1528.                 return nil
  1529.             else
  1530.                 loadstring(objMgr)()
  1531.             end
  1532.         end
  1533.         if pom ~= nil then
  1534.             if pom[GUID] == nil then
  1535.                 return nil
  1536.             else
  1537.                 return pom[GUID][1], pom[GUID][2], pom[GUID][3], pom[GUID][4], pom[GUID][5], pom[GUID][6]
  1538.             end
  1539.         end
  1540.         return nil
  1541.     end
  1542.  
  1543.     function PQR_UnitInfo(unit)
  1544.         if UnitExists(unit) then
  1545.             return PQR_GUIDInfo(UnitGUID(unit))
  1546.         else
  1547.             return PQR_GUIDInfo(unit)
  1548.         end
  1549.     end
  1550.  
  1551.     function atan2custom(Y,X)
  1552.         local pi = 3.14159265358979
  1553.         local product = 0
  1554.  
  1555.         if tonumber(Y) == nil or tonumber(X) == nil then
  1556.             return 0
  1557.         end
  1558.  
  1559.         if X == 0 and Y == 0 then
  1560.             return 0
  1561.         end
  1562.  
  1563.         if X == 0 then
  1564.             product = pi / 2
  1565.             if Y < 0 then
  1566.                 product = product * 3
  1567.             end
  1568.         else
  1569.             product = atancustom(Y / X)
  1570.             if X < 0 then
  1571.                 product = product + pi
  1572.             end
  1573.         end
  1574.         return product
  1575.     end
  1576.  
  1577.     function atancustom(r)
  1578.         return r/(1+(r*r/(3+(4*r*r)/(5+(9*r*r)/(7+(16*r*r)/(9+(25*r*r)/(11+(36*r*r)/(13+(49*r*r)/(15+(64*r*r)/(17+(81*r*r)))))))))))
  1579.     end
  1580.  
  1581.     PQRUNIT = 3
  1582.     PQRPLAYER = 4
  1583.     function PQR_UnitFacing(unitCheck, unitTarget, degrees)
  1584.         local degreeCheck = tonumber(degrees)
  1585.         local checkX,checkY,_,_, unitCheckType, unitCheckTarget = PQR_UnitInfo(unitCheck)
  1586.         local targetX,targetY,_,_, unitTargetType, unitTargetTarget = PQR_UnitInfo(unitTarget)
  1587.         local pi = 3.14159265358979
  1588.  
  1589.  
  1590.  
  1591.         if unitCheckType == PQRUNIT and (unitTargetType == PQRPLAYER or unitTargetType == PQRUNIT) then
  1592.             local playerGUID = UnitGUID("player")
  1593.             local facingTarget =  PQR_CalculateYaw(unitCheck, unitTarget)
  1594.             if unitCheckTarget == UnitGUID("player") and (unitTarget == "player" or unitTarget == playerGUID) then
  1595.                 --the thing we are checking is targetting the player, which we are comparing to...
  1596.                 facingTarget = 0
  1597.             else
  1598.                 --we need to correct the angle
  1599.                 --we need to get the angle of the CHECK to the TARGET OF CHECK
  1600.                 local tocX, tocY = PQR_UnitInfo(unitCheckTarget)
  1601.                 if tocX ~= nil then
  1602.                     --we have a target of check.
  1603.                     --we need to get the angle between the 2.
  1604.                     --local angle = atan2((tocY - checkY),(tocX - checkX))
  1605.                     local angle = atan2((checkY - tocY),(checkX - tocX))
  1606.                     angle = angle + 180
  1607.                     --convert degrees to radians
  1608.                     angle = angle * 0.0174532925
  1609.                    
  1610.                     --fix the rotation of the check unit.
  1611.                     if UnitExists(unitCheck) then
  1612.                         --unit exists by ref.
  1613.                         pom[UnitGUID(unitCheck)][4] = angle
  1614.                     else
  1615.                         --a GUID was used.
  1616.                         pom[unitCheck][4] = angle
  1617.                     end
  1618.  
  1619.                     facingTarget =  PQR_CalculateYaw(unitCheck, unitTarget)
  1620.                 end
  1621.             end
  1622.            
  1623.             if facingTarget == nil then
  1624.                 facingTarget = 180
  1625.             end
  1626.  
  1627.             if degrees == true then
  1628.                 return facingTarget
  1629.             elseif degreeCheck ~= nil then
  1630.                 --custom number check
  1631.                 if degreeCheck > 360 then
  1632.                     degreeCheck = 360
  1633.                 elseif degreeCheck < 0 then
  1634.                     degreeCheck = 0
  1635.                 end
  1636.             else
  1637.                 degreeCheck = 180
  1638.             end
  1639.             local facingNumber = tonumber(facingTarget)
  1640.             if facingNumber < degreeCheck / 2 or facingNumber > 360 - (degreeCheck / 2) then
  1641.                 return true
  1642.             else
  1643.                 return false
  1644.             end
  1645.         else
  1646.             local facingTarget = PQR_CalculateYaw(unitCheck, unitTarget)
  1647.             if facingTarget == nil then
  1648.                 facingTarget = 180
  1649.             end
  1650.             if degrees == true then
  1651.                 return facingTarget
  1652.             elseif degreeCheck ~= nil then
  1653.                 --custom number check
  1654.                 if degreeCheck > 360 then
  1655.                     degreeCheck = 360
  1656.                 elseif degreeCheck < 0 then
  1657.                     degreeCheck = 0
  1658.                 end
  1659.             else
  1660.                 degreeCheck = 180
  1661.             end
  1662.             local facingNumber = tonumber(facingTarget)
  1663.             if facingNumber < degreeCheck / 2 or facingNumber > 360 - (degreeCheck / 2) then
  1664.                 return true
  1665.             else
  1666.                 return false
  1667.             end
  1668.         end
  1669.  
  1670.         return false
  1671.     end
  1672.  
  1673.     function PQR_CalculateYaw(unit1, unit2)
  1674.         local unit1X, unit1Y, unit1Z, unit1R = PQR_UnitInfo(unit1)
  1675.         local unit2X, unit2Y, unit2Z, unit2R = PQR_UnitInfo(unit2)
  1676.  
  1677.         if unit1X == nil or unit2X == nil then
  1678.             return nil
  1679.         else
  1680.             local pi = 3.14159265358979
  1681.             local yaw = (180 / pi) * (atan2custom((unit2Y - unit1Y), (unit2X - unit1X)));
  1682.            
  1683.             local rotation = unit1R * (180 / pi)
  1684.             if yaw < 0 then
  1685.                 yaw = yaw + 360;
  1686.             end
  1687.             yaw = yaw - rotation
  1688.             if yaw < 0 then
  1689.                 yaw = yaw + 360
  1690.             end
  1691.             if yaw >= 360 then
  1692.                 yaw = 0
  1693.             end
  1694.             return yaw
  1695.         end
  1696.     end
  1697.  
  1698.     function PQR_UnitDistance(unit1, unit2)
  1699.         local unit1X, unit1Y, unit1Z = PQR_UnitInfo(unit1)
  1700.         local unit2X, unit2Y, unit2Z = PQR_UnitInfo(unit2)
  1701.  
  1702.         if unit1X == nil or unit2X == nil then
  1703.             return nil
  1704.         else
  1705.             return sqrt((unit1X - unit2X) * (unit1X - unit2X) + (unit1Y - unit2Y) * (unit1Y - unit2Y) + (unit1Z - unit2Z) * (unit1Z - unit2Z))
  1706.         end
  1707.     end
  1708.  
  1709.     function PQR_CheckUIError(msg, seconds)
  1710.         local errorTime = PQR_LastUIError[msg]
  1711.  
  1712.         if seconds == nil then
  1713.             seconds = 1
  1714.         end
  1715.  
  1716.         if errorTime and GetTime() < errorTime + seconds then
  1717.             return true
  1718.         end
  1719.  
  1720.         return false
  1721.     end
  1722.  
  1723.     function PQR_TargetArea(unit)
  1724.         local uX, uY, uZ = PQR_UnitInfo(unit)
  1725.         if uX ~= nil and uX ~= 0 then
  1726.             SetCVar("PQR_TargetX", uX)
  1727.             SetCVar("PQR_TargetY", uY)
  1728.             SetCVar("PQR_TargetZ", uZ)
  1729.             SetCVar("PQR_TargetClick", "1")
  1730.         end
  1731.     end
  1732.  
  1733.     function PQR_GetCVar(cVarName)
  1734.         if cVarName == nil then
  1735.             return nil
  1736.         end
  1737.         local cVarValue = GetCVar(cVarName)
  1738.         local sETX = strchar(33)
  1739.        
  1740.         if cVarValue == nil then
  1741.             return nil
  1742.         end
  1743.  
  1744.         local sETX = strchar(33)
  1745.         local findETX = strfind(cVarValue, sETX)
  1746.         if findETX == nil then
  1747.             return nil
  1748.         end
  1749.        
  1750.         findETX = tonumber(findETX)
  1751.  
  1752.         if findETX == 1 then
  1753.             return ""
  1754.         else
  1755.             cVarValue = strsub(cVarValue, 1, findETX - 1)
  1756.         end
  1757.  
  1758.         local cVarNumber = tonumber(cVarValue)
  1759.         if cVarNumber == nil then
  1760.             --string
  1761.             return cVarValue
  1762.         else
  1763.             return cVarNumber
  1764.         end
  1765.  
  1766.     end
  1767.  
  1768.     function PQR_SetCVar(cVarName, cVarValue)
  1769.         if cVarName == nil then
  1770.             return
  1771.         end
  1772.         local cVarValueTest = GetCVar(cVarName)
  1773.         if cVarValueTest == nil then
  1774.             return
  1775.         end
  1776.         local sETX = strchar(33)
  1777.  
  1778.         SetCVar(cVarName, cVarValue..sETX)
  1779.     end
  1780.    
  1781.     --Setup our global variables and activate our event frame.
  1782.     if PQR_EventFrame == nil then
  1783.         --Setup our data table.
  1784.         PQR = {}
  1785.         for i=0,4 do
  1786.             PQR[i] = {}
  1787.         end
  1788.  
  1789.         PQR_RotationTable = {}
  1790.         PQR_SetupTables()
  1791.         PQR_SetupInterruptTable()
  1792.  
  1793.         --General global variables.
  1794.         PQR_ShowChat = true
  1795.         PQR_RequireCombat = true
  1796.         PQR_CustomTarget = ""
  1797.  
  1798.         hooksecurefunc("CastSpellByID", PQR_CastSpellByID)
  1799.         hooksecurefunc("CastSpellByName", PQR_CastSpellByName)
  1800.         PQR_CurrentRotationNumber = nil
  1801.         PQR_CurrentAbilityName = nil
  1802.  
  1803.         PQR_LuaLoadedTable = {}
  1804.         PQR_Rotation1 = ""
  1805.         PQR_Rotation2 = ""
  1806.         PQR_Rotation3 = ""
  1807.         PQR_Rotation4 = ""
  1808.         PQR_InterruptSelected = ""
  1809.         PQR_EventsEnabled = true
  1810.         PQR_LegacyMode = false
  1811.  
  1812.         PQR_LastObjectManagerPulse = 0
  1813.         PQR_RotationEnabled = false
  1814.         PQR_InterruptEnabled = false
  1815.         PQR_ChangeInterrupt = false
  1816.         PQR_InterruptName = ""
  1817.         PQR_RunningInterruptName = ""
  1818.         PQR_InterruptStarted = false
  1819.         PQR_RotationStarted = false
  1820.         PQR_RotationName = ""
  1821.         PQR_RunningRotationName = ""
  1822.         PQR_ChangeRotation = false
  1823.         PQR_ManualLoaded = false
  1824.         PQR_BehindTime = 0
  1825.         PQR_InterruptAll = false
  1826.         PQR_MonkGCD = 0
  1827.         PQR_LastTarget = ""
  1828.         PQR_LastCastTime = 0
  1829.         PQR_SpellAvailableTime = 0.125
  1830.         PQR_AverageTable = {}
  1831.         PQR_soundStartRotation = ""
  1832.         PQR_soundChangeRotation = ""
  1833.         PQR_soundStopRotation = ""
  1834.         PQR_soundStartInterrupt = ""
  1835.         PQR_soundStopInterrupt = ""
  1836.         PQR_ObjMgrPulseTimer = 0.2
  1837.         PQR_LastUIError = { }
  1838.  
  1839.         --Movement tracking
  1840.         PQR_CurrentStationaryTime = 0
  1841.         PQR_CurrentMovingTime = 0
  1842.         PQR_ResetMovementTime = 0.5
  1843.  
  1844.         PQR_Rotation = -1
  1845.         PQR_totalElapsed1 = 0.0
  1846.         PQR_totalElapsed2 = 0.0
  1847.         PQR_UpdateInterval1 = 0.05
  1848.         PQR_UpdateInterval2 = 0.05
  1849.         PQR_EventSendElapsed = 0.0
  1850.         PQR_BaseRotation = nil
  1851.  
  1852.         PQR_DebugLevel = "Disabled"
  1853.         PQR_LastSpellcast = 0
  1854.         PQR_LastCastCount = 0
  1855.         PQR_SwappedRotation = false
  1856.  
  1857.         PQR_EventFrame = CreateFrame("Frame")
  1858.         PQR_EventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
  1859.         PQR_EventFrame:RegisterEvent("PLAYER_LOGOUT")
  1860.         PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  1861.         PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_START")
  1862.         PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_SENT")
  1863.         PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
  1864.         PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_FAILED")
  1865.         PQR_EventFrame:RegisterEvent("UNIT_SPELLCAST_FAILED_QUIET")
  1866.         PQR_EventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  1867.         PQR_EventFrame:RegisterEvent("UI_ERROR_MESSAGE")
  1868.         PQR_EventFrame:SetScript("OnUpdate", PQR_EventFrame_OnUpdate)
  1869.         PQR_EventFrame:SetScript("OnEvent", PQR_EventFrame_OnEvent)
  1870.         PQR_EventFrame:Show()
  1871.  
  1872.         local cVarValue = GetCVar("PQREvent")
  1873.         if cVarValue ~= nil then
  1874.             SetCVar("PQREvent", "")
  1875.         end
  1876.         PQR_EventSend = CreateFrame("Frame")
  1877.         PQR_EventSend:SetScript("OnUpdate", PQR_EventSend_OnUpdate)
  1878.         PQR_EventSend:Show()
  1879.  
  1880.         PQR_Loaded = true
  1881.         PQR_Event("PQR_BotLoaded")
  1882.  
  1883.         PQR_LoadLua("PQR_PQI.lua")
  1884.  
  1885.         local cVarValue = GetCVar("PQR_TargetsAroundTarget")
  1886.         if cVarValue ~= nil then
  1887.             SetCVar("PQR_TargetsAroundTarget", "PQR_000_VALUE")
  1888.         else
  1889.             RegisterCVar("PQR_TargetsAroundTarget", "PQR_000_VALUE")
  1890.         end
  1891.  
  1892.     end
  1893. end
  1894.  
  1895. --DO NOT CHANGE, This is for firing the PQR_BotLoaded event for PQInterface
  1896. if PQR_Loaded == false then
  1897.     PQR_Loaded = true
  1898.     local cVarValue = GetCVar("PQREvent")
  1899.     if cVarValue ~= nil then
  1900.         SetCVar("PQREvent", "")
  1901.     end
  1902.     PQR_Event("PQR_BotLoaded")
  1903. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement