Zadrot Alert

08.07.2025 - Zadrot

Zadrot Alert

Какой-то чел на бг сегодня попросил выложить аддон.
Не проблема.
Добавил даже китайский и английский переводы переводчиком.
Если вдруг там что обидное, я не виноват.

Zadrot Alert - простенький оповещатор о приближающихся врагах на БГшках.

Весит 8 килобайт. Проверено пару раз на версии Pandaria Classic.

Как использовать:
Жми кнопку на миникарте (или /zalert) чтобы показать окно
В окне жми кнопку чтобы оповестить союзников о приближающихся врагах

Кстати, если кто ходит на бг, создал новое Близзард сообщество для организации групп на случайные и рейтинговые поля боя БГшка в Пандарии. Для премейдов короче. Оно доступно прямо в игре, там же, где гильдия. Присоединяйтесь :)

  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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
local addonName = "Zadrot Alert"
local ZA = CreateFrame("Frame", addonName, UIParent)
ZA:RegisterEvent("PLAYER_ENTERING_WORLD")
ZA:RegisterEvent("ZONE_CHANGED")
ZA:RegisterEvent("ZONE_CHANGED_INDOORS")
ZA:RegisterEvent("ZONE_CHANGED_NEW_AREA")
ZA:SetScript("OnEvent", function(self, event)
    if event == "PLAYER_ENTERING_WORLD" then
        ZadrotAlert_Initialize()
        self:UnregisterEvent("PLAYER_ENTERING_WORLD")
    elseif event == "ZONE_CHANGED" or event == "ZONE_CHANGED_INDOORS" or event == "ZONE_CHANGED_NEW_AREA" then
        if ZA.frame then
            ZA.UpdateUI()
        end
    end
end)

local L = {
    ruRU = {
        ONE = "1",
        TWO = "2",
        THREE = "3",
        FOUR = "4",
        MANY = "Много",
        CLEAR = "Чисто",
        APPROACHING = "Приближается",
        ENEMY_SINGLE = "враг",
        ENEMY_DUAL = "врага",
        ENEMY_PLURAL = "врагов",
        MANY_ENEMIES = "много врагов",
        ALL_CLEAR = "Всё чисто!",
        LOCATION_NOT_FOUND = "Локация не найдена",
        ERROR_PREFIX = "ZA Ошибка",
        PREFIX = "ZA"
    },
    zhCN = {
        ONE = "1",
        TWO = "2",
        THREE = "3",
        FOUR = "4",
        MANY = "许多",
        CLEAR = "清除",
        APPROACHING = "接近中",
        ENEMY_SINGLE = "敌人",
        ENEMY_DUAL = "敌人",
        ENEMY_PLURAL = "敌人",
        MANY_ENEMIES = "许多敌人",
        ALL_CLEAR = "一切清除!",
        LOCATION_NOT_FOUND = "位置未找到",
        ERROR_PREFIX = "ZA 错误",
        PREFIX = "ZA"
    },
    enUS = {
        ONE = "1",
        TWO = "2",
        THREE = "3",
        FOUR = "4",
        MANY = "Many",
        CLEAR = "Clear",
        APPROACHING = "Approaching",
        ENEMY_SINGLE = "enemy",
        ENEMY_DUAL = "enemies",
        ENEMY_PLURAL = "enemies",
        MANY_ENEMIES = "many enemies",
        ALL_CLEAR = "All clear!",
        LOCATION_NOT_FOUND = "Location not found",
        ERROR_PREFIX = "ZA Error",
        PREFIX = "ZA"
    }
}

local locale = GetLocale()
local lang = L[locale] or L.enUS

if locale == "zhCN" or locale == "zhTW" then
    lang = L.zhCN
end

if locale == "ruRU" then
    lang = L.ruRU
end

local function utf8sub(str, start, numChars)
    local currentIndex = start
    local charCount = 0
    local result = ""
    
    while currentIndex <= #str and charCount < numChars do
        local c = str:byte(currentIndex)
        local charLen = 1
        if c > 240 then
            charLen = 4
        elseif c > 225 then
            charLen = 3
        elseif c > 192 then
            charLen = 2
        end
        
        result = result .. str:sub(currentIndex, currentIndex + charLen - 1)
        currentIndex = currentIndex + charLen
        charCount = charCount + 1
    end
    
    if currentIndex <= #str then
        result = result .. "..."
    end
    
    return result
end

function ZA.UpdateUI()
    if not ZA.frame then return end
    
    local zone = GetZoneText()
    local subzone = GetSubZoneText()
    local validSubzone = (subzone ~= "" and subzone ~= zone)
    
    if validSubzone then
        if #subzone > 25 then
            subzone = utf8sub(subzone, 1, 21)
        end
        ZA.frame.title:SetText(subzone)
    else
        ZA.frame.title:SetText(addonName)
    end
    
    for _, button in ipairs(ZA.frame.buttons) do
        if validSubzone then
            button:Enable()
        else
            button:Disable()
        end
    end
