Thread Tools Display Modes
12/22/15, 05:33 PM   #21
Wandamey
Guest
Posts: n/a
Originally Posted by SnowmanDK View Post
I can say that what you wrote above returns
worldMap
no matter what map I have showing. I tried while showing Tamriel, Coldharbour, Craglorn and Davon's Watch.

Edit: Now I am slow again

From your edit, then I assume I should make something like this on addon load?:
ZO_PreHookHandler("worldMap", "OnShow", myfunctiononshow)
or did I miss something?
no I missed something, i was looking for an example with a scene-manager function (which would have used "worldMap" ) when I found my PreHookHandler that need the control name, not the scene name

maybe /zgoo mouse or /zgoo SCENE while on a map and browse around to find that map "panel" name that begins with ZO_

it's a bit frustrating to not be able to load a char... circonian? help? OK this time I go to bed for real. gn8

Last edited by Wandamey : 12/22/15 at 05:36 PM.
  Reply With Quote
12/22/15, 05:39 PM   #22
SnowmanDK
 
SnowmanDK's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 161
Originally Posted by Wandamey View Post
no I missed something, i was looking for an example with a scene-manager function (which would have used "worldMap" ) when I found my PreHookHandler that need the control name, not the scene name

maybe /zgoo mouse or /zgoo SCENE while on a map and browse around to find that map "panel" name that begins with ZO_

it's a bit frustrating to not be able to load a char... circonian? help? OK this time I go to bed for real. gn8
Well have a good night
I can tell that
/zgoo mouse
returned
GetName()= "ZO_WorldMapContainer"
GetOwningWindow()= "ZO_WorldMap"
GetParent()= "ZO_WorldMapScroll"
  Reply With Quote
12/22/15, 05:42 PM   #23
Wandamey
Guest
Posts: n/a
I lied, i looked into a map mod instead of going to bed and found ZO_WorldMap too

try

ZO_PreHookHandler(ZO_WorldMap, "OnShow", UpdateBaitsCount)

and if it works it will be the one line function that does all of what you dreamt
and now i think i can sleep
  Reply With Quote
12/22/15, 06:37 PM   #24
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by SnowmanDK View Post
For now I have ended up with this (a kind of a mix):
Lua Code:
  1. --
  2.             if     string.find(icon, "centipede") then  --Crawlers
  3.                 ...
Just a little tip to make that part more concise with just two string matches (using a table for counts instead of individual local vars):
Lua Code:
  1. -- at file scope
  2. local bait_to_water = {
  3.   centipede="Foul", fish_roe="Foul",
  4.   torchbug="River", shad="River",
  5.   worms="Ocean", fish_tail="?",
  6.   guts="Lake", river_betty="Lake"
  7. }
  8.  
  9. -- in func
  10.   local counts = {}
  11.  
  12. -- in loop
  13.   local k = icon:match("centipede|fish_roe|torchbug|shad|worms|fish_tail|guts|river_betty")
  14.   local water = bait_to_water[k]
  15.   if water == "?" then
  16.     if name:find("simple|einfacher|appāt") then --Simle Bait
  17.         water = "General"
  18.     else    --Chub
  19.         water = "Ocean"
  20.     end
  21.   end
  22.   if water then
  23.     counts[water] = (counts[water] or 0) + stack
  24.   end
  Reply With Quote
12/23/15, 01:46 PM   #25
SnowmanDK
 
SnowmanDK's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 161
First, merry christmas, happy hanuka, or whatever

With the great help from all you guys, then I ended with what I think is my final code.
I may no have used what you all suggested, but you still inspired me
function:
Lua Code:
  1. local function UpdateBaitAmount()
  2.     if DestinationsSV.filters[PINS_FISHING_SHOW_BAIT_LEFT] then
  3.         local numLures = GetNumFishingLures()
  4.         local oldBaitCount = defaults.data.FoulBaitLeft + defaults.data.FoulSBaitLeft + defaults.data.RiverBaitLeft + defaults.data.RiverSBaitLeft + defaults.data.OceanBaitLeft + defaults.data.OceanSBaitLeft + defaults.data.LakeBaitLeft + defaults.data.LakeSBaitLeft + defaults.data.GeneralBait
  5.         local baitCount = 0
  6.         for lureIndex=1, numLures do
  7.             if stack then
  8.                 baitCount = baitCount + stack
  9.             end
  10.         end
  11.         if baitCount ~= oldBaitCount then
  12.             LMP:RefreshPins(PINS_FISHING)
  13.         end
  14.     end
  15. end
call:
Lua Code:
  1. ZO_PreHookHandler(ZO_WorldMap, "OnShow", UpdateBaitAmount)
I know I COULD have chosen to just fire the LMP:RefreshPins(PINS_FISHING) every time the map opens to skip the comparison of stacks, but I think this will have a smaller impact on the game.
  Reply With Quote
12/23/15, 05:36 PM   #26
Wandamey
Guest
Posts: n/a

