View Single Post
09/22/20, 04:17 PM   #3
QuantumPie
AddOn Author - Click to view addons
Join Date: Sep 2019
Posts: 32
Originally Posted by votan View Post
<emperor>Welcome on the dark side</emperor>

You are right, size is used as a value, only. By default. But by the power of Lua you can intercept accessing properties like "size" to change the returned value dynamically.
For example:
Lua Code:
  1. function addon:HookPOIPins()
  2.     local GetCurrentMapIndex = GetCurrentMapIndex
  3.     local function HookPinSize(data)
  4.         local orgMetaTable = getmetatable(data)
  5.         local orgSize = data.size or 40
  6.         data.size = nil -- Force to ask the metatable
  7.  
  8.         local newMetaTable = {}
  9.         setmetatable(newMetaTable, orgMetaTable)
  10.         local alter = {}
  11.         alter.size = function()
  12.             return GetCurrentMapIndex() == 1 and 1 or orgSize
  13.         end
  14.                 -- more alternates here
  15.  
  16.         newMetaTable.__index = function(data, key)
  17.             return alter[key] and alter[key](data) or newMetaTable[key] -- if alternate exists, call it
  18.         end
  19.         newMetaTable.__newindex = function(data, key, value)
  20.             if key == "size" then
  21.                 orgSize = value
  22.                 return -- Do not set value within table to keep using metatable
  23.             end
  24.             return rawset(data, key, value)
  25.         end
  26.         setmetatable(data, newMetaTable)
  27.     end
  28.     HookPinSize(ZO_MapPin.PIN_DATA[MAP_PIN_TYPE_FAST_TRAVEL_WAYSHRINE])
  29.     HookPinSize(ZO_MapPin.PIN_DATA[MAP_PIN_TYPE_FAST_TRAVEL_WAYSHRINE_CURRENT_LOC])
  30. end
Of course you have to adapt this to your needs.
How could I get the players unit tag from this? In your addon you set the texture and color to a function that takes the pin as the parameter and gets the unit tag from that. Is there a similar way to achieve this with the hook?
  Reply With Quote