用mudlet的Geyser.Gauge功能制作北大侠客行的图形化血条

初学mudlet,在北大侠客行中用Geyser.Gauge功能编了个简单的血条脚本。血条效果如下:

file

脚本由三部分组成,一是Script,二是trigger,三是Timer,细节如下:

一、脚本script部分,以下内容复制后放在Script的lua code处。

GUI = GUI or {}
setBorderBottom(200)
--<创建HP框架>
bottom_Frame =
  Geyser.Container:new({name = "left_Frame", x = "0%", y = "-9%", width = "55%", height = "9%"})
--<创建HP状态条HBox>
GUI.footer =
  Geyser.HBox:new(
    {name = "Gauge.footer1", x = "0%", y = "0%", width = "100%", height = "99%"}, bottom_Frame
  )
GUI.column1 = Geyser.VBox:new({name = "Gauge.column1"}, GUI.footer)
GUI.column2 = Geyser.VBox:new({name = "Gauge.column2"}, GUI.footer)
--column3 = Geyser.VBox:new({name = "Gauge.column3",h_stretch_factor=0.2},GUI.footer1)
--<创建精神gauge状态条>create an gauge
GUI.jsbar = Geyser.Gauge:new({name = "GUI.jsbar"}, GUI.column1)
GUI.jsbar.front:setStyleSheet(
  [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #00ff00, stop: 0.1 #00e800, stop: 0.49 #009800, stop: 0.5 #007d00, stop: 1 #00d100);
    border-top: 1px black solid;
    border-left: 1px black solid;
    border-bottom: 1px black solid;
    border-radius: 7;
    padding: 3px;]]
)
GUI.jsbar.back:setStyleSheet(
  [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #009000, stop: 0.1 #007400, stop: 0.49 #005900, stop: 0.5 #003d00, stop: 1 #009d00);
    border-width: 1px;
    border-color: black;
    border-style: solid;
    border-radius: 7;
    padding: 3px;]]
)
--<创建气血gauge状态条>create an gauge
GUI.qxbar = Geyser.Gauge:new({name = "GUI.qxbar"}, GUI.column1)
GUI.qxbar.front:setStyleSheet(
  [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #fe0000, stop: 0.1 #ee0000, stop: 0.49 #a80000, stop: 0.5 #360000, stop: 1 #ce0000);
    border-top: 1px black solid;
    border-left: 1px black solid;
    border-bottom: 1px black solid;
    border-radius: 7;
    padding: 3px;]]
)
GUI.qxbar.back:setStyleSheet(
  [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #840000, stop: 0.1 #750000, stop: 0.49 #440000, stop: 0.5 #380000, stop: 1 #980000);
    border-width: 1px;
    border-color: black;
    border-style: solid;
    border-radius: 7;
    padding: 3px;]]
)
--<创建食物gauge状态条>create an gauge
GUI.foodbar = Geyser.Gauge:new({name = "GUI.foodbar"}, GUI.column1)
GUI.foodbar.front:setStyleSheet(
  [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #ffd452, stop: 0.1 #eec64c, stop: 0.49 #947b2f, stop: 0.5 #746025, stop: 1 #eec64c);
    border-top: 1px black solid;
    border-left: 1px black solid;
    border-bottom: 1px black solid;
    border-radius: 7;
    padding: 3px;]]
)
GUI.foodbar.back:setStyleSheet(
  [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #91782e, stop: 0.1 #87702b, stop: 0.49 #56471b, stop: 0.5 #4d4018, stop: 1 #7c6728);
    border-width: 1px;
    border-color: black;
    border-style: solid;
    border-radius: 7;
    padding: 3px;]]
)
--<创建精力gauge状态条>create an gauge
GUI.jlbar = Geyser.Gauge:new({name = "GUI.jlbar"}, GUI.column2)
GUI.jlbar.front:setStyleSheet(
  [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #eeee00, stop: 0.1 #e3e300, stop: 0.49 #abab00, stop: 0.5 #3e3e00, stop: 1 #ebeb00);
    border-top: 1px black solid;
    border-left: 1px black solid;
    border-bottom: 1px black solid;
    border-radius: 7;
    padding: 3px;]]
)
GUI.jlbar.back:setStyleSheet(
  [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e5ad29, stop: 0.1 #d6a226, stop: 0.49 #a57c1d, stop: 0.5 #96711b, stop: 1 #614911);
    border-width: 1px;
    border-color: black;
    border-style: solid;
    border-radius: 7;
    padding: 3px;]]
)
--<创建内力gauge状态条>create an gauge
GUI.nlbar = Geyser.Gauge:new({name = "GUI.nlbar"}, GUI.column2)
GUI.nlbar.front:setStyleSheet(
  [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #50f1f1, stop: 0.1 #4adfdf, stop: 0.49 #005f5f, stop: 0.5 #004343, stop: 1 #45d1d1);
    border-top: 1px black solid;
    border-left: 1px black solid;
    border-bottom: 1px black solid;
    border-radius: 7;
    padding: 3px;]]
)
GUI.nlbar.back:setStyleSheet(
  [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #4285c7, stop: 0.1 #3a75b0, stop: 0.49 #264d74, stop: 0.5 #1f3f5f, stop: 1 #376ea5);
    border-width: 1px;
    border-color: black;
    border-style: solid;
    border-radius: 7;
    padding: 3px;]]
)
--<创建饮水gauge状态条>create an gauge
GUI.waterbar = Geyser.Gauge:new({name = "menu.GUI.waterbar"}, GUI.column2)
GUI.waterbar.front:setStyleSheet(
  [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #aaffff, stop: 0.1 #99e5e5, stop: 0.49 #5c8a8a, stop: 0.5 #486c6c, stop: 1 #87caca);
    border-top: 1px black solid;
    border-left: 1px black solid;
    border-bottom: 1px black solid;
    border-radius: 7;
    padding: 3px;]]
)
GUI.waterbar.back:setStyleSheet(
  [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #72abab, stop: 0.1 #699d9d, stop: 0.49 #517a7a, stop: 0.5 #446666, stop: 1 #79b6b6);
    border-width: 1px;
    border-color: black;
    border-style: solid;
    border-radius: 7;
    padding: 3px;]]
)

