[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Dynamic Buff Indicator

Dynamic Buff Indicator

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Solaobajiuik   (7 posts)  [Biography] bio
Date Wed 05 Oct 2016 06:39 PM (UTC)
Message
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

[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 05 Oct 2016 08:58 PM (UTC)
Message
You mean, buff_off should make the bar go away? Or the whole thing? See "RemoveBar" in the documentation.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Solaobajiuik   (7 posts)  [Biography] bio
Date Reply #2 on Wed 05 Oct 2016 10:24 PM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 06 Oct 2016 04:28 AM (UTC)
Message
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)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Solaobajiuik   (7 posts)  [Biography] bio
Date Reply #4 on Thu 06 Oct 2016 12:21 PM (UTC)
Message
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
[Go to top] top

Posted by Solaobajiuik   (7 posts)  [Biography] bio
Date Reply #5 on Thu 06 Oct 2016 12:53 PM (UTC)
Message
And of course.. to make it look sexier and readable :)
[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Thu 06 Oct 2016 07:54 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


16,659 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]