end

function ZadrotAlert_Initialize()
    ZA.frame = CreateFrame("Frame", addonName.."Frame", UIParent)
    local frame = ZA.frame
    frame:SetSize(220, 120)
    frame:SetPoint("RIGHT", UIParent, "RIGHT", -110, 0)
    frame:SetMovable(true)
    frame:EnableMouse(true)
    frame:RegisterForDrag("LeftButton")
    frame:SetScript("OnDragStart", frame.StartMoving)
    frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
    frame:Hide()
    
    local bg = frame:CreateTexture(nil, "BACKGROUND")
    bg:SetAllPoints()
    bg:SetColorTexture(0.1, 0.1, 0.1, 0.8)
    
    frame.title = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    frame.title:SetPoint("TOP", 0, -10)
    frame.title:SetWidth(200)
    frame.title:SetText(addonName)
    frame.title:SetTextColor(1, 1, 1)
    
    frame.buttons = {}
    
    local topButtons = {
        {text = lang.ONE, count = 1, x = -75},
        {text = lang.TWO, count = 2, x = -25},
        {text = lang.THREE, count = 3, x = 25},
        {text = lang.FOUR, count = 4, x = 75}
    }

    for i, btnInfo in ipairs(topButtons) do
        local btn = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
        btn:SetSize(40, 30)
        btn:SetPoint("TOP", btnInfo.x, -35)
        btn:SetText(btnInfo.text)
        btn:SetScript("OnClick", function()
            SendAlert(btnInfo.count)
        end)
        table.insert(frame.buttons, btn)
    end

    local bottomButtons = {
        {text = lang.MANY, count = 5, x = -50},
        {text = lang.CLEAR, count = 0, x = 50}
    }

    for i, btnInfo in ipairs(bottomButtons) do
        local btn = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
        btn:SetSize(80, 30)
        btn:SetPoint("TOP", btnInfo.x, -75)
        btn:SetText(btnInfo.text)
        btn:SetScript("OnClick", function()
            SendAlert(btnInfo.count)
        end)
        table.insert(frame.buttons, btn)
    end
    
    local miniButton = CreateFrame("Button", addonName.."MiniButton", Minimap)
    miniButton:SetSize(20, 20)
    miniButton:SetPoint("TOPLEFT", Minimap, "TOPLEFT", 2, -2)
    miniButton:SetNormalTexture("Interface\\Icons\\Ability_warrior_rallyingcry")
    miniButton:GetNormalTexture():SetTexCoord(0.1, 0.9, 0.1, 0.9)
    miniButton:SetScript("OnClick", function() 
        frame:SetShown(not frame:IsShown()) 
    end)
    
    SLASH_ZADROTALERT1 = "/zalert"
    SlashCmdList["ZADROTALERT"] = function() 
        frame:SetShown(not frame:IsShown()) 
    end
    
    ZA.UpdateUI()
end

function SendAlert(count)
    local subzone = GetSubZoneText()
    local zone = GetZoneText()
    
    local validSubzone = false
    if subzone ~= "" and subzone ~= zone then
        validSubzone = true
    end
    
    if not validSubzone then
        DEFAULT_CHAT_FRAME:AddMessage("|cFFFF0000["..lang.ERROR_PREFIX.."]:|r "..lang.LOCATION_NOT_FOUND)
        return
    end
    
    local location = subzone
    local message
    
    if count == 5 then
        message = string.format("%s %s! [%s]", 
            lang.APPROACHING, 
            lang.MANY_ENEMIES, 
            location)
    elseif count > 0 then
        if GetLocale() == "zhCN" or GetLocale() == "zhTW" then
            message = string.format("%s %d %s! [%s]", 
                lang.APPROACHING, 
                count, 
                lang.ENEMY_PLURAL, 
                location)
        else
            local enemyWord
            if count == 1 then
                enemyWord = lang.ENEMY_SINGLE
            elseif count < 5 then
                enemyWord = lang.ENEMY_DUAL
            else
                enemyWord = lang.ENEMY_PLURAL
            end
            
            message = string.format("%s %d %s! [%s]", 
                lang.APPROACHING, 
                count, 
                enemyWord, 
                location)
        end
    else
        message = string.format("%s [%s]", lang.ALL_CLEAR, location)
    end
    
    if IsInInstance() then
        SendChatMessage(message, "INSTANCE_CHAT")
    else
        DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00["..lang.PREFIX.."]:|r "..message)
    end
end