[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]  Miniwindows
. . -> [Subject]  Health -- Enemy Bar Problem
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Health -- Enemy Bar Problem

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


Posted by Cybercholo   Mexico  (6 posts)  [Biography] bio
Date Thu 28 Aug 2014 06:08 PM (UTC)

Amended on Thu 28 Aug 2014 09:06 PM (UTC) by Cybercholo

Message
I have a problem using the plugin Health_Bar_Miniwindow.

I have modified to work with the following prompt:
&Y<%h/%Hhp %m/%Mmana %v/%Vmov %E <%d><%a><%A><%S>>&W

and looks like this:

prompt
<21156/21156hp 11591/11591mana 1541/1541mov (NL) <2217><1000><S><E>>


fprompt
&Y<%h/%Hhp %m/%Mmana %v/%Vmov %E>&W

<21156/21156hp 11591/11591mana 1539/1541mov (98%) >


The Health bar displays perfectly Hp, Mana, Mov and during combat Hp shows the enemy.

The problem is that when the value is "(NL)" Bar On Screen is not displayed, whereas if likes "(99%)" is displayed and the values ​​are updated every assault.


do_prompt function (name, line, wildcards) 
   hp = tonumber max_hp (wildcards [1]), tonumber (wildcards [2]) 
   mana, max_mana = tonumber (wildcards [3]), tonumber (wildcards [4]) 
   move, max_move = tonumber (wildcards [5]), tonumber (wildcards [6]) 
   if "%7" == "NL" then 
    enemy, tonumber max_enemy = ("100"), tonumber ("100") 
     else 
    enemy, max_enemy = tonumber (wildcards [7]), tonumber ("100") 
   end - if 



This is how I tried to solve the problem does not work.

Any idea?
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #1 on Thu 28 Aug 2014 08:30 PM (UTC)
Message
If that's directly pasted from your script, you have a space in %7 that shouldn't be there. Pretty sure %7 shouldn't be in quotes either.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Cybercholo   Mexico  (6 posts)  [Biography] bio
Date Reply #2 on Thu 28 Aug 2014 09:09 PM (UTC)

Amended on Thu 28 Aug 2014 09:10 PM (UTC) by Cybercholo

Message
Meerclar said:

If that's directly pasted from your script, you have a space in %7 that shouldn't be there. Pretty sure %7 shouldn't be in quotes either.


was an error copying the script, is "%7" and also try wildcards [7]

and corrected the previous post.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 28 Aug 2014 09:16 PM (UTC)
Message
Can you show the trigger please?

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.


Also show your script:


do_prompt function (name, line, wildcards) 
   hp = tonumber max_hp (wildcards [1]), tonumber (wildcards [2]) 
   mana, max_mana = tonumber (wildcards [3]), tonumber (wildcards [4]) 
   move, max_move = tonumber (wildcards [5]), tonumber (wildcards [6]) 
   if "%7" == "NL" then 
    enemy, tonumber max_enemy = ("100"), tonumber ("100") 
     else 
    enemy, max_enemy = tonumber (wildcards [7]), tonumber ("100") 
   end - if 


That just doesn't look right. For one thing the "%7" should be wildcards [7], and I can't really believe that compiled.

When I try that I get:

Compile error
World: smaug
Immediate execution
[string "Immediate"]:1: '=' expected near 'function'

- Nick Gammon

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

Posted by Cybercholo   Mexico  (6 posts)  [Biography] bio
Date Reply #4 on Thu 28 Aug 2014 09:39 PM (UTC)
Message

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

<muclient>
<plugin
   name="Health_Bar_Miniwindow"
   author="Nick Gammon"
   id="48062dcd6b968c590df50f32"
   language="Lua"
   purpose="Shows stats in a mini window"
   date_written="2010-02-14 09:00"
   requires="4.40"
   version="2.0"
   save_state="y"
   >
