View Single Post
11-09-09, 03:06 AM   #300
gorocketgo
A Defias Bandit
Join Date: Nov 2009
Posts: 2
To the addon author:

I am trying to make an improvement upon how the safezeone is calculated. I am only yet a novice at lua so please correct my understanding here:

1. Events like OnClick or OnKeyDown happen in the client (I can try casting if I am disconnected)
2. Events like UNIT_SPELLCAST_START arrive from the server (I cannot start casting if I am disconnected)

So here's an example of how my idea will work:

1. Hook the click or keypress that triggers a spell
2. In the script handler, I save the value of GetTime() to varA
3. In the event handler for UNIT_SPELLCAST_START I save the value of GetTime() to varB
4. I subtract varA from varB to find the latency for the cast.

Here's how I tested this idea:

Code:
local sent
local received

--Client starts cast
local button = CreateFrame('CheckButton', 'mybutton', UIParent, 'ActionBarButtonTemplate')
button:SetPoint("CENTER")
button:SetAttribute('type', 'spell')
button:SetAttribute('spell', "Lesser Heal")

button:SetScript("PostClick", function(self, button, down)
	sent = GetTime()

	DEFAULT_CHAT_FRAME:AddMessage(format(">>>Cast sent at %f", sent))
	end
)

--Client receives cast
local Test = CreateFrame('Frame')
Test:RegisterEvent("UNIT_SPELLCAST_START")

Test:SetScript("OnEvent", function()
	received = GetTime()
	local latency = (received - sent) * 1e3

	DEFAULT_CHAT_FRAME:AddMessage(format("<<<Event received at %f", received))
	DEFAULT_CHAT_FRAME:AddMessage(format("Latency results at %dms", latency))
	end
)
Now every time I cast it will find the right latency:

>>Cast began at 119838.474000
<<Event received at 119838.597000
Latency results at 123ms

And this value would be used to measure your safezone etc. I hope this makes sense. Please reply with your thoughts. Thanks.