1
+ -- constants
2
+ local playerName = UnitName (" player" )
3
+ local defaultMpThreshold = 50
4
+ local antiSpamThresholdValue = 20
5
+
6
+ -- Saved vars (config)
7
+ local mpThreshold -- mp = mana percentage
8
+
9
+ -- vars
10
+ local antiSpam = false
11
+ local antiSpamThreshold
12
+
13
+ local version = GetAddOnMetadata (" OutOfMana2" ," Version" )
14
+ -- Addon loaded message
15
+ print (" |c0003fc07OOM |r[v|c0003fc07" .. version .. " |r] loaded: /mana" )
16
+
17
+ -- Handle Events
18
+ local f = CreateFrame (" Frame" );
19
+ f :RegisterEvent (" ADDON_LOADED" )
20
+ f :RegisterEvent (" PLAYER_LOGOUT" )
21
+ f :RegisterEvent (" UNIT_POWER_UPDATE" )
22
+
23
+ function f :OnEvent (event , arg1 , arg2 )
24
+ if event == " ADDON_LOADED" and arg1 == " OutOfMana2" then
25
+ if not OutOfManaDB2 then
26
+ OutOfManaDB2 = {}
27
+ OutOfManaDB2 .mpThreshold = defaultMpThreshold
28
+ end
29
+ mpThreshold = OutOfManaDB2 .mpThreshold
30
+ antiSpamThreshold = mpThreshold + antiSpamThresholdValue
31
+ end
32
+ if event == " PLAYER_LOGOUT" then
33
+ OutOfManaDB2 .mpThreshold = mpThreshold
34
+ end
35
+ if event == " UNIT_POWER_UPDATE" then
36
+ local mp = (UnitPower (" player" , 0 ) / UnitPowerMax (" player" )) * 100 -- current player mana percentage
37
+ if (arg1 == " player" ) and (arg2 == " MANA" ) and (mp <= mpThreshold ) and (not antiSpam ) then
38
+ DoEmote (" OOM" )
39
+ SendChatMessage (playerName .. " - I have " .. round (mp ) .. " % mana!" , IsInGroup (LE_PARTY_CATEGORY_INSTANCE ) and " INSTANCE_CHAT" or IsInRaid () and " RAID" or " PARTY" )
40
+ antiSpam = true
41
+ end
42
+ if (arg1 == " player" ) and (arg2 == " MANA" ) and (mp >= antiSpamThreshold ) and antiSpam then
43
+ antiSpam = false
44
+ end
45
+ end
46
+ end
47
+
48
+ f :SetScript (" OnEvent" , f .OnEvent )
49
+
50
+ function round (number )
51
+ if (number - (number % 0.1 )) - (number - (number % 1 )) < 0.5 then
52
+ number = number - (number % 1 )
53
+ else
54
+ number = (number - (number % 1 )) + 1
55
+ end
56
+ return number
57
+ end
58
+
59
+ -- Commands
60
+ SLASH_SAVED1 = " /mana" ;
61
+ function SlashCmdList .SAVED (msg )
62
+ if msg ~= " " then
63
+ mpThreshold = tonumber (msg )
64
+ print (" Changed limit to: " .. mpThreshold .. " %" )
65
+ if (mpThreshold + antiSpamThresholdValue > 100 ) then
66
+ antiSpamThreshold = 100
67
+ else
68
+ antiSpamThreshold = mpThreshold + antiSpamThresholdValue
69
+ end
70
+ else
71
+ print (" Limit: " .. mpThreshold .. " %" .. " (\" /mana number\" to change)" )
72
+ end
73
+ end
0 commit comments