<description trim="y">
<![CDATA[

La utilidad de instalar este plugin es de volver el prompt normal en una version grafica que muestre los puntos de vida, mana, movimiento, deidad y alineamiento en las famosas barras de energia.


Este plugin funcionara a partir de nivel 10, pues antes el alineamiento en el prompt sale en forma alfabetica.


Una vez que se visualize la ventana grafica, se puede reposicionar en dentro de la pantalla en donde mejor convenga. Solo hace falta poner el mouse encima, y mantener presionado el boton izquierdo del mouse y ponerla en el lugar deseado.

Esta pensado para un prompt tipo Smaug, mas especificamente para un prompt de Balzhur MUD.

El siguiente prompt es el que puede leer el codigo para poder pasarlo a modo grafico automaticamente:
prompt:
&Y<%h/%Hhp %m/%Mmana %v/%Vmov %E <%d><%a><%A><%S>>&W

Asi se veria el prompt en su pantalla: (saldra en color amarillo)

<1156/1156hp 1591/1591mana 1541/1541mov <2500><1000><HS><E>>

fprompt:
&Y<%h/%Hhp %m/%Mmana %v/%Vmov %E >&W

Asi se veria el prompt en su pantalla:
<21156/21156hp 11591/11591mana 1536/1541mov (100%) >

Antes de instalar el plugin, tendra que cambiar su prompt al que se
indica arriba.




]]>
</description>

</plugin>

<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="^&lt;(d+)s*/(d+)hp (d+)/(d+)mana (d+)/(d+)mov ((d+).*) "
   regexp="y"
   script="do_prompt"
   sequence="100"
  >
  </trigger>
</triggers>



<!--  Script  -->


<script>
<![CDATA[

GAUGE_HEIGHT = 20

WINDOW_WIDTH = 270
WINDOW_HEIGHT = 88
NUMBER_OF_TICKS = 10

BACKGROUND_COLOUR = ColourNameToRGB "rosybrown"
FONT_COLOUR = ColourNameToRGB "darkred"
BORDER_COLOUR = ColourNameToRGB "#553333"

function DoGauge (sPrompt, current, max, Colour)

  if max <= 0 then 
    return 
  end -- no divide by zero
  
  -- fraction in range 0 to 1
  local Fraction = math.min (math.max (current / max, 0), 1) 
   
  local width = WindowTextWidth (win, font_id, sPrompt)
  
  WindowText (win, font_id, sPrompt, gauge_left - width, vertical, 0, 0, FONT_COLOUR)

  WindowRectOp (win, 2, gauge_left, vertical, WINDOW_WIDTH - 7, vertical + GAUGE_HEIGHT, -- en vez de 7, tenia 5
                          BACKGROUND_COLOUR)  -- fill entire box
  
  local gauge_width = (WINDOW_WIDTH - gauge_left - 5) * Fraction -- en vez de 7, tenia 5 
  
   -- box size must be > 0 or WindowGradient fills the whole thing 
  if math.floor (gauge_width) > 0 then
    
    -- top half
    WindowGradient (win, gauge_left, vertical, gauge_left + gauge_width, vertical + GAUGE_HEIGHT / 2, 
                    0x000000,
                    Colour, 2) 
    
    -- bottom half
    WindowGradient (win, gauge_left, vertical + GAUGE_HEIGHT / 2, 
                    gauge_left + gauge_width, vertical +  GAUGE_HEIGHT,   
                    Colour,
                    0x000000,
                    2) 

  end -- non-zero
  
  -- show ticks
  local ticks_at = (WINDOW_WIDTH - gauge_left - 5) / (NUMBER_OF_TICKS + 1)
  
  -- ticks
  for i = 1, NUMBER_OF_TICKS do
    WindowLine (win, gauge_left + (i * ticks_at), vertical, 
                gauge_left + (i * ticks_at), vertical + GAUGE_HEIGHT, ColourNameToRGB ("silver"), 0, 1)
  end -- for

  -- draw a box around it
  WindowRectOp (win, 1, gauge_left, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT, 
          ColourNameToRGB ("lightgrey"))  -- frame entire box
  
  -- mouse-over information: add hotspot if not there
  if not WindowHotspotInfo(win, sPrompt, 1) then
    WindowAddHotspot (win, sPrompt, gauge_left, vertical, WINDOW_WIDTH - 5, vertical + font_height, 
                  "", "", "", "", "", "", 0, 0)
  end -- if
  
  -- store numeric values in case they mouse over it
  WindowHotspotTooltip(win, sPrompt, string.format ("%st%i / %i (%i%%)", 
                        sPrompt, current, max, Fraction * 100) )
                                  
  vertical = vertical + font_height + 3
end -- function DoGauge

function do_prompt (name, line, wildcards)
  hp, max_hp = tonumber (wildcards [1]), tonumber (wildcards [2])
  mana, max_mana = tonumber (wildcards [3]), tonumber (wildcards [4])
  move, max_move = tonumber (wildcards [5]), tonumber (wildcards [6])
  if "%7" == "NL" then
   enemy, max_enemy = tonumber ("100"), tonumber ("100")
    else
   enemy, max_enemy = tonumber (wildcards [7]), tonumber ("100")   
  end -- if
  


continue....
[Go to top] top

Posted by Cybercholo   Mexico  (6 posts)  [Biography] bio
Date Reply #5 on Thu 28 Aug 2014 09:40 PM (UTC)
Message


 
  -- fill entire box to clear it
  check (WindowRectOp (win, 2, 0, 0, 0, 0, BACKGROUND_COLOUR))  -- fill entire box
  
  -- Edge around box rectangle
  check (WindowCircleOp (win, 3, 0, 0, 0, 0, BORDER_COLOUR, 0, 2, 0, 1))

  vertical = 6  -- pixel to start at tenia 6

  DoGauge ("HP: ",    hp ,   max_hp,    ColourNameToRGB "darkgreen")
  DoGauge ("Mana: ",  mana,  max_mana,  ColourNameToRGB "mediumblue")
  DoGauge ("Mov: ",  move,  max_move,  ColourNameToRGB "gold")
  DoGauge ("Enemy: ",  enemy,  max_enemy,  ColourNameToRGB "red")
  WindowShow (win, true)
  
end -- function do_prompt


function OnPluginInstall ()
  
  win = GetPluginID ()
  font_id = "fn"
  
  require "movewindow"  -- load the movewindow.lua module

  -- install the window movement handler, get back the window position
  windowinfo = movewindow.install (win, 7)  -- default to 7 (on right, center top/bottom)
                   
  font_name = "Fixedsys"    -- the font
    
  -- make miniwindow so I can grab the font info
  WindowCreate (win, 
                windowinfo.window_left,
                windowinfo.window_top,
                WINDOW_WIDTH, 
                WINDOW_HEIGHT,  
                windowinfo.window_mode,   
                windowinfo.window_flags,    
                BACKGROUND_COLOUR)

  -- add the drag handler so they can move the window around
  movewindow.add_drag_handler (win, 0, 0, 0, 0)
                 
  WindowFont (win, font_id, font_name, 9)
  font_height = WindowFontInfo (win, font_id, 1)  -- height
  
  -- work out how far in to start the gauge
  gauge_left =                        WindowTextWidth (win, font_id, "HP: ")
  gauge_left = math.max (gauge_left,  WindowTextWidth (win, font_id, "Mana: "))
  gauge_left = math.max (gauge_left,  WindowTextWidth (win, font_id, "Move: "))
  
  gauge_left = gauge_left + 10  -- allow gap from edge tenia 5 
  
  if GetVariable ("enabled") == "false" then
    ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
    check (EnablePlugin(GetPluginID (), false))
  end -- they didn't enable us last time
 
end -- OnPluginInstall

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

function OnPluginEnable ()
  WindowShow (win, true)
  
  -- draw gauge again if possible
  if hp and max_hp and mana and max_mana and move and max_move then
    do_prompt ("", "", { hp, max_hp, mana, max_mana, move, max_move } )
  end -- if know hp, endurance and guile
end -- OnPluginEnable

function OnPluginSaveState ()
   -- save window current location for next time  
  movewindow.save_state (win)
  SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
end -- OnPluginSaveState


]]>
</script>