don't forget this
local name, icon, stack, sellPrice, quality = GetFishingLureInfo(lureIndex)
before using the stack variable.


And idk what happens in refresh pins, if you refresh your data there or not, but in case, as the call is already done to count the stacks in this loop, you might as well update your saved variables right away (with the name and icon check) for the next check.
You'll have to do it at some point and the call is done so... Beside these are very small loops and in UI mode it's not like you're looting zombies in the middle of a swarm.

also, if i lose 2 worms and find 2 minows, it wont update.

but i'm not sure what you are displaying though : the total number of baits? or the total for this water type? or each type amout for the water?
  Reply With Quote
12/24/15, 07:50 AM   #27
SnowmanDK
 
SnowmanDK's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 161
Originally Posted by Wandamey View Post

don't forget this
local name, icon, stack, sellPrice, quality = GetFishingLureInfo(lureIndex)
before using the stack variable.


And idk what happens in refresh pins, if you refresh your data there or not, but in case, as the call is already done to count the stacks in this loop, you might as well update your saved variables right away (with the name and icon check) for the next check.
You'll have to do it at some point and the call is done so... Beside these are very small loops and in UI mode it's not like you're looting zombies in the middle of a swarm.

also, if i lose 2 worms and find 2 minows, it wont update.

but i'm not sure what you are displaying though : the total number of baits? or the total for this water type? or each type amout for the water?
Ooops deleted that part by accident: "GetFishingLureInfo(lureIndex)"
It always does it's initial count on player load, so that part is covered.
In regards to the chance of getting 2 of one bait and loosing 2 of another, then you are right. The chance of that happening is small, but I guess I should count them individually.
Thanks for the tips

My pins show this (example, depending on settings in Destinations. They can all be toggled)
achievement name
rare fish name (the fish names can be only the ones missing, OR all for the acheivement)
rare fish name
rare fish name
water type (foul, ocean etc.)
optimal primary bait name/optimal rare bait name
primary bait left/rare bait left/simple bait left (if any)
  Reply With Quote
12/25/15, 04:16 AM   #28
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by SnowmanDK View Post
I can say that what you wrote above returns
worldMap
no matter what map I have showing. I tried while showing Tamriel, Coldharbour, Craglorn and Davon's Watch.

Edit: Now I am slow again

From your edit, then I assume I should make something like this on addon load?:
ZO_PreHookHandler("worldMap", "OnShow", myfunctiononshow)
or did I miss something?
Although I still don't understand, why not doing the count upon first tooltip, checking if the world map is shown or about to be shown can be done this way:
Lua Code:
  1. local function WorldMapStateChanged(oldState, newState)
  2.         if (newState == SCENE_FRAGMENT_SHOWING) then
  3.         elseif (newState == SCENE_FRAGMENT_SHOWN) then
  4.         end
  5. end
  6. WORLD_MAP_SCENE:RegisterCallback("StateChange", WorldMapStateChanged)
  Reply With Quote
12/25/15, 10:20 AM   #29
SnowmanDK
 
SnowmanDK's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 161
Originally Posted by votan View Post
Although I still don't understand, why not doing the count upon first tooltip, checking if the world map is shown or about to be shown can be done this way:
Lua Code:
  1. local function WorldMapStateChanged(oldState, newState)
  2.         if (newState == SCENE_FRAGMENT_SHOWING) then
  3.         elseif (newState == SCENE_FRAGMENT_SHOWN) then
  4.         end
  5. end
  6. WORLD_MAP_SCENE:RegisterCallback("StateChange", WorldMapStateChanged)
I tried that but it only triggered when I changed to another map. Not when I just pressed "M".
Don't know if I did something wrong. Maybe it is because I had already previously opened the map in that zone?
  Reply With Quote
12/25/15, 12:22 PM   #30
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by SnowmanDK View Post
I tried that but it only triggered when I changed to another map. Not when I just pressed "M".
Don't know if I did something wrong. Maybe it is because I had already previously opened the map in that zone?
Are you sure? From what you telling here, it sounds more like the callback "OnWorldMapChanged", which is not the same.
It would be very odd, if the scene state would not change, if you press 'M'.
  Reply With Quote
12/25/15, 01:25 PM   #31
Wandamey
Guest
Posts: n/a
hi guys, merry Christmas!

and yup that should have worked, but maybe the issue wasn't the callback when you tried last page, Snowman, but the value you are using to update your pins :

last of your (posted) code, you say your count is updated on player activated (and probably map changed too?), but when you check if the count has changed in what you wrote, nowhere you are updating the new value to use it on the refreshed pins
As I said idk what happens on refresh pins, but as it seems to be from a lib I assume the new value is not calculated there.

maybe that was what prevented the update on state change and made you have to change the shown map to update your values.
  Reply With Quote
12/26/15, 03:38 PM   #32
SnowmanDK
 
SnowmanDK's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 161
Originally Posted by Wandamey View Post
hi guys, merry Christmas!

