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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Miniwindow plugin - status window for Aardwolf
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Miniwindow plugin - status window for Aardwolf

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Nick Gammon   Australia  (19,671 posts)  [Biography] bio   Forum Administrator
Date Sun 27 Jul 2008 12:44 AM (UTC)  quote  ]

Amended on Sun 27 Jul 2008 08:47 PM (UTC) by Nick Gammon

Message
The plugin below illustrates using the new miniwindows concept in a plugin.

Miniwindows were released in version 4.34, see here for a copy:

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


The plugin below shows a nice health bar in the bottom RH corner, so you can see at a glance your health, compared to the mob you are fighting.


To use it, download the code below and save as Aardwolf_Health_Bar.xml in the Aardwolf subdirectory below your Plugins directory. If you haven't used any Aardwolf plugins before you may need to make the Aardwolf directory.


This plugin also uses the "stats detector" plugin, so you also need this file:

http://www.gammon.com.au/mushclient/plugins/Aardwolf/Stats_Detector.xml

The "Stats detector" plugin uses telnet negotation, so you also need this file:

http://www.gammon.com.au/mushclient/plugins/Aardwolf/telnet_options.lua

In a standard MUSHclient installation these three files should to into this directory:


C:\Program Files\MUSHclient\worlds\plugins\Aardwolf\


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>

<!-- Plugin "Health_Bar" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Aardwolf_Health_Bar_v2"
   author="Nick Gammon"
   id="1459b816b5acd49c249f72e7"
   language="Lua"
   purpose="Shows Aardwolf stats in a mini window"
   date_written="2008-07-18"
   requires="4.34"
   version="1.0"
   save_state="y"
   >
<description trim="y">
<![CDATA[
Install this plugin to show an info bar with HP, Mana, 
and Movement points shown as a bar (between 0 and 10 blocks).
If you are fighting the enemy's name and health are also displayed.
]]>
</description>

</plugin>

<!--  Script  -->


<script>
<![CDATA[

gauge_left = 45
gauge_height = 11
gauge_right = 190

background_colour = 0x808080
box_colour = 0xD3D3D3

require "checkplugin"

function capitalize (s)
  return string.sub (s, 1, 1):upper () .. string.sub (s, 2):lower ()
end -- capitalize 

function DoGauge (sPrompt, Percent, sGoodColour, sBadColour)

  Percent = tonumber (Percent)
   
  local width = WindowTextWidth (win, font_id, sPrompt)
  
  WindowText (win, font_id, sPrompt,
                             gauge_left - width - 2, vertical - 2, 0, 0, 0x000000)

  WindowRectOp (win, 1,   -- frame rectangle
          gauge_left, vertical, 
          gauge_right, vertical + gauge_height, 
          box_colour)


  local colour
  
--
--  Below 30% warn by using different colour
--

  if Percent < 30 then
    colour = sBadColour
  else
    colour = sGoodColour
  end -- if

  local pixels = (gauge_right - gauge_left - 1) * Percent / 100

  WindowRectOp (win, 2, -- fill rectangle
          gauge_left + 1, vertical + 1, 
          gauge_left + pixels, vertical + gauge_height - 1, 
          ColourNameToRGB (colour))

  vertical = vertical + font_height
end -- function

function draw_bar ()

  check (WindowRectOp (win, 2, 0, 0, 0, 0, background_colour))  -- fill entire box
  
  -- DrawEdge rectangle
  check (WindowRectOp (win, 5, 0, 0, 0, 0, 10, 15))
  vertical = 8  -- pixel to start at
  
  DoGauge ("HP: ",   stats.hp_percent, "darkgreen", "maroon")

  if stats.enemy_percent ~= "9999" then
    -- enemy name:  stats.enemy
    DoGauge ("Enemy: ", stats.enemy_percent, "darkred", "red")
  end -- if fighting 

  DoGauge ("Mana: ", stats.mana_percent, "mediumblue", "mediumblue")
  DoGauge ("Move: ", stats.moves_percent, "gold", "gold")

  WindowShow (win, true)
  
end -- draw_bar

function OnPluginBroadcast (msg, id, name, text)
  if msg == 1 and id == "8a710e0783b431c06d61a54c" then
  
   -- get all variables
   stats = GetPluginVariableList("8a710e0783b431c06d61a54c")
     
   draw_bar ()
   
  end -- stats changed
end

function OnPluginInstall ()
  
  win = GetPluginID ()
  font_id = "fn"
  
  font_name = "Sylfaen"    -- the actual font
  
  -- make miniwindow so I can grab the font info
  check (WindowCreate (win, 
                 0, 0, 200, 65,  
                 8,   -- bottom right
                 0,   -- flags
                 background_colour) )

  check (WindowFont (win, font_id, font_name, 8, false, false, false, false, 0, 0))  -- normal
  
  font_height = WindowFontInfo (win, font_id, 1)  -- height
  
  if GetVariable ("enabled") == "false" then
    ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
    check (EnablePlugin(GetPluginID (), false))
    return
  end -- they didn't enable us last time
  
  OnPluginEnable ()  -- do initialization stuff
  
end -- OnPluginInstall

function OnPluginEnable ()
  checkplugin ("8a710e0783b431c06d61a54c", "Stats_Detector.xml")
end -- OnPluginEnable

function OnPluginDisable ()
  WindowShow (win, false)
end -- OnPluginDisable

function OnPluginSaveState ()
  SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
end -- OnPluginSaveState


]]>
</script>

