Modifying statistics bar by Magnus Lundborg

Posted by Haj on Sun 28 Apr 2013 07:39 AM — 1 posts, 8,640 views.

#0
Hi, I tried messing around with this and I could not figure it out using the following URL http://www.lua.org/pil/20.2.html. I am by no means any good at writing plugins and would appreciate some help. I am trying to modify the code below to now trigger off of this HP: 1548 (1548) GP: 255 (345) XP: 154831 A: evil B: 37%



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient [
  <!ENTITY trigger_match 
   "(?:> |)Hp: (\d+) ?\((\d+)\) +(?:Gp: (\d+) ?\((\d+)\)) +(?:Xp: (\d+))$"> 
]>   
<!-- Saved on Monday, April 28, 2003, 9:53 AM -->
<!-- MuClient version 3.41 -->

<!-- Based on the Plugin "Health_Bar" (by Nick Gammon) generated by Plugin Wizard -->
<!-- Rewritten in LUA by Beale (Ian Kirker) -->
<!-- Modified by Sciante (Magnus Lundborg) to show xp and time statistics -->
<!-- and to work properly using wine in Linux (sorry that the bars had to go) -->
<!-- Slightly inspired by the Timer plugin by Nick Gammon -->
<!-- This version uses a slightly smaller bar to fit on most screens -->
<!-- Sux2b VBScript. -->


<!--
You will probably need to customise the trigger to match your MUD.

See ENTITY line near top of file. The above trigger will match on:

  Hp: x (X) Gp: y (Y) Xp: z

where x, X, y, Y and z are numerical values.
-->

<muclient>
<plugin
   name="Statistics_Bar"
   author="Magnus Lundborg"
   id="a2af5216d68563401888e01e"
   language="Lua"
   purpose="Shows HP, GP, XP as well as using a timer to calculate xp gain"
   date_written="2003-04-28 09:50:05"
   date_modified="2005-05-05 16:00"
   requires="3.49"
   version="1.2"
   >
<description trim="y">
<![CDATA[
Install this plugin to show an info bar with HP, GP, 
and Experience points. You also get information about xp gain over
a given time period, which can be reset by typing "resettimer".

You need your score line to display the appropriate information,
naturally.

Customise the plugin if you want to match a different sort of score line.

To see this message, type: Statistics_Bar:help

]]>
</description>

</plugin>


<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="&trigger_match;"
   name="InfoBar"
   regexp="y"
   script="DoPrompt"
   sequence="100"
  >
  </trigger>
</triggers>


<!--  Aliases  -->

<aliases>
  <alias
   script="TimerToZero"
   match="resettimer"
   enabled="y"
   sequence="100"
  >
  </alias>
</aliases>



<!--  Script  -->


<script>
<![CDATA[

local time=0
local basexp
local xp
local mins

--
--  Called by alias to zero timer
--
function TimerToZero (sName, sLine, wildcards)
	time = 0
	world.InfoClear()
	world.Info("Timer and xp counter reset. Restarted on next score output.")
end


function DoPrompt(sName, sLine, wildcards)

	local xpdiff
	local timediff
	local str

	xp=wildcards[5]

	if time==0 then
		time = world.GetConnectDuration()
		basexp=xp
	end


	xpdiff=xp-basexp

	timediff = (world.GetConnectDuration()) - time

	mins=(timediff/60)
	mins=math.floor(mins*10+0.5)/10

	--This is the font used in the text.
	sFont="Arial"
	
	--Clear the Infobar.
	world.InfoClear()
	
	world.Info("HP: " .. wildcards[1] .. " \(" .. wildcards[2] .. "\) ")
	world.Info("  GP: " .. wildcards[3] .. " \(" .. wildcards[4] .. "\) ")
	world.InfoFont(sFont, 11, 1)	
	world.Info("  XP: " .. xp)
	world.Info("      " .. xpdiff .. " xp in " .. mins .. " minutes")
	world.Info("      Av. xp/hour: " .. (math.floor ((xpdiff/(timediff/3600))*10+0.5))/10)
	world.Info("        \"resettimer\" resets the time and xp counter")
	
end

--
--  Do this once
--
world.ShowInfoBar(1)



]]>
</script>

</muclient>