-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeathCount.lua
168 lines (131 loc) · 3.74 KB
/
DeathCount.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
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
DC = {};
DC.fully_loaded = false;
DC.default_options = {
frameRef = "TOP",
frameX = 0,
frameY = 0,
hide = false,
frameW = 200 ,
frameH = 200,
};
deathCounter = 0
local function DeathCountChat(msg, editbox)
if msg == 'say' then
SendChatMessage("Total Deaths:"..' '..tostring(deathCounter), "SAY", "Common", "Bob");
elseif msg == 'reset' then
deathCounter = 0
DeathSave = 0
print("Amount of deaths have been reset to 0")
else
print("Total Deaths:"..' '..tostring(deathCounter));
end
end
SLASH_DCOUNTER1, SLASH_DCOUNTER2 = '/deaths', '/death'
SlashCmdList["DCOUNTER"] = DeathCountChat
function DC.OnReady()
_G.DCPrefs = _G.DCPrefs or {};
for k,v in pairs(DC.default_options) do
if (not _G.DCPrefs[k]) then
_G.DCPrefs[k] = v;
end
end
DC.CreateUIFrame();
end
function DC.OnSaving()
if (DC.UIFrame) then
local point, relativeTo, relativePoint, xOfs, yOfs = DC.UIFrame:GetPoint()
_G.DCPrefs.frameRef = relativePoint;
_G.DCPrefs.frameX = xOfs;
_G.DCPrefs.frameY = yOfs;
end
end
function DC.OnEvent(frame, event, ...)
if (event == 'ADDON_LOADED') then
local name = ...;
if name == 'DC' then
DC.OnReady();
end
return;
end
if (event == 'PLAYER_LOGIN') then
DC.fully_loaded = true;
if DeathSave == nil then
DeathSave = 0
else
deathCounter = DeathSave
end
return;
end
if (event == 'PLAYER_DEAD') then
deathCounter = DeathSave+1
print("You died. Total deaths:"..' '..tostring(deathCounter));
DeathSave = deathCounter
return;
end
if (event == 'PLAYER_LOGOUT') then
DC.OnSaving();
DeathSave = deathCounter
return;
end
end
function DC.CreateUIFrame()
DC.UIFrame = CreateFrame("Frame",nil,UIParent);
DC.UIFrame:SetFrameStrata("BACKGROUND")
DC.UIFrame:SetWidth(_G.DCPrefs.frameW);
DC.UIFrame:SetHeight(_G.DCPrefs.frameH);
DC.UIFrame.texture = DC.UIFrame:CreateTexture();
DC.UIFrame.texture:SetAllPoints(DC.UIFrame);
DC.UIFrame.texture:SetTexture(0, 0, 0);
DC.UIFrame:SetPoint(_G.DCPrefs.frameRef, _G.DCPrefs.frameX, _G.DCPrefs.frameY);
DC.UIFrame:SetMovable(true);
DC.UIFrame:EnableMouse(true);
DC.Cover = CreateFrame("Button", nil, DC.UIFrame);
DC.Cover:SetFrameLevel(128);
DC.Cover:SetPoint("TOPLEFT", 0, 0);
DC.Cover:SetWidth(_G.DCPrefs.frameW);
DC.Cover:SetHeight(_G.DCPrefs.frameH);
DC.Cover:EnableMouse(true);
DC.Cover:RegisterForClicks("AnyUp");
DC.Cover:RegisterForDrag("LeftButton");
DC.Cover:SetScript("OnDragStart", DC.OnDragStart);
DC.Cover:SetScript("OnDragStop", DC.OnDragStop);
DC.Cover:SetScript("OnClick", DC.OnClick);
DC.Label = DC.Cover:CreateFontString(nil, "OVERLAY");
DC.Label:SetPoint("CENTER", DC.UIFrame, "CENTER", 2, 0);
DC.Label:SetJustifyH("LEFT");
DC.Label:SetFont([[Fonts\FRIZQT__.TTF]], 12, "OUTLINE");
DC.Label:SetText(" ");
DC.Label:SetTextColor(1,1,1,1);
DC.SetFontSize(DC.Label, 20);
end
function DC.SetFontSize(string, size)
local Font, Height, Flags = string:GetFont()
if (not (Height == size)) then
string:SetFont(Font, size, Flags)
end
end
function DC.OnDragStart(frame)
DC.UIFrame:StartMoving();
DC.UIFrame.isMoving = true;
GameTooltip:Hide()
end
function DC.OnDragStop(frame)
DC.UIFrame:StopMovingOrSizing();
DC.UIFrame.isMoving = false;
end
function DC.OnClick(self, aButton)
if (aButton == "RightButton") then
print("Total Deaths:"..' '..tostring(deathCounter));
end
end
function DC.UpdateFrame()
DC.Label:SetText("Deaths:"..' '..tostring(deathCounter));
end
DC.EventFrame = CreateFrame("Frame");
DC.EventFrame:Show();
DC.EventFrame:SetScript("OnEvent", DC.OnEvent);
DC.EventFrame:SetScript("OnUpdate", DC.OnUpdate);
DC.EventFrame:RegisterEvent("ADDON_LOADED");
DC.EventFrame:RegisterEvent("PLAYER_LOGIN");
DC.EventFrame:RegisterEvent("PLAYER_LOGOUT");
DC.EventFrame:RegisterEvent("PLAYER_DEAD");