How to detect when I have used some bait
I am trying to add a tooltip to my fishing pins in Destinations and I have succeeded.
It reads the amount of bait suitable for that particular type of water, and adds it to the pin info. My problem is, when I have used a bait, then it doesn't update to the new amount when I reopen my map. Only if I change to another map does it update. That is because it is set to re-read bait info from my bag on map change. Is there a way to detect I have used a bait, so I can get it to update the numbers left? I have looked into both fishing events and map events, but can't seem to find any that can be used in this case... Or did I miss something? |
Quote:
how you doing? :) Plan A and B: 1. Maybe EVENT_INVENTORY_ITEM_USED is triggered? 2. EVENT_INVENTORY_SINGLE_SLOT_UPDATE is triggered for sure. May set a dirty flag in that event to re-read baits in custom pins tooltip creator callback. CU |
Quote:
Update: EVENT_INVENTORY_SINGLE_SLOT_UPDATE worked for me :) I set it to update all fishing pins IF the change in the bag was in a fishing bait stack (checked using GetItemLink()). |
or you could recount your stack right before displaying the tooltip with a Prehook "OnShow" ? what are the chances for the tooltip to be already on screen while the baits are depleted?
ZO_PreHook(yourtooltip, "OnShow", yourupdatefunc) If your tooltip is personalized it would restrain the number of calls for sure. (whoops forgot to say hi!:o) actually it would be even savier do it on map display as you tried, but for that you should look at the SCENES functions, I can't tell exactly for this. |
Quote:
Even though EVENT_INVENTORY_SINGLE_SLOT_UPDATE works, and I did set it to only update when a bait stack changes, then it causes a small lag every time it updates, eg. you pick up bait or move/use bait. Not critical, but still... |
yes you have to browse your bag each time, would be the same with the tooltips though I just got another idea:
you can do your own "popuptooltip" like this : MyItemTooltip = WINDOW_MANAGER:CreateControlFromVirtual("MyItemTooltipName", parent , "ZO_ItemIconTooltip") (if SetLink doesn't work with this try "ZO_PopupTooltip" in 3rd arg) then you can anchor it exactly as you want with no risk to make a mistake with the original one and use a SetLink to generate the raw itemtooltip of your baits. it'll have the image and the description but no hooks from other addons. advantage of this : the number of possed items is already on it in the corner : bag and bank with no extra processing the display would a bit overkill for just a number, but at least not the background processing. Maybe just stuck the popup in a corner and use the control to display whatever extra fancy info you need. good luck! |
Quote:
Count the baits, once needed and cache until dirty flag is true again. But there are many ways :) |
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:
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
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:
|
I thank you for all your suggestions, and will see what I can make out of it :)
I guess I was a bit inaccurate in my initial question. I needed to know WHAT kind of bait that have changed in amount. This means I have to check all 9 types of bait. I also need to make sure it can register if I have more than one stack of a certain bait and add it all up. IF I understand this all right, then I can't just cache the amount in a variable for later use, as the amount can change when you move bait to/from your bank, when you pick up bait, when you get it from a mail and so on UNLESS I set it to update in all those cases... The only exception is if I can set it to ONLY update when the map is opened, but I guess it would have to be some sort of a prehook function to make sure the pin data is updated before you point to the pins (correct me if I am wrong). The most important thing is to make it update the amount of correct bait on the correct pins when the map is opened. My current solution does check all 9 and it does take multiple stacks into account. As it is it updates every time there is a change in the bag content by doing a EVENT_INVENTORY_SINGLE_SLOT_UPDATE. It is not optimal, I know, but it works for now :) UPDATE: I realized one thing... So far I have using GetItemLink(BAG_BACKPACK, i) to go through the entire bag. I can use GetFishingLureInfo(lureIndex) instead, just as long as I use the icon name for comparisons (to make sure it works across languages) then I guess that would be a LOT better :) |
I couldn't test circonian's function ( local name, icon, stack, sellPrice, quality = GetFishingLureInfo(lureIndex) ) because i can't log in on PTS and i don't have live installed anymore, but if the indexes are related to the wheel menu (the one to choose the bait when you fish) then it's jackpot : the indexes will be fixed values, the stacks would be already all taken into account i think. (i don't remember the original display, but i'm sure votan knows about that and could confirm)
and the biggest loop you would have to do would be of 9 elements (currently you are browsing your whole bag, aka up to 200 elements each time you pick a bait) In this case you can use the stack return of circonian's function to update your values, lets say on map opening (it would be the cheapest number of calls and the values would be updated before displaying any tooltip - if the guy who can go through his whole screen in less than 10ms doesn't come back :D) afaik there is no way to loot things or fish or look in the bag with the map on the screen so it seems to be a very viable option. Now if this function doesn't rely on incertain indexes, it wouldn't hurt either to use it on a tooltip prehook as it is way lighter than a whole bag check. to know what bait has what index, run the function for all baits and display the name, the stack and the index to see for yourself, you'll see if it add stacks too and references all baits or not. (if it references only the baits you possess, that may be a bit trickier to use it - but you could make a table of baits ids and retrieve the localized name from a fake itemLink it to compare to the name returned by the function for example - these would be little, manageable tables.) i'd like to be more precise with examples of functions but as I can't test by myself right now, i rather count on someone else to tell you how to run the update on map opening for example... edit : eerf i'm a slow typer, you edited and already saw the point of circonian's findings...:rolleyes: beware the chub and the simple bait, not sure they don't share the same pic. |
Quote:
well am not as deep in your problem, as you :) But the tooltip creator of the map pins is/can be a callback-function, which can do anything you want before adding text to the tooltip. you can count the baits the first time a pin is hovered (creator callback is called the first time) and cache the values until map gets closed again. uncomplete example: Code:
... /edit: Ok, I'm even more slow :) |
For now I have ended up with this (a kind of a mix):
Lua Code:
Testing it right now ;) Edit: I am slow too lol |
Quote:
edit cross post with SMDK if you wait 5 mn, i'm sure votan will help with a tested version of bait listing by id and something like this : local fakeitemLink = zo_strformat(|H0blablabla<<1>>blablabla|h|h, baitId) <---build an ItemLink with no name zo_strformat(<<1>>,GetItemLinkName(fakeitemLink)) <-- get localized name - format or not depending on the value returned by GetFishingLureInfo or format both the same to compare (all you need to do this is in fisherman, file Baits.lua btw : all ids, the localized name function too) but i think you are able to simply make a table lure[itemId] = lureindex, i'm pretty sure these indexes are stable because of the selection wheel. 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. |
Quote:
Lua Code:
Edit: You are right about the local lureIndex = GetFishingLure() ;) I just copied from circonian's example lol. |
I was thinking you could avoid the loop by using the indexes directly, though it may look cleaner, it would bring nothing since you update all the values at the same time.
your way is more resistant against indexes variations too. Don't mind what i said. |
Quote:
Now I just need an event that is fired when I OPEN my map (by pressing 'M'). As it is now, it counts every time there is ANY change in my bag, which causes lag. I did look into votan's example using Lua Code:
|
there is an example in votan's answer,I colored it, you'll have to temper with it a bit, he uses the var dirty to even tell if it was necessary to update or not. Now that your counting function is shortened to a minimum, you can run it each time you open the map.
Quote:
maybe try this instead but as I said, i can't test it and i'm the queen of typos. good luck :D Code:
local function WorldMapStateChanged(oldState, newState) Edit : and still a super slow typer. It's not map change, it's Scene State change . just try it. or i'll check another example with the standard scene manager. But anyway it's time for me to call it a day, and soon circonian will be there and make us all look like unwiped kids with a one line function that does everything you always dreamt of and even more. :D |
Quote:
Code:
local function WorldMapStateChanged(oldState, newState) I then closed the map and started fishing. After catching one fish, I opened the map again and pointed to the fishing pin. It still showed the same number as before. BUT... After I zoomed to a city map and back out THEN it showed to correct amount. So... Seems like it doesn't update when I need it to :( |
there must be some prehook with onshow or something...
for starters type this in your chat with the map opened to know the scene name : /script d(SCENE_MANAGER:GetCurrentScene():GetName()) at worse i made something like this but for all the UI mode... i got to retrieve it, i'll edit a bit later --- i used this with the stats panel once, that will require to /zgoo SCENE maybe instead of the script line. I don't remember :s ZO_PreHookHandler(ZO_StatsPanel, "OnShow", myfunctiononshow) ZO_PreHookHandler(ZO_StatsPanel, "OnHide", myfunctiononhide) you got to find the map name to replace ZO_StatsPanel no idea how it would react for gamepad though |
Quote:
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 :D 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? |
Quote:
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 |
Quote:
I can tell that /zgoo mouse returned GetName()= "ZO_WorldMapContainer" GetOwningWindow()= "ZO_WorldMap" GetParent()= "ZO_WorldMapScroll" |
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 |
Quote:
Lua Code:
|
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:
Lua Code:
|
:)
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? |
Quote:
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) |
Quote:
Lua Code:
|
Quote:
Don't know if I did something wrong. Maybe it is because I had already previously opened the map in that zone? |
Quote:
It would be very odd, if the scene state would not change, if you press 'M'. |
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. |
Quote:
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). |
Quote:
Lua 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:
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:
Do the lure counts in the tooltip creator Lua Code:
|
All times are GMT -6. The time now is 03:07 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI