It sounds like you are all talking about scanning the bag for lures. Why not use the lure indices to store the information then all you need is this?
Lua Code:
local name, icon, stack, sellPrice, quality = GetFishingLureInfo(lureIndex)
This is probably not what you need, but you asked for a way to detect when the bait count changes.
I see no way to know when you loose bait, catch something, or stop fishing (when you don't react to a fish on the line). This is the closest I could think of that would work for all situations. There is a delay though, it updates 30 seconds after you cast which was my estimate of the longest time you could have a line in the water before the line is retracted.
Warning: Spoiler
Lua Code:
local TIME_TO_HOLD_KEY_MS = 250
-- This is only a guess
-- maximum time before you fail to catch a fish
-- and you stop fishing automatically
local MAX_LURE_TIME = 30000
local lureCounts = {}
-- Initialize lure counts
local function InitializeLureCounts()
local numLures = GetNumFishingLures()
for lureIndex=1, numLures do
local name, icon, stack, sellPrice, quality = GetFishingLureInfo(lureIndex)
lureCounts[lureIndex] = stack
end
end
-- Update lure count by lureIndex & unregister the update
local function UpdateLureCount(lureIndex)
local lureIndex = GetFishingLure()
local name, icon, stack, sellPrice, quality = GetFishingLureInfo(lureIndex)
lureCounts[lureIndex] = stack
EVENT_MANAGER:UnregisterForUpdate("CheckLureCount")
end
local function OnStopFishingInteraction()
if not SCENE_MANAGER:IsInUIMode() then
local additionalInfo = select(5, GetGameCameraInteractableActionInfo())
-- must be interacting with a fishing node to cast a line
if additionalInfo == ADDITIONAL_INTERACT_INFO_FISHING_NODE then
-- Must have lures to cast a line
if GetFishingLure() ~= 0 then
local self = FISHING_KEYBOARD
if IsInGamepadPreferredMode() then
self = FISHING_GAMEPAD
end
-- If this fails then the bait radial menu "was" displayed through startInteraction
-- so the line is only cast if this is true
if self.beginHold and GetFrameTimeMilliseconds() < self.beginHold + TIME_TO_HOLD_KEY_MS then
d("We cast our lure")
local lureIndex = GetFishingLure()
-- Yes I'm updating now & in 30 seconds.
-- If they catch a fish over & over and keep recasting the line before 30 sec is up the lure might not
-- get updated until 30 sec after they stop fishing. So update on cast & in 30 seconds.
-- best I could think of
UpdateLureCount(lureIndex)
-- No reliable way to know when you stop fishing, so use a timer
EVENT_MANAGER:RegisterForUpdate("CheckLureCount", MAX_LURE_TIME, function() UpdateLureCount(lureIndex) end)
end
end
end
end
end
-- Use FISHING_MANAGER so it will catch both keyboard & gamepade modes
ZO_PreHook(FISHING_MANAGER, "StopInteraction", OnStopFishingInteraction)
If you only need to know the lure counts when a map pin tooltip is displayed use the lureIndices. I don't know how your storing the lure information, but since your adding information about the lure to the pin tooltip, you must know which lure it is. If you use the lureIndices to identify/store that information about the lures then when you add the info to the pin you already know the lureindex so just update the stack count first with this:
Lua Code:
-- example
local lureCounts = {
[lureIndex] = {},
}
local name, icon, stack, sellPrice, quality = GetFishingLureInfo(lureIndex)
lureCounts[lureIndex].stack = stack
-- do whatever to add info to pin