How to reset the PlayerFrame with lua?

–Last Update–
Thanks to Gregory on the WoW Addons; discord for helping me out.
The reason the function wasn’t working when just in a lua file with nothing else is that it was trying to execute too soon. Using the code below and making it wait for the PLAYER_ENTERING_WORLD event it works and resets the PlayerFrame location.

One more note, by checking arg1, the code is checking to see if this is the initial login, if not it doesn’t run the code. Would do something like this if you didn’t want the code firing on reload or changing zones.

local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function(self, event, arg1)
    if arg1 then -- If you are logging in and not reloading the UI or changing "instances"
        PlayerFrame_ResetUserPlacedPosition()
    end
end)



–Update–
So, I took the function and added it into a button and it works. I am not sure what the difference is, but here is the code that works with a button.

local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")

btn:SetPoint("CENTER")

btn:SetSize(100, 40)

btn:SetText("Click me")

btn:SetScript("OnClick",

              function(self, button) PlayerFrame_ResetUserPlacedPosition() end)


I am trying to make a simple addon for moving around, saving, and resetting the PlayerFrame.

Note that I am attempting this on the live Classic servers.

I have figured out how to move it but not what to do if I want to reset it. I know if you right click there is an option to reset the frame, is there way to use that? I have found the function from Blizzard, below. Is there way to use this function?

function UIParent_UpdateTopFramePositions()
	local topOffset = 0;
	local buffsAreaTopOffset = 0;

	if (OrderHallCommandBar and OrderHallCommandBar:IsShown()) then
		topOffset = 12;
		buffsAreaTopOffset = OrderHallCommandBar:GetHeight();
	end

	if (PlayerFrame and not PlayerFrame:IsUserPlaced() and not PlayerFrame_IsAnimatedOut(PlayerFrame)) then
		PlayerFrame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", -19, -4 - topOffset)
	end

	if (TargetFrame and not TargetFrame:IsUserPlaced()) then
		TargetFrame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 250, -4 - topOffset);
	end

	local ticketStatusFrameShown = TicketStatusFrame and TicketStatusFrame:IsShown();
	local gmChatStatusFrameShown = GMChatStatusFrame and GMChatStatusFrame:IsShown();
	if (ticketStatusFrameShown) then
		TicketStatusFrame:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", -180, 0 - buffsAreaTopOffset);
		buffsAreaTopOffset = buffsAreaTopOffset + TicketStatusFrame:GetHeight();
	end
	if (gmChatStatusFrameShown) then
		GMChatStatusFrame:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", -170, -5 - buffsAreaTopOffset);
		buffsAreaTopOffset = buffsAreaTopOffset + GMChatStatusFrame:GetHeight() + 5;
	end
	if (not ticketStatusFrameShown and not gmChatStatusFrameShown) then
		buffsAreaTopOffset = buffsAreaTopOffset + 13;
	end

	BuffFrame:SetPoint("TOPRIGHT", MinimapCluster, "TOPLEFT", -10, 0 - buffsAreaTopOffset);
end

The above function was used in this reset function for the PlayerFrame from Blizzard.

function PlayerFrame_ResetUserPlacedPosition()

  PlayerFrame:ClearAllPoints();

  PlayerFrame:SetUserPlaced(false);

  PlayerFrame:SetClampedToScreen(false);

  PlayerFrame_SetLocked(true);

  UIParent_UpdateTopFramePositions();

end