Last edited by Wopak; 09-09-2012 at 12:39 AM.
Because PQR_UnitInfor(var1) returns 5 Values or more, can't remember in a Table:
Value 1: X position
Value 2: Y position
Value 3: Z position
Value 4: Faction ID?
Value 5: Cant rememberI know most of the time, for me, it return's 0 lol
EDIT* See how I do select(1,... and select(2,...? I'm selecting those 2 values from the table that PQR_UnitInfo() is creating, in this case, The X and Y values of both my Target and myself in my rotation's.
EDIT** After reading over it, I just came to a conclusion. I don't have to call it twice, but hey, I made this function way back when I was just really starting to understand LUA coding. I'll have to change it around xD lol
Last edited by firepong; 09-09-2012 at 12:57 AM.
Your last EDIT was my point exactlyNow you've taken 2 call out out PQR_UnitDistance, that you basically have no control over, which leaves us with:
Function PQR_UnitDistance(var1, var2)
if UnitExists(var1) and not UnitIsDead(var1) then
local x1 , y1 = PQR_UnitInfo(var1)
local x2 , y2 = PQR_UnitInfo(var2)
local w = 100000
local h = 100000
local distance = sqrt(min(x1 - x2, w - (x1 - x2))^2 + min(y1 - y2, h - (y1-y2))^2)
return distance
end
end
-----
Now, i know this is all minor thing's, but i'm used to database optimizing IRL and everything adds up, so here goes.
You declaring to local variables that you're not carrying over to something else, or doing any other internal manipulation too, so i assume it's only 'fot the looks'
local w = 100000
local h = 100000
Delete those and put those values directly in the line
local distance = sqrt(min(x1 - x2, 100000 - (x1 - x2))^2 + min(y1 - y2, 100000 - (y1-y2))^2)
Now for this line itself, it's rather pointless to make distance a local variable for the exact same reasons as stated above, plus the fact that you're declaring distance only to return it in the next line, best option is to do this.
return sqrt(min(x1 - x2, w - (x1 - x2))^2 + min(y1 - y2, h - (y1-y2))^2)
and delete
return distance
Leaving you with
Function PQR_UnitDistance(var1, var2)
if UnitExists(var1) and not UnitIsDead(var1) then
local x1 , y1 = PQR_UnitInfo(var1)
local x2 , y2 = PQR_UnitInfo(var2)
return sqrt(min(x1 - x2, 100000 - (x1 - x2))^2 + min(y1 - y2, 100000 - (y1-y2))^2)
end
end
For your thought's about taking out UnitExists(), i can't say really, i only deal with objects. But a general rule of thumb is: Always ensure you have valid input data
Last edited by Wopak; 09-09-2012 at 05:05 AM.
Testing comparison between Buba Fury Single Target and FAW, Results Attachment 10052 http://oi49.tinypic.com/34ypauc.jpg
Last edited by CrazyCactuaR; 09-09-2012 at 07:07 AM.
(╯°□°)╯︵┻━┻ ლ(ಠ益ಠლ
Still LF disc priest profiles both pvp / pve :s
Whats FAW?
is it possible to make PQR press Keys after a key press? if i press E if will press Q W R right after ? or if i press R Q it will press mouse5?