and yup that should have worked, but maybe the issue wasn't the callback when you tried last page, Snowman, but the value you are using to update your pins :

last of your (posted) code, you say your count is updated on player activated (and probably map changed too?), but when you check if the count has changed in what you wrote, nowhere you are updating the new value to use it on the refreshed pins
As I said idk what happens on refresh pins, but as it seems to be from a lib I assume the new value is not calculated there.

maybe that was what prevented the update on state change and made you have to change the shown map to update your values.
It was refreshing fishing pins in lines 11-13 of my last code
The code for re-reading the bait amounts are included in that part (as I have had issues with too many functions before, then I try to include them in existing ones).
  Reply With Quote
12/26/15, 09:37 PM   #33
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by Wandamey View Post
re edit : you are using local lureIndex = GetFishingLure() at first? It probably just return the index of the current lure on the rod? not sure. but anyway you are using it as the indice 2 lines later. Doesn't seem needed at all.
Oops, your right that's pointless. It was supposed to be
Lua Code:
  1. local lureIndex = lureIndex or GetFishingLure()
I wrote the function one way & then changed it and missed that and yes it returns the index of the lure on the rod which was part of some code I sent him to check the counts after fishing so only the index of the lure on the rod was needed for that code.

As for the map change talk...it seems like you only need this info for the map pin tooltip so why not just do it in the creator?
Map pin tooltips are re-created everytime they are shown, so your bait count update code would only have to run when a tooltip is shown, which sounds like the only time you need the updated count.
Also that way you would not have to re-check the counts for all of the types of baits. Since you would know which map pin the tooltip is for, you know which baits you are wanting to display and you only have to update those bait counts.


Add a lures table to your pin tag to hold the usable lureIndices:
Lua Code:
  1. -- approx. line 3177
  2. local tooltipText = {
  3.    -- add this table
  4.    lures = {},
  5. }

Then instead of creating the string {3/1/71} for counts in FishpinTypeCallback, just determine which lureIndex is usable in that water and put those lure indices in the lures table in the tag.
Lua Code:
  1. elseif TYPE == 43 then
  2. --[[
  3.     fishingBaitLeft = tostring(LakeBaitLeft).."/"..tostring(LakeSBaitLeft)
  4.     if GeneralBait >= 1 then
  5.         fishingBaitLeft = fishingBaitLeft.."/"..tostring(GeneralBait)
  6.     table.insert(tooltipText.lures, 0)
  7.     end
  8.     textLine = textLine + 1
  9.     table.insert(tooltipText, textLine, ZO_ColorDef:New(unpack(DestinationsSV.pins.pinTextureFish.textcolorBait)):Colorize(zo_strformat("<<1>>", "{"..fishingBaitLeft.."}")))
  10. --]]
  11.     -- Decide which lureIndices should be used & add them to the table
  12.         -- 5 = just an example of some lure Index usable in this water
  13.     table.insert(tooltipText.lures, 5)
  14.     -- add as many lure indices as needed, insert them in the order
  15.     -- you want them displayed in


Do the lure counts in the tooltip creator
Lua Code:
  1. local pinTooltipCreator = {
  2.     creator = function(pin)
  3.         local pinType, pinTag = pin:GetPinTypeAndTag()
  4.        
  5.         -- do it here
  6.         -- You may need some check to make sure its a fishing map pin
  7.         -- if pinType == xxxxx then
  8.             local lures = pinTag.lures
  9.             local tooltipLureCountText
  10.            
  11.             for _, lureIndex in pairs(lures) do
  12.                 -- updates bait count
  13.                 local name, icon, stack, sellPrice, quality  = GetFishingLureInfo(lureIndex)   
  14.            
  15.                 -- If you need something more complex than just the
  16.                 -- lure counts in the backpack call a custom function instead
  17.                 -- to do that work
  18.                 --local stack = UpdateLureCount(lureIndex)
  19.  
  20.                 -- if you need to save counts for use in other places besides the tooltip save it here
  21.                 -- someTable.whatever[lureIndex] = stack
  22.  
  23.                 -- build the tooltip text line for lure counts as you go
  24.                 if tooltipLureCountText then
  25.                     tooltipLureCountText = zo_strformat("<<1>>/<<2>>", tooltipLureCountText, stack)
  26.                 else
  27.                     tooltipLureCountText = stack
  28.                 end
  29.             end
  30.             -- add your { }
  31.             tooltipLureCountText = zo_strformat("{<<1>>}", tooltipLureCountText)
  32.            
  33.             -- Update the new string in your tag:
  34.             pinTag[4] = tooltipLureCountText
  35.         --end
  36.        
  37.        
  38.         for _, lineData in ipairs(pinTag) do
  39.             SetTooltipText(InformationTooltip, lineData)
  40.         end
  41.     end,
  42.     tooltip = 1,
  43. }

Last edited by circonian : 12/26/15 at 11:12 PM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » How to detect when I have used some bait

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off