0

In World Of Warcraft I have created a little coords script that outputs current coords:

local function ou(self,elapsed)
    px,py=GetPlayerMapPosition("player")
    DEFAULT_CHAT_FRAME:AddMessage(format("( %s )  [%f , %f]",GetZoneText(), px *100, py *100))
end

local f = CreateFrame("frame")
f:SetScript("OnUpdate", ou)

This however spams default chat frame...

How would I create custom frame and how would I access it?
(I can't use custom channel with SendChatMessage)

...I would like to do this WITHOUT making an addon, thanks :)

4

1 回答 1

1

I found a solution in storing frame in global variable, as I don't intend to create a plugin, the whole program requires a few macros (macro's maximum number of characters is 255).

First macro - prepare function that will set frame attributes later
f = input frame that will be set
x = x coordinate of position
y = y coordinate of position

function setMyFrame(f,x,y)
   f:SetSize(288,100)
   f:SetPoint("TOPLEFT",UIParent,"TOPLEFT",x,y) 
   f.text = f.text or f:CreateFontString(nil,"ARTWORK","QuestFont_Shadow_Huge")   
   f.text:SetAllPoints(true)     
end

Second macro - prepare coords function that will set current coords as frame's text
ctotel = time elapsed since last update of the frame
creft = how often should the frame be updated in SECONDS - good one is 0.1 - 10 times a second is performance friendly and fast enaugh to coords update
f = input frame that will be updated
i = "how long it's been since the last update call cycle" (you don't set that - it is inherited from the WoW system)

ctotel = 0
creft = 0.1
function myCoords(f,i)
   ctotel = ctotel + i
   if ctotel >= creft then
      px,py=GetPlayerMapPosition("player")
      f.text:SetText(format("( %s ) [%f , %f]",GetZoneText(), px *100, py *100))
      ctotel = 0
   end
end

Third macro - store frame in global variable and set it and run update script with myCoords as callback

myCoordsFrame = CreateFrame("Frame","MyCoordsFrame",UIParent)
setMyFrame(myCoordsFrame, 500, 0)
myCoordsFrame:SetScript("OnUpdate", myCoords)

Of course in game all macros have to be preceeded with /run and have to be inlined - no line breaks - instead of linebreak just make space...

Also you have to run macros in THIS ^^^ order (first=>second=>third)

Advantage in setting frame and creft as globals:
Frames can't be destroyed while in the world (you have to relog to destroy them) so when it's global you can later move it with

/run setMyFrame(myCoordsFrame, NEW_X_COORDINATE, NEW_Y_COORDINATE)

If you would like the coords to update slower/faster you can do it by resetting the creft - e.g. to almost realtime refresh every 0.05 or even 0.01 seconds:
/run creft = 0.05 ... or even /run creft = 0.01

Make Coords movable - draggable by left mouse (credit to Wanderingfox from WoWhead):

myCoordsFrame:SetMovable(true)
myCoordsFrame:EnableMouse(true)
myCoordsFrame:SetScript("OnMouseDown",function() myCoordsFrame:StartMoving() end)
myCoordsFrame:SetScript("OnMouseUp",function() myCoordsFrame:StopMovingOrSizing() end)

...and as copy-paste ingame macro:

/run myCoordsFrame:SetMovable(true) myCoordsFrame:EnableMouse(true) myCoordsFrame:SetScript("OnMouseDown",function() myCoordsFrame:StartMoving() end) myCoordsFrame:SetScript("OnMouseUp",function() myCoordsFrame:StopMovingOrSizing() end)
于 2015-09-01T17:16:13.823 回答