</muclient>




This is the complete code of the trigger.

It works when in combat and the parameter "(NL)" changed to "(99%)" and displays it in the health bar with the label "Enemy"
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Thu 28 Aug 2014 11:22 PM (UTC)

Amended on Thu 28 Aug 2014 11:24 PM (UTC) by Nick Gammon

Message
I had to tweak it a bit:


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

<muclient>
<plugin
   name="Health_Bar_Miniwindow"
   author="Nick Gammon"
   id="48062dcd6b968c590df50f32"
   language="Lua"
   purpose="Shows stats in a mini window"
   date_written="2010-02-14 09:00"
   requires="4.40"
   version="2.0"
   save_state="y"
   >
<description trim="y">
<![CDATA[

La utilidad de instalar este plugin es de volver el prompt normal en una version grafica que muestre los puntos de vida, mana, movimiento, deidad y alineamiento en las famosas barras de energia.


Este plugin funcionara a partir de nivel 10, pues antes el alineamiento en el prompt sale en forma alfabetica.


Una vez que se visualize la ventana grafica, se puede reposicionar en dentro de la pantalla en donde mejor convenga. Solo hace falta poner el mouse encima, y mantener presionado el boton izquierdo del mouse y ponerla en el lugar deseado.

Esta pensado para un prompt tipo Smaug, mas especificamente para un prompt de Balzhur MUD.

El siguiente prompt es el que puede leer el codigo para poder pasarlo a modo grafico automaticamente:
prompt:
&Y<%h/%Hhp %m/%Mmana %v/%Vmov %E <%d><%a><%A><%S>>&W

Asi se veria el prompt en su pantalla: (saldra en color amarillo)

<1156/1156hp 1591/1591mana 1541/1541mov <2500><1000><HS><E>>

fprompt:
&Y<%h/%Hhp %m/%Mmana %v/%Vmov %E >&W

Asi se veria el prompt en su pantalla:
<21156/21156hp 11591/11591mana 1536/1541mov (100%) >

Antes de instalar el plugin, tendra que cambiar su prompt al que se
indica arriba.




]]>
</description>

