forked from vortigern11/RightClick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRightClick.lua
47 lines (36 loc) · 1.24 KB
/
RightClick.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
local _, _, _, client = GetBuildInfo()
client = client or 11200
local GetTime = GetTime
local MouselookStop = MouselookStop
local UnitCanAttack = UnitCanAttack
local UnitExists = UnitExists
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
local mouseInfo = CreateFrame("Frame")
mouseInfo:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
mouseInfo.time = 0
mouseInfo.isAliveEnemy = false
mouseInfo:SetScript("OnEvent", function(self, e)
local this = self or this
local event = e or event
if event == "UPDATE_MOUSEOVER_UNIT" then
this.time = GetTime()
this.isAliveEnemy = not UnitIsDeadOrGhost("mouseover")
and UnitCanAttack("player", "mouseover")
end
end)
local OnMouseUp = function(self, button)
local arg1 = button or arg1
if arg1 == "RightButton" then
if (GetTime() - mouseInfo.time) > 5 then return end
local targetIsAliveEnemy = UnitExists("target")
and not UnitIsDeadOrGhost("target") and UnitCanAttack("player", "target")
local shouldPrevent = mouseInfo.isAliveEnemy or targetIsAliveEnemy
if shouldPrevent then MouselookStop() end
end
end
-- HookScript does not exist before TBC
if client >= 20000 then
WorldFrame:HookScript("OnMouseUp", OnMouseUp)
else
WorldFrame:SetScript("OnMouseUp", OnMouseUp)
end