</muclient>

- Nick Gammon

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

Posted by Nick Gammon   Australia  (19,671 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 27 Jul 2008 12:45 AM (UTC)  quote  ]
Message

Example of it in operation:


- Nick Gammon

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

Posted by Kenneth   (18 posts)  [Biography] bio
Date Reply #2 on Wed 06 Aug 2008 06:06 PM (UTC)  quote  ]
Message
is there any way to put this mini-window in a different corner of the main window? or perhaps a different window?
[Go to top] top

Posted by Nick Gammon   Australia  (19,671 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 07 Aug 2008 12:44 AM (UTC)  quote  ]
Message
Check out this page:

http://www.gammon.com.au/mushclient/mw_creation.htm#WindowCreate

Now in the plugin above is this stuff:


check (WindowCreate (win, 
                 0, 0, 200, 65,  
                 8,   -- bottom right
                 0,   -- flags
                 background_colour) )


The 8 means bottom right, as the comment says. Looking at the link above you can change the 8 to some other number to get a different position.

- Nick Gammon

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

Posted by Kenneth   (18 posts)  [Biography] bio
Date Reply #4 on Thu 07 Aug 2008 12:54 PM (UTC)  quote  ]

Amended on Thu 07 Aug 2008 03:58 PM (UTC) by Kenneth

Message
Thanks Nick, that worked. I actually just found your Map miniwindow plugin, so i'm using that and the Health bar miniwindow in the main window now. Problem solved. :)
[Go to top] top

Posted by Scarn   (47 posts)  [Biography] bio
Date Reply #5 on Mon 25 Aug 2008 04:40 PM (UTC)  quote  ]
Message
Sorry with all the bone quests, but im new at all this.

Could someone post the BASICS of one of these bars, once I get a grip on something im ok at coding but I havent a clue where to start.

My prompt is,

HP:*/130 EP:*/130 REG:* >

If someone could explain to me the basics to just get my HP in a bar (in the info bar) i'd be very gracious. Thanks,
[Go to top] top

Posted by Nick Gammon   Australia  (19,671 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Mon 25 Aug 2008 11:36 PM (UTC)  quote  ]
Message
Look at the Health Bar plugin on this page:

http://www.gammon.com.au/mushclient/plugins/

Basically it uses a trigger to match your prompt, extracts the numbers, and displays them.

- Nick Gammon

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

Posted by Scarn   (47 posts)  [Biography] bio
Date Reply #7 on Tue 26 Aug 2008 06:26 PM (UTC)  quote  ]
Message
Trying to convert this to...


HP:130/130 EP:130/130 REG: >

...is this easily possible?

Great plugin by the way.


[Go to top] top

Posted by Nick Gammon   Australia  (19,671 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Tue 26 Aug 2008 09:24 PM (UTC)  quote  ]
Message
Did you look at the plugin I mentioned? It is certainly possible, you basically want a trigger to match on:

HP:*/* EP:*/* REG: >

and then draw the gauges appropriately.

- Nick Gammon

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

Posted by Scarn   (47 posts)  [Biography] bio
Date Reply #9 on Wed 27 Aug 2008 04:27 PM (UTC)  quote  ]
Message
Okay, I got the bar working fine with my prompt set too (with my full HP at 100).

HP:56/100 EP:65/100 REG: >

However, I wish to have it working from my normal prompt...

HP:56 EP:56 REG: >

I edited the script to replace the "wildcards(2)" and the "wildcards(4)" with the value "100", however when the trigger fires the following error occurs, is there any way round this?

Error number: -2146828275
Event: Execution of line 403 column 3
Description: Type mismatch: 'CInt'
Called by: Function/Sub: DoPrompt called by trigger

Reason: processing trigger "InfoBar"


Again, this is probably something simple - but with my limited knowledge I can't solve it.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Reply #10 on Wed 27 Aug 2008 05:32 PM (UTC)  quote  ]
Message
Could you show what your code looks like?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Scarn   (47 posts)  [Biography] bio
Date Reply #11 on Wed 27 Aug 2008 06:01 PM (UTC)  quote  ]
Message
TRIGGER:

<triggers>
<trigger
enabled="y"
expand_variables="y"
match="^HP\:(\d+)\/(\d+) EP\:(\d+)\/(\d+) REG\: \&gt;$"
name="InfoBar"
regexp="y"
script="DoPrompt"
send_to="12"
sequence="100"
>
<send>setvariable "Health", "%1"
setvariable "Energy", "%3"
setvariable "Region", "%5"

status = WindowCreate ("6", 0, 0, 290,673, 6, 0, ColourNameToRGB ("black"))

status = WindowGradient (6, 27, 10, 50, 33, ColourNameToRGB ("white"),ColourNameToRGB ("white"),1)
status = WindowGradient (6, 34, 10, 42, 33, ColourNameToRGB ("darkred"),ColourNameToRGB ("red"),1)
status = WindowGradient (6, 27, 18, 50, 25, ColourNameToRGB ("darkred"),ColourNameToRGB ("red"),1)

status = WindowGradient (6, 27, 60, 50, 83, ColourNameToRGB ("white"),ColourNameToRGB ("white"),1)
status = WindowGradient (6, 34, 60, 42, 83, ColourNameToRGB ("green"),ColourNameToRGB ("lime"),1)
status = WindowGradient (6, 27, 67, 50, 75, ColourNameToRGB ("green"),ColourNameToRGB ("lime"),1)

status = WindowGradient (6, 20, 110, 50, 133, ColourNameToRGB ("black"),ColourNameToRGB ("saddlebrown"),1)
status = WindowGradient (6, 20, 118, 50, 123, ColourNameToRGB ("sienna"),ColourNameToRGB ("yellow"),1)
status = WindowGradient (6,32, 116, 37, 125, ColourNameToRGB ("orange"),ColourNameToRGB ("yellow"),1)

status = WindowGradient (6, 20, 156, 26, 183, ColourNameToRGB ("cyan"),ColourNameToRGB ("blue"),1)
status = WindowGradient (6, 29, 165, 36, 183, ColourNameToRGB ("fuscia"),ColourNameToRGB ("purple"),1)
status = WindowGradient (6, 38, 173, 46, 183, ColourNameToRGB ("green"),ColourNameToRGB ("lime"),1)
status = WindowGradient (6, 20, 183, 50, 187, ColourNameToRGB ("white"),ColourNameToRGB ("red"),1)

status = WindowFont (6, "heading", "Trebuchet MS", 16, TRUE, FALSE, FALSE, FALSE, 0, 0)
status = WindowText (6, "heading", " Health: @Health",65, 10, 0, 0,ColourNameToRGB ("white"),false)
status = WindowText (6, "heading", " Energy: @Energy",65, 58, 0, 0,ColourNameToRGB ("white"),false)
status = WindowText (6, "heading", " Gold: @Gold",65,108, 0, 0,ColourNameToRGB ("white"),false)
status = WindowText (6, "heading", " Exp: @Exp",65,156, 0, 0,ColourNameToRGB ("white"),false)

status = WindowShow (6, true)

</send>
</trigger>
</triggers>


SCRIPT:

sub DoGauge (sPrompt, iCurrent, iMax, sGoodColour, sBadColour)
dim pc, count

'
' Do prompt in black Arial
'
InfoColour "black"
InfoFont "Arial", 10, 0
Info sPrompt

'
' Use Webdings for gauge (black square)
'

InfoFont "Webdings", 12 , 0

pc = CInt ((CInt (iCurrent) / CInt (iMax)) * 20)

'
' Below 20% warn by using different colour
'

if pc < 2 then
InfoColour sBadColour
else
InfoColour sGoodColour
end if

'
' Draw active part of gauge
'
for count = 0 to pc
Info "g"
next

'
' Draw rest of gauge in grey (ie. unfilled bit)
'

InfoColour "dimgray"
while count <= 20
count = count + 1
Info "g"
wend

end sub

sub DoPrompt (sName, sLine, wildcards)

InfoClear

'
' World name
'

InfoFont "Arial", 12, 1 ' 12 point Arial *bold*
InfoColour "black"
Info GetInfo (2) ' world name
InfoColour "white"
info "Health: "
DoGauge "", wildcards (1), 130, "red", "aqua"
InfoColour "white"
InfoFont "Arial", 12, 1 ' 12 point Arial *bold*
info " Energy: "
DoGauge "", wildcards (3), 130, "mediumblue", "mediumblue"

end sub

'
' Do this once
'
ShowInfoBar vbTrue











END
[Go to top] top

Posted by Nick Gammon   Australia  (19,671 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Wed 27 Aug 2008 09:37 PM (UTC)  quote  ]
Message
I don't understand why the DoGauge script is still there - that is drawing a gauge in the Info bar, whereas the trigger is drawing another one in the miniwindow.

- Nick Gammon

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

Posted by Scarn   (47 posts)  [Biography] bio
Date Reply #13 on Wed 27 Aug 2008 09:45 PM (UTC)  quote  ]
Message
The trigger is just putting some variables in the miniwindow, targets/health/mana points etc etc, not a minibar.
[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.


6,005 views.

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [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.

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]