So, I've read through this thread and there seems to be a lot of semi understanding to how
DanNet observers function. I for one learn best by trying and seeing what doesn't work until I find a way I like it to work. If that involves reading through others code, even better.
Of late, I've been on a binge of getting rid of plugins and decide to get rid of
MQ2Debuffs for Core. The following is the result, taken a little further.
This is a frame work for establishing any observers you need with 1 call and a simple string containing the tlo/members you are after.
Using this example, we are going to establish a series of debuffs we want to look for on our group.
Somewhere in your code you have defined the following:
/declare lstObserverCure string outer "|Me|TotalCounters|CountersDisease|CountersCurse|CountersPoison|CountersCorruption|Snared|Mezzed|Maloed|Tashed"
'
This is the list of debuffs and the TLO we will be passing to the function that establishes all the unique observers for each character.
to establish the observers on all your group members you would:
/call observer FALSE "${lstObserverCure}" FALSE
if you wanted to DEBUG it,
/call observer TRUE "${lstObserverCure}" FALSE
If you wan it to be completely quiet:
/call observer FALSE "${lstObserverCure}" TRUE
|***
* DES: creates observers
* USE: /call observer [DEBUG T/F] [string of things to observe] [SILENT T/F]
* NOTE: the variable passed to this sub, _observer, is a list.
* NOTE: the first item in the list is the tlo, all the other items are members you want to check
* NOTE: if you want to use more then 1 TLO, call the sub multiple times with different lists
***|
sub observer(bool _debug, string _observer, bool _silent)
/if (${_debug}) /echo observer(${_debug}, ${_observer})
/declare _countT int local 0
/declare _countE int local 0
/declare _toonName string local FALSE
/declare _element string local FALSE
/declare _TLO string local FALSE
/declare _timestart int local 0
/declare _timeend int local 0
/declare DanNetChannel string local all
/if (${_debug}) /echo Observers Set\aw::\ax\a-tStart\ax
| cycle the toons inside the dan group
/for _countT 1 to ${DanNet.PeerCount[${DanNetChannel}]}
/varset _timestart ${MacroQuest.Running}
/varset _toonName ${DanNet.Peers[${DanNetChannel}].Arg[${_countT},|]}
| skip me
/if (${_toonName.Equal[${Me.DisplayName}]}) /continue
| existing?
/if (${DanNet[${_toonName}].ObserveCount}) /continue
| set the TLO
/if (${_debug}) /echo ::_TLO::${_observer.Arg[1,|]}
/varset _TLO ${_observer}.Arg[1,|]}
| loop the string, skip the first one
/for _countE 2 to ${_observer}.Count[|]}
/if (${_debug}) /echo ::_element[${_countE}]::${_observer.Arg[${_countE},|]}
| set the element
/varset _element ${_observer.Arg[${_countE},|]}
| define the variable. we will be using this for a while. like a long while
/if (!${Defined[${_toonName}_${_element}]}) /declare ${_toonName}_${_element} string outer
| set observer
/if (${_debug}) /echo /dobserve ${_toonName} -q "${_TLO}.${_element}" -o ${_toonName}_${_element}
/dobserve ${_toonName} -q "${_TLO}.${_element}" -o ${_toonName}_${_element}
| give the loop the briefest of pauses..
/delay 1 ${DanNet[${_toonName}].O[${_toonName}_${_element}].Received}
/next _countE
/varset _timeend ${MacroQuest.Running}
/if (!${_silent}) /echo Observers Set\a-t::\ax\aw${_observer}\ax\a-t::\ax\aw${_toonName}\ax ${sep} (${Math.Calc[((${_timeend}-${_timestart}) / 10) / 60]}s)
/next _countT
/return
The snip is fairly commented so you can see what I did. But to summarize, we look therough all the members of the
DanNet group All, and for each person we cycle Me.???? for every other element in the list to establish all the debuff observations.
In the end we get variables like
${charactername_TotalCounters}
that we can echo to see if the toon has any debuffs at all. If they do, then you can start checking which ones they may have. There will be a variable created for each toon_DEBUFF that you want to watch. But in reality, we only need to watch for one to speed up our checks in the end.
For me, my cleric takes about 1 second to establish ~45 observers covering all the debuffs I'm interested in checking for all the toons. How you check the observers is your design, mines a little too built into Core to lay out here. I reestablish this observer routine in case characters. The average time for a cure check cycle for me happens about of every 3 seconds. The actual check takes less then 1 second for all 6 characters in the group.
But this is how I removed
MQ2Debuffs from my builds.
Hopefully, this helps a little in the understanding of observers with working examples. If you have questions, feel free.
-exspes
edit: fixed a variable i forgot to adapt as i pulled it out of my macro.