-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTurtleCount.lua
More file actions
152 lines (131 loc) · 4.69 KB
/
Copy pathTurtleCount.lua
File metadata and controls
152 lines (131 loc) · 4.69 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
local turtle = (TargetHPText or TargetHPPercText)
if not turtle then
DEFAULT_CHAT_FRAME:AddMessage("|cff00ff98Turtle|cffe6b300Count|r: This addon will only function correctly for Turtle WoW.")
return
end
local TurtleCount = CreateFrame("Button", "TurtleCount", Minimap)
TurtleCount:Hide()
TurtleCount:SetFrameLevel(64)
TurtleCount:SetFrameStrata("MEDIUM")
TurtleCount:SetWidth(63)
TurtleCount:SetHeight(23)
TurtleCount:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 8, edgeSize = 16,
insets = { left = 3, right = 3, top = 3, bottom = 3 }
})
TurtleCount:SetBackdropBorderColor(.9,.8,.5,1)
TurtleCount:SetBackdropColor(.4,.4,.4,1)
TurtleCount:SetMovable(true)
TurtleCount:SetClampedToScreen(true)
TurtleCount:SetUserPlaced(true)
TurtleCount:EnableMouse(true)
TurtleCount:RegisterForDrag("LeftButton")
TurtleCount:SetScript("OnDragStart", function()
if (IsShiftKeyDown() and IsControlKeyDown()) then
this:StartMoving()
end
end)
TurtleCount:SetScript("OnDragStop", function() this:StopMovingOrSizing() end)
TurtleCount:RegisterForClicks("RightButtonDown")
TurtleCount:SetScript("OnClick", function()
if (IsShiftKeyDown() and IsControlKeyDown()) then
this:SetUserPlaced(false)
TurtleCount:Position()
end
end)
function TurtleCount:Position()
TurtleCount:ClearAllPoints()
TurtleCount:SetPoint("TOP", Minimap, "BOTTOM", 0, -12)
end
TurtleCount.text = TurtleCount:CreateFontString("Status", "LOW", "GameFontNormal")
TurtleCount.text:SetFont(STANDARD_TEXT_FONT, 12, "OUTLINE")
TurtleCount.text:SetPoint("RIGHT", TurtleCount, "RIGHT", -5, 1)
TurtleCount.text:SetFontObject(GameFontWhite)
TurtleCount.icon = TurtleCount:CreateTexture(nil, 'ARTWORK')
TurtleCount.icon:SetWidth(13)
TurtleCount.icon:SetHeight(13)
TurtleCount.icon:SetPoint("LEFT", TurtleCount, "LEFT", 5, 0)
TurtleCount.icon:SetTexture("Interface\\Addons\\TurtleCount\\img\\turtle.tga")
local refreshTime = 0
local onlineCount
local maxCount
local highCount
local lowCount
local queried
TurtleCount.Commas = function(number)
number = tonumber(number)
if number > 1000000 then
return gsub(number, "(%d)(%d%d%d)(%d%d%d)$", "%1,%2,%3")
else
return gsub(number, "(%d)(%d%d%d)$", "%1,%2")
end
end
function TurtleCount:UpdateText(count)
count = TurtleCount.Commas(count)
TurtleCount.text:SetText(count)
end
function TurtleCount:ServerInfo()
SendChatMessage(".server info")
queried = true
end
function TurtleCount:RefreshTime()
refreshTime = GetTime() + 60
end
-- Examples of Turtle WoW Server Info:
-- Players online: 1111 (0 queued). Max online: 2222 (33 queued).
-- Server uptime: 11 Hours 22 Minutes 33 Seconds.
-- Server Time: Mon, [01.01.2023] 01:02:03
local HookChatFrame_OnEvent = ChatFrame_OnEvent
function ChatFrame_OnEvent(event)
if (event == "CHAT_MSG_SYSTEM") then
if queried then
_, _, online = string.find(arg1,"Players online:%s*(%d+)")
_, _, max = string.find(arg1,"Max online:%s*(%d+)")
_, _, serverTime = string.find(arg1,"Server Time:%s*(.+)")
if (online and max) then
onlineCount = online
maxCount = max
TurtleCount:UpdateText(onlineCount)
if (not highCount) then
highCount = onlineCount
lowCount = onlineCount
end
if (highCount < onlineCount) then
highCount = onlineCount
end
if ((lowCount > onlineCount)) then
lowCount = onlineCount
end
end
if not serverTime then
return
else
queried = nil
return
end
end
end
HookChatFrame_OnEvent(event)
end
TurtleCount:SetScript("OnUpdate", function()
if (refreshTime) and (GetTime() > refreshTime) then
TurtleCount:ServerInfo()
TurtleCount:RefreshTime()
end
end)
TurtleCount:SetScript("OnEnter", function()
GameTooltip:ClearLines()
GameTooltip:SetOwner(this, ANCHOR_BOTTOMLEFT)
GameTooltip:AddLine("Turtles Online")
GameTooltip:AddDoubleLine("Max", TurtleCount.Commas(maxCount).." players", 1,1,1,1,1,1)
GameTooltip:AddDoubleLine("High", TurtleCount.Commas(highCount).." players", 1,1,1,1,1,1)
GameTooltip:AddDoubleLine("Low", TurtleCount.Commas(lowCount).." players", 1,1,1,1,1,1)
GameTooltip:Show()
end)
TurtleCount:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
TurtleCount:Position()
TurtleCount:Show()