That makes sense, sure they don't want players exploiting the API. I only need X and Y, I don't need Z. Say the player's position is [X] = 0.467469, [Y] = 0.409835 and the position of the target is [X] = 0.415760, [Y] = 0.427441. At the moment, if someone were to make a combat mod, it is returning X and Y for NPCs, so it's not really protected to prevent misuse.
At the moment most of the equations I have seen for calculating the distance of a harvest node, a Crate, a barrel, an NPC seem to use just the difference of x1 and x2, then y1 and y2. HarvestMap, uses more of what I am looking for.
Standard Form: (x-a)2 + (y-b)2 = r2
HarvestMap:
dx = entry[1] - x
dy = entry[2] - y
dx * dx + dy * dy < 0.000025 ( 0.005 ^ 2 )
Say the NPC, Barrel, Crate, Sack, is at the center (a,b) and the player is at (x,y). I want to calculate that distance. Basically that is what is happening in RangeReticle. I tossed in a plethora of d("") lines to print out information. The mod successfully returned my distance from the center of the circle (a,b) in meters.
I could have been standing on the circle the same "r" distance from (a,b) and RangeReticle calculated the distance correctly. However, when I went to use GetMapPlayerPosition('reticleover') to get the position of what my reticle was on, all the values were 0, not just the Z value, but X and Y also.
Which is why I am wondering if there is another option.
Warning: Spoiler
Lua Code:
function getTargetDistance(itemX, itemY)
local multiplier = 5.0
local theRange = 0
-- Get details of what's under the reticle
local targetX, targetY, targetH = GetMapPlayerPosition('reticleover')
-- Get details of the player
local selfX, selfY, selfH = GetMapPlayerPosition('player')
-- Get map details
local mapWidth, mapHeight = GetMapNumTiles()
local mapType = GetMapType()
local mapContentType = GetMapContentType()
-- Calculate and display target range
if targetX and targetY then
local dimensionsX, dimensionsY = ZO_WorldMapContainer:GetDimensions()
if mapContentType == MAP_CONTENT_NONE then
if mapType == MAPTYPE_SUBZONE then
elseif mapType == MAPTYPE_ZONE then
end
elseif mapContentType == MAP_CONTENT_AVA then
if mapType == MAPTYPE_SUBZONE then
elseif mapType == MAPTYPE_ZONE then
multiplier = 12.0
end
elseif mapContentType == MAP_CONTENT_DUNGEON then
if mapType == MAPTYPE_SUBZONE then
dimensionsX, dimensionsY = ZO_WorldMapContainer1:GetDimensions()
multiplier = 1.0
elseif mapType == MAPTYPE_ZONE then
end
end
if dimensionsX <= 2000 then
previousDimensionsX = dimensionsX
elseif previousDimensionsX <= 2000 then
dimensionsX = previousDimensionsX
end
if dimensionsY <= 2000 then
previousDimensionsY = dimensionsY
elseif previousDimensionsY <= 2000 then
dimensionsY = previousDimensionsY
end
if dimensionsX > 2000 or dimensionsY > 2000 then
local X, Y = ZO_WorldMapContainer:GetDimensions()
local X1, Y1 = ZO_WorldMapContainer1:GetDimensions()
dimensionsX = math.min(X, X1)
dimensionsY = math.min(Y, Y1)
end
local actualSelfX = selfX * dimensionsX
local actualSelfY = selfY * dimensionsY
local actualTargetX = itemX * dimensionsX
local actualTargetY = itemY * dimensionsY
local dist = math.sqrt(math.pow((actualSelfX - actualTargetX), 2) + math.pow((actualSelfY - actualTargetY), 2)) * multiplier
distance = math.floor(dist + 0.5)
-- Disable range functionality when a zone isn't working with range calculation
if distance > 100 then
distance = -999
end
if distance >= 0 then
theRange = distance
end
end
return {
range = theRange,
dist = multiplier
}
end
That is the function I used from RangeReticle to test with. I basically turned it into a function I could pass the arguments to of the Node. So say the Node is a fishing hole, I was passing the locations of all the fishing holes to that function.
Lua Code:
for i = 1, #sv do
local item = sv[i]
d("Range of loot : " .. getTargetDistance(item[1], item[2]).range)
end
Just to see what the values were, and what it returned. It returns a nice neat distance of 0 to, oh say 48 meters.
Well that is a lot to calculate, and I could ask permission to use the code, but I want to use my own code. In fact all I really want to use is Standard Form of (x-a)2 + (y-b)2 = r2. I can't get (a,b) from GetMapPlayerPosition('reticleover') unless it's an NPC.