</plugin>

<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="^&lt;(\d+)s*/(\d+)hp (\d+)/(\d+)mana (\d+)/(\d+)mov \(((\d+)%|NL)\) "
   regexp="y"
   script="do_prompt"
   sequence="100"
  >
  </trigger>
</triggers>



<!--  Script  -->


<script>
<![CDATA[

GAUGE_HEIGHT = 20

WINDOW_WIDTH = 270
WINDOW_HEIGHT = 88
NUMBER_OF_TICKS = 10

BACKGROUND_COLOUR = ColourNameToRGB "rosybrown"
FONT_COLOUR = ColourNameToRGB "darkred"
BORDER_COLOUR = ColourNameToRGB "#553333"

function DoGauge (sPrompt, current, max, Colour)

  if max <= 0 then 
    return 
  end -- no divide by zero
  
  -- fraction in range 0 to 1
  local Fraction = math.min (math.max (current / max, 0), 1) 
   
  local width = WindowTextWidth (win, font_id, sPrompt)
  
  WindowText (win, font_id, sPrompt, gauge_left - width, vertical, 0, 0, FONT_COLOUR)

  WindowRectOp (win, 2, gauge_left, vertical, WINDOW_WIDTH - 7, vertical + GAUGE_HEIGHT, -- en vez de 7, tenia 5
                          BACKGROUND_COLOUR)  -- fill entire box
  
  local gauge_width = (WINDOW_WIDTH - gauge_left - 5) * Fraction -- en vez de 7, tenia 5 
  
   -- box size must be > 0 or WindowGradient fills the whole thing 
  if math.floor (gauge_width) > 0 then
    
    -- top half
    WindowGradient (win, gauge_left, vertical, gauge_left + gauge_width, vertical + GAUGE_HEIGHT / 2, 
                    0x000000,
                    Colour, 2) 
    
    -- bottom half
    WindowGradient (win, gauge_left, vertical + GAUGE_HEIGHT / 2, 
                    gauge_left + gauge_width, vertical +  GAUGE_HEIGHT,   
                    Colour,
                    0x000000,
                    2) 

  end -- non-zero
  
  -- show ticks
  local ticks_at = (WINDOW_WIDTH - gauge_left - 5) / (NUMBER_OF_TICKS + 1)
  
  -- ticks
  for i = 1, NUMBER_OF_TICKS do
    WindowLine (win, gauge_left + (i * ticks_at), vertical, 
                gauge_left + (i * ticks_at), vertical + GAUGE_HEIGHT, ColourNameToRGB ("silver"), 0, 1)
  end -- for

  -- draw a box around it
  WindowRectOp (win, 1, gauge_left, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT, 
          ColourNameToRGB ("lightgrey"))  -- frame entire box
  
  -- mouse-over information: add hotspot if not there
  if not WindowHotspotInfo(win, sPrompt, 1) then
    WindowAddHotspot (win, sPrompt, gauge_left, vertical, WINDOW_WIDTH - 5, vertical + font_height, 
                  "", "", "", "", "", "", 0, 0)
  end -- if
  
  -- store numeric values in case they mouse over it
  WindowHotspotTooltip(win, sPrompt, string.format ("%st%i / %i (%i%%)", 
                        sPrompt, current, max, Fraction * 100) )
                                  
  vertical = vertical + font_height + 3
end -- function DoGauge

function do_prompt (name, line, wildcards)
  hp, max_hp = tonumber (wildcards [1]), tonumber (wildcards [2])
  mana, max_mana = tonumber (wildcards [3]), tonumber (wildcards [4])
  move, max_move = tonumber (wildcards [5]), tonumber (wildcards [6])
  if wildcards [7] == "NL" then
   enemy, max_enemy = 100, 100
    else
   enemy, max_enemy = tonumber (wildcards [8]), 100 
  end -- if
  

 
  -- fill entire box to clear it
  check (WindowRectOp (win, 2, 0, 0, 0, 0, BACKGROUND_COLOUR))  -- fill entire box
  
  -- Edge around box rectangle
  check (WindowCircleOp (win, 3, 0, 0, 0, 0, BORDER_COLOUR, 0, 2, 0, 1))

  vertical = 6  -- pixel to start at tenia 6

  DoGauge ("HP: ",    hp ,   max_hp,    ColourNameToRGB "darkgreen")
  DoGauge ("Mana: ",  mana,  max_mana,  ColourNameToRGB "mediumblue")
  DoGauge ("Mov: ",  move,  max_move,  ColourNameToRGB "gold")
  DoGauge ("Enemy: ",  enemy,  max_enemy,  ColourNameToRGB "red")
  WindowShow (win, true)
  
end -- function do_prompt


function OnPluginInstall ()
  
  win = GetPluginID ()
  font_id = "fn"
  
  require "movewindow"  -- load the movewindow.lua module

  -- install the window movement handler, get back the window position
  windowinfo = movewindow.install (win, 7)  -- default to 7 (on right, center top/bottom)
                   
  font_name = "Fixedsys"    -- the font
    
  -- make miniwindow so I can grab the font info
  WindowCreate (win, 
                windowinfo.window_left,
                windowinfo.window_top,
                WINDOW_WIDTH, 
                WINDOW_HEIGHT,  
                windowinfo.window_mode,   
                windowinfo.window_flags,    
                BACKGROUND_COLOUR)

  -- add the drag handler so they can move the window around
  movewindow.add_drag_handler (win, 0, 0, 0, 0)
                 
  WindowFont (win, font_id, font_name, 9)
  font_height = WindowFontInfo (win, font_id, 1)  -- height
  
  -- work out how far in to start the gauge
  gauge_left =                        WindowTextWidth (win, font_id, "HP: ")
  gauge_left = math.max (gauge_left,  WindowTextWidth (win, font_id, "Mana: "))
  gauge_left = math.max (gauge_left,  WindowTextWidth (win, font_id, "Move: "))
  
  gauge_left = gauge_left + 10  -- allow gap from edge tenia 5 
  
  if GetVariable ("enabled") == "false" then
    ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
    check (EnablePlugin(GetPluginID (), false))
  end -- they didn't enable us last time
 
end -- OnPluginInstall

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

function OnPluginEnable ()
  WindowShow (win, true)
  
  -- draw gauge again if possible
  if hp and max_hp and mana and max_mana and move and max_move then
    do_prompt ("", "", { hp, max_hp, mana, max_mana, move, max_move } )
  end -- if know hp, endurance and guile
end -- OnPluginEnable

function OnPluginSaveState ()
   -- save window current location for next time  
  movewindow.save_state (win)
  SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
end -- OnPluginSaveState


]]>
</script>

</muclient>


First, your trigger was never going to match "NL" because you were checking for digits. Second, you still had %7 inside the code.

The trigger has been changed to:


^<(\d+)s*/(\d+)hp (\d+)/(\d+)mana (\d+)/(\d+)mov \(((\d+)%|NL)\) 


Note the explicit test for NL. This pushes the percentage up to wildcard 8, where wildcard 7 is now either (say) "95%" or "NL".

Thus the code to handle that is now:


  if wildcards [7] == "NL" then
   enemy, max_enemy = 100, 100
    else
   enemy, max_enemy = tonumber (wildcards [8]), 100 
  end -- if


Note that you don't need to do this:


   enemy, max_enemy = tonumber ("100"), tonumber ("100")


You want numbers, right? So use them:


   enemy, max_enemy = 100, 100

- Nick Gammon

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

Posted by Cybercholo   Mexico  (6 posts)  [Biography] bio
Date Reply #7 on Fri 29 Aug 2014 12:18 AM (UTC)
Message
Now works perfectly !!
my knowledge of programming are few and realized I had not comparing letters with numbers, thanks for teaching me xD

En español...

Funciona perfectamente, se agradece que me hayas dado a entender mis errores con tanta paciencia, ahora ya entiendo un poco mas xD

Sos la leche nick xD (something like you are god xD)
[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.


4,273 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 FutureQuest]