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="^<(\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 | Top |
|