function onGaugeHP()
  GUI.jsbar:setValue(jsCur, jsMax, "<b>" .. jsCur .. "/" .. jsMax .. "精神</b>")
  GUI.jsbar.text:setToolTip("js", "10")
  GUI.qxbar:setValue(qxCur, qxMax, "<b>" .. qxCur .. "/" .. qxMax .. "气血</b>")
  GUI.qxbar.text:setToolTip("qx", "10")
  GUI.foodbar:setValue(foodCur_cut, foodMax, "<b>" .. foodCur .. "/" .. foodMax .. "食物</b>")
  GUI.foodbar.text:setToolTip("food", "10")
  GUI.jlbar:setValue(jlCur_cut, jlMax, "<b>" .. jlCur .. "/" .. jlMax .. "精力</b>")
  GUI.jlbar.text:setToolTip("jl", "10")
  GUI.nlbar:setValue(nlCur_cut, nlMax, "<b>" .. nlCur .. "/" .. nlMax .. "内力</b>")
  GUI.nlbar.text:setToolTip("nl", "10")
  GUI.waterbar:setValue(
    waterCur_cut, waterMax, "<b>" .. waterCur .. "/" .. waterMax .. "饮水</b>"
  )
  GUI.waterbar.text:setToolTip("water", "10")
end
registerAnonymousEventHandler("myHP", "onGaugeHP")

这是script的部分截图 file

二、触发器trigger(1)和trigger(2)

trigger(1)是在侠客行mud命令行输入“hpbrief”后,服务器端返回输出精力、精神、内力、气血、食物、饮水等一系列数值,trigger(1)通过正则表达式进行抓取.

trigger(1)用mudlet的多行截取功能进行正则判断,三行中间要用line spacer隔开一行,同时要勾选And Multi-line (delta),下面选触发覆盖5行,详见截图

#(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)
#(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)
#\d+,\d+,(\d+),(\d+),\d+,\d+

trigger截图: file

以下内容复制后放在trigger(1)的lua code处

jsCur = tonumber(multimatches[3][7])

jsMax = tonumber(multimatches[3][5])

qxCur = tonumber(multimatches[3][4])

qxMax = tonumber(multimatches[3][2])

foodCur = tonumber(multimatches[5][2])

foodMax = tonumber(300)

jlCur = tonumber(multimatches[1][7])

jlMax = tonumber(multimatches[1][6])

nlCur = tonumber(multimatches[1][5])

nlMax = tonumber(multimatches[1][4])

waterCur = tonumber(multimatches[5][3])

waterMax = tonumber(300)

if jlCur > jlMax then
  jlCur_cut = jlMax
else
  jlCur_cut = jlCur
end

if nlCur > nlMax then
  nlCur_cut = nlMax
else
  nlCur_cut = nlCur
end

if foodCur > foodMax then
  foodCur_cut = foodMax
else
  foodCur_cut = foodCur
end

if waterCur > waterMax then
  waterCur_cut = waterMax
else
  waterCur_cut = waterCur
end

raiseEvent("myHP") --事件系统调用script的gauge血条框架

trigger(2)的正则判断

^你的客户端支持MXP

以下内容复制后放在trigger(2)的lua code处

logon = "on"
enableTimer("hpbrief")
send("hpbrief;fullme;set wimpy 30;i;score",false)

trigger(2)的截图 file

三、时钟Timer部分

这里设定的是mudlet每2秒钟向服务器发送一次“hpbrief”,以获取游戏角色的血条数据

以下内容复制后放在timer的lua code处


if logon == "on" then  --这里加判断句是为了避免在登录时被系统误认为密码输入,
  send("hpbrief", false)
end

以下是timer的截图 file

第一次用mudlet,文科生,没有写代码经验,全是在本站看贴子,和在wiki.mudlet.org上看官方手册学的一点点皮毛,内容可能有很多错误,欢迎大家斧正。

另外,编写血条颜色过渡代码用的是按mudlet官方推荐的QT Designer工具,用这个工具,颜色大家可以自已修改。 file

修改过渡颜色主要是改script中的相关数字。

每个血条有两层,front和back,重点是要改front层的颜色,底层的用比front深一些的颜色就可以。 以下面代码为例

background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #00ff00, stop: 0.1 #00e800, stop: 0.49 #009800, stop: 0.5 #007d00, stop: 1 #00d100);

以“精神”的状态条为例:

  • stop:0 #00ff00 浅绿
  • stop:0.1 #00e800 浅绿
  • stop:0.49 #009800 墨绿
  • stop:0.5 #007d00 深绿
  • stop: 1 #00d100 浅绿

六位颜色代码代码都可以修改,可在QT Designer随意挑选,只要是两头浅,中间深,这样渐变的过渡效果就产生了。

在这里抛砖引玉,请各位行家帮我优化,共同交流,祝各位好运!

京ICP备13031296号-4