Dynamic Buff Indicator

Posted by Solaobajiuik on Wed 05 Oct 2016 06:39 PM — 7 posts, 26,806 views.

#0
I saw that a Forum User named Jarvis actually got one working with the bar's being removed/added instead of staying on the screen. Does anyone have something that will do this dynamic like that? I'm trying to write one myself, however, I am having problems getting the bar's to remove themselves.

require "InfoBox"

box = InfoBox:New("ARMOR")
buffs = box:AddBar("Buffs")
box.Bars[1].captionPlacement = 4
box:CaptionPlacement()
box:Update()

function buff_on (spell)
	buffs = box:AddBar(spell, 100, "darkgreen")
	box.Bars[1].captionPlacement = 4
	box:CaptionPlacement()
	box:Update()
end

function buff_off (spell)
	buffs = box:AddBar(spell, 100, "darkred")
	box.Bars[1].captionPlacement = 4
	box:CaptionPlacement()
	box:Update()
end

Australia Forum Administrator #1
You mean, buff_off should make the bar go away? Or the whole thing? See "RemoveBar" in the documentation.
#2
The way I read the documentation buff_off would need to be


function buff_off (spell)
	buffs = box:RemoveBar(1)
	box.Bars[1].captionPlacement = 4
	box:CaptionPlacement()
	box:Update()
end


But, what I am trying to do is


function buff_off (spell)
	buffs = box:RemoveBar(spell)
	box.Bars[1].captionPlacement = 4
	box:CaptionPlacement()
	box:Update()
end


Or some way to figure out what the numeric value of the bar of that spell name is.
Australia Forum Administrator #3
As you add new buffs the new one is added to a table. If you do this you will see it:


require "tprint"
tprint (box)


Amongst other things you see:


"Bars":
  1:
    "matteShadow"=5131854
    "cellLeft"=0
    "cellTop"=6
    "id"=1
    "captionPlacement"=4
    "matteHilight"=11711154
    "caption"="Buffs"
  2:
    "id"=2
    "goodColour"=25600
    "cellLeft"=0
    "matteShadow"=5131854
    "value"=100
    "cellTop"=31
    "matteHilight"=11711154
    "caption"="bar"


My caption was "bar" in this case.

You could iterate through that table to find the id number like this:


local index = nil
for k, v in ipairs (box.Bars) do
  if v.caption == "bar" then   -- or whatever caption you want
    index = v.id
    break
  end -- if
end -- for

print ("ID for bar is ", index)
#4
Alright, So I got that working now. Thanks Nick! Last thing to do is find out if its possible to drag+move InfoBars. I've love to be able to move the miniwindow around by clicking on the header.

It doesn't sound like InfoBars are moveable. It's all based on the initial placement.


require "InfoBox"

box = InfoBox:New("ARMOR")
buffs = box:AddBar("Buffs")
box.Bars[1].captionPlacement = 4
box:CaptionPlacement()
box:Update()

function buff_on (spell)
	local barID = getbarID(spell)

	if barID ~= nil then
		buffs = box:RemoveBar(barID)
		box.Bars[1].captionPlacement = 4
		box:CaptionPlacement()
		box:Update()
	end
end -- buff_on

function buff_off (spell)
	buffs = box:AddBar(spell, 100, "darkred")
	box.Bars[1].captionPlacement = 4
	box:CaptionPlacement()
	box:Update()
end -- buff_off
 
function getbarID (caption)
	require "tprint"

	local index = nil
    for k, v in ipairs (box.Bars) do
		if v.caption == caption then
    		index = v.id
    		break
  		end -- if
	end -- for

	return index;
end -- getbarID
#5
And of course.. to make it look sexier and readable :)
Australia Forum Administrator #6
You don't need the "tprint" line there, that was just for debugging.

To move the window (bar) see this post:

http://www.gammon.com.au/forum/?id=9594


Add these three lines to after "box:Update()" and you can then drag the bar window around:


require "movewindow"  
windowinfo = movewindow.install (box.windowName, miniwin.pos_center_right, 0)  -- default position / flags
movewindow.add_drag_handler (box.windowName, 0, 0, 0, 0, miniwin.cursor_both_arrow) 


With slightly more work you can get it to remember where you left the bar last time and put it back there - see the post above for more details.