Maelstrom counter script

I somehow managed to get Microsoft Copilot to write a working script that counts how much maelstrom my Shaman has and uses. The script also lets me move the counter around and resize it. Only there is one problem. When I change zones, log in and out, or reload, the script resets to its original location and size. I spent over an hour trying to get Copilot to fix the issue but it keeps failing. I even went so far as to give it an example with a well written mage icicle counter script, but for some reason Copilot just couldn’t finish the job.

Here is the script that works but doesn’t save location and size of the counter. Any of you know how to add that to the script?




local frame = CreateFrame(“FRAME”,“MaelstromCounterUI”,UIParent); – Need a frame to respond to events
frame:RegisterEvent(“PLAYER_LOGIN”); – Fired when saved variables are loaded
frame:RegisterEvent(“PLAYER_LOGOUT”); – Fired when about to log out
frame:RegisterEvent(“UNIT_AURA”);

frame:SetWidth(128); – Set these to whatever height/width is needed
frame:SetHeight(64); – for your Texture

frame.text = frame:CreateFontString();
frame.text:SetPoint(“CENTER”, 0, 0)
frame.text:SetSize(128, 64)
frame.text:SetFont(“Fonts\FRIZQT__.TTF”, 12, “OUTLINE”)
frame:SetMovable(true);
frame.tex = frame:CreateTexture(nil, “BACKGROUND”)
frame.tex:SetAllPoints()
frame.tex:SetColorTexture(1, 1, 1, 0.5)

frame:SetPoint(“CENTER”,0,0);
function frame:RecalculateUI()
frame.text:SetFont(“Fonts\FRIZQT__.TTF”, MaelstromCounter.size, “OUTLINE”);
frame.text:SetHeight(MaelstromCounter.size1.2);
frame.text:SetWidth(MaelstromCounter.size
1.2);
frame:SetHeight(frame.text:GetHeight());
frame:SetWidth(frame.text:GetWidth());
frame.tex:SetAllPoints()

	frame:Hide();

if MaelstromCounter.show then
	frame:Show();
end

frame:ClearAllPoints()
frame:SetPoint(MaelstromCounter.point,MaelstromCounter.relativeTo,MaelstromCounter.relativePoint,MaelstromCounter.xOf,MaelstromCounter.yOf);

end
SLASH_MAELSTROMCOUNTER1 = “/mc”
SLASH_MAELSTROMCOUNTER2 = “/maelstromcounter”
SlashCmdList[“MAELSTROMCOUNTER”] = function(msg)
local _, _, cmd, args = string.find(msg, “%s?(%w+)%s?(.*)”)
if cmd == “move” then

MaelstromCounter.movable = not MaelstromCounter.movable;
if MaelstromCounter.movable then
	print("Start moving mouse to adjust positon of the frame.");
	frame:SetMovable(true);
	frame:StartMoving()
else
	print("Position saved.");
	frame:StopMovingOrSizing()
	frame:SetMovable(false);
MaelstromCounter.point,MaelstromCounter.relativeTo,MaelstromCounter.relativePoint,MaelstromCounter.xOf,MaelstromCounter.yOf = frame:GetPoint(1);
	frame:RecalculateUI()
end

elseif cmd == “size” then
MaelstromCounter.size = tonumber(args)
print("Font size set to " … MaelstromCounter.size);
frame:RecalculateUI()
elseif cmd == “show” then
MaelstromCounter.show = true;
frame:RecalculateUI()
print(“Maelstrom counter showed”)
elseif cmd == “hide” then
MaelstromCounter.show = false;
frame:RecalculateUI()
print(“Maelstrom counter vanished”)
elseif cmd == “reset” then
frame:Defaults();
frame:RecalculateUI()
print(“Maelstrom counter set to default”)
else
print(“Available commands: show, hide, move, size, reset”)
end
end
function frame:Defaults()
MaelstromCounter = {};
MaelstromCounter.size = 60;
MaelstromCounter.movable = false;
MaelstromCounter.point = “CENTER”;
MaelstromCounter.xOf = 0;
MaelstromCounter.yOf = 0;
MaelstromCounter.show = true;
MaelstromCounter.relativeTo = UIParent;
MaelstromCounter.relativePoint = “CENTER”
frame.text:SetFont(“Fonts\FRIZQT__.TTF”, MaelstromCounter.size, “OUTLINE”);
end
function frame:Maelstrom()
local name,count,max,_
max=0;
for i=1,40 do
name,_,count=UnitAura(“player”,i,“HELPFUL”);
if name == “Maelstrom Weapon” then
max=count;
end
frame.text:SetText(max)
end
if max == 5 then
frame.tex:SetColorTexture(0, 0.5, 1, 0.7)
else
frame.tex:SetColorTexture(0, 0, 0, 0)
end
end
function frame:OnEvent(event, arg1)
if event == “PLAYER_LOGIN” then
if MaelstromCounter == nil then
frame:Defaults();
frame:RecalculateUI()

end
if MaelstromCounter then
MaelstromCounter.movable = false;
frame.text:SetFont(“Fonts\FRIZQT__.TTF”, MaelstromCounter.size, “OUTLINE”);
frame:RecalculateUI()
end
elseif event == “PLAYER_LOGOUT” then
end

if event == “UNIT_AURA” then
frame:Maelstrom();
end
end
frame:Hide();
frame:SetScript(“OnEvent”, frame.OnEvent);

There’s existing WeakAuras that do what you want, such as:
https://wago.io/XEn00CYpA

Yea, was hoping to do it without a bloated addon. Someone wrote a nice working script for mage icicles so thought a similar one could be done for shaman maelstrom. Like I said, the maelstrom script written by Microsoft Copilot works fine.

But saving the size and location after you move it is an issue cause it always reverts back to its original size and location which is right on top of my character in center of screen. The mage icicle one does not do it.