Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Plugins ➜ Health and Experience and Bars, oh my!

Health and Experience and Bars, oh my!

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


Pages: 1  2  3 4  

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #30 on Mon 28 Feb 2011 05:45 AM (UTC)

Amended on Mon 28 Feb 2011 05:52 AM (UTC) by Nick Gammon

Message
Caelen said:

in config.lua

CHARACTER_NAME = GetInfo(3)
if CHARACTER_NAME then
SetTriggerOption("hpall", "match", "^" .. GetInfo(3) .. " Reports\: HP\:(\d+)\% SP\:(\d+)\% EP\:(\d+)\%$")
end

Would this work?


Why not do this?


CHARACTER_NAME = GetInfo(3)
if CHARACTER_NAME then
  SetTriggerOption("hpall", "match", "^" .. CHARACTER_NAME .. " Reports\: HP\:(\d+)\%  SP\:(\d+)\%  EP\:(\d+)\%$")
end


But more to the point, triggers can incorporate variables. So just make it:


SetVariable ("my_character", GetAlphaOption ("player"))

SetTriggerOption("hpall", "match", "^@my_character Reports\: HP\:(\d+)\%  SP\:(\d+)\%  EP\:(\d+)\%$")


Make sure "expand variables" is on. Of course, you don't need to do the SetTriggerOption now, because that part won't change. Just incorporate the variable into the original trigger.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #31 on Mon 28 Feb 2011 05:55 AM (UTC)
Message
Nick Gammon said:

SetVariable ("my_character", GetAlphaOption ("player"))

SetTriggerOption("hpall", "match", "^@my_character Reports\: HP\:(\d+)\%  SP\:(\d+)\%  EP\:(\d+)\%$")


Forewarning: the @variable tokens are evaluated BEFORE any code is run, so if you have the below script, it won't do what you expect:

-- assume 'foo' contains "11" right now

SetVariable("foo", "42")
Note("@foo") -- shows 11, not 42!

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #32 on Mon 28 Feb 2011 06:05 AM (UTC)
Message
Absolutely, but his character name won't change from minute to minute, will it?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #33 on Mon 28 Feb 2011 06:22 AM (UTC)
Message
Not at all. It was just in the same [code] block and I wanted to make sure nobody got the wrong idea.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Caelen   (81 posts)  Bio
Date Reply #34 on Mon 28 Feb 2011 08:44 AM (UTC)
Message
Didn't know I could use variables in the trigger matches like that! Awesome. Let me finish retesting those, and I'll post a link to the file.

Any idea why the first trigger was always returning a value of 100% though?
Top

Posted by Caelen   (81 posts)  Bio
Date Reply #35 on Mon 28 Feb 2011 09:02 AM (UTC)

Amended on Mon 28 Feb 2011 09:04 AM (UTC) by Caelen

Message
http://www.mediafire.com/?7enc168d682e6kc

Everything is working except for two things. Transparency, and the "do_prompt_percent" function.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #36 on Mon 28 Feb 2011 11:00 AM (UTC)

Amended on Mon 28 Feb 2011 11:01 AM (UTC) by Twisol

Message
Can you explain what you mean by "returning" please? As I understand the term, it means "the value returned by a function", as in the imaginary function 'add(2, 2)' returns 4. A trigger doesn't return anything in particular, unless you're talking about the wildcard parameters (which would be matches) or the displayed value of the health bar (which is just output).

Sorry to get pedantic, but it's hard to reproduce the problem if I don't know what I should be looking at. :)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Caelen   (81 posts)  Bio
Date Reply #37 on Mon 28 Feb 2011 06:50 PM (UTC)
Message
Ah, sorry. I mean the "function DoGauge" always draws the bars at 100% full when the two triggers in question match. I tested the triggers using "print", and they are grabbing the correct numbers in both cases. The problem is either in function DoGauge or function do_prompt_percent.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #38 on Mon 28 Feb 2011 11:48 PM (UTC)
Message
Nitpick, but this is unnecessary:
  if current > max then
     current = max
  end -- cannot have more than max

  if current < 0 then
     current = 0
  end -- cannot have less than zero
  
  -- fraction in range 0 to 1
  local Fraction = math.min (math.max (current / max, 0), 1) 

By locking current between 0 and max, you're already ensuring that Fraction is between 0 and 1 (as 0/max is 0 and max//max is 1). I'd prefer just to forgo the if-checks because the math.min and math.max do it neatly in one line.
local Fraction = math.min (math.max (current / max, 0), 1)


Secondly, you're passing 'current' and 'max' in to DoGauge so it can figure out how much of the gauge should be filled, but you already -have- that in the percentage. Just (hpp / 100) gives you the fraction of the gauge that needs filling.


I can't actually run the plugin currently, but I don't see any actual bugs, so I'm probably missing something.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Caelen   (81 posts)  Bio
Date Reply #39 on Tue 01 Mar 2011 12:30 AM (UTC)
Message
Twisol said:

local Fraction = math.min (math.max (current / max, 0), 1)



Cleaned up :D Thanks.

Twisol said:

Secondly, you're passing 'current' and 'max' in to DoGauge so it can figure out how much of the gauge should be filled, but you already -have- that in the percentage. Just (hpp / 100) gives you the fraction of the gauge that needs filling.


What I'm trying to do is get do_prompt_percent to send the current and max values so that the mouseover hotspot will display the correct (or at least somewhat close) information when only supplied with the percentage. The math looks fine to me... but I just don't see why it isn't sending the correct info.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #40 on Tue 01 Mar 2011 12:49 AM (UTC)
Message
I always find it helps to put in debugging print statements. Perhaps the values are 100 times what you expect, or one is missing, or something?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #41 on Tue 01 Mar 2011 01:30 AM (UTC)
Message
Caelen said:

What I'm trying to do is get do_prompt_percent to send the current and max values so that the mouseover hotspot will display the correct (or at least somewhat close) information when only supplied with the percentage. The math looks fine to me... but I just don't see why it isn't sending the correct info.

Oh, I see. I must've skipped over that part.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Caelen   (81 posts)  Bio
Date Reply #42 on Tue 01 Mar 2011 02:49 AM (UTC)

Amended on Tue 01 Mar 2011 03:23 AM (UTC) by Caelen

Message
Nick Gammon said:

I always find it helps to put in debugging print statements. Perhaps the values are 100 times what you expect, or one is missing, or something?


Results of the printing: (printed added before what was printed)
hp
HP:306/306  SP:238/238  EP:111/155
printed HP: 306/306 current/max
printed SP: 238/238 current/max
printed EP: 111/155 current/max
> 
hpp
HP:100%  SP:100%  EP:71%
printed HP:306/306%100
printed SP:238/238%100
printed EP:155/155%71
printed HP: 306/306 current/max
printed SP: 238/238 current/max
printed EP: 155/155 current/max


Modifications to DoGauge:
  print (sPrompt .. current .. "/" .. max .. " current/max")


Modifications to do_prompt_percent:
  print ("HP:" .. hp .. "/" .. max_hp .. "%" .. hpp)
  print ("SP:" .. sp .. "/" .. max_sp .. "%" .. spp)
  print ("EP:" .. ep .. "/" .. max_ep .. "%" .. epp)


So, do_prompt_percent is the problem... it's catching the right value for the percentage (71), but it's not doing the math right.

function do_prompt_percent (name, line, wildcards)

  hpp = tonumber (wildcards [1])
  spp = tonumber (wildcards [2])
  epp = tonumber (wildcards [3])
  hp = max_hp * ( hpp / 100 )
  sp = max_sp * ( spp / 100 )
  ep = max_ep * ( spp / 100 )
  print ("HP:" .. hp .. "/" .. max_hp .. "%" .. hpp)
  print ("SP:" .. sp .. "/" .. max_sp .. "%" .. spp)
  print ("EP:" .. ep .. "/" .. max_ep .. "%" .. epp)

  draw_the_bars ()
      
end -- do_prompt_percent


Ideas?

EDIT: changed that middle part to
  hp = math.floor(max_hp * (hpp / 100))
  sp = math.floor(max_sp * (spp / 100))
  ep = math.floor(max_ep * (spp / 100))


Doesn't change the results, but I don't want any decimal values gumming it up.

EDIT2: I have decided to, for now, scrap the idea of making the background transparent. It would be nice, but without the background it would get quite messy as text appeared beneath the gauges. Plus, I can't do the blend thing, which seems to be what people were wanting actually XD
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #43 on Tue 01 Mar 2011 06:23 AM (UTC)
Message
Well, I just installed the plugin and ran this small script:
Simulate("HP:100/500  SP:100/400  EP:100/300\r\n")

The gauges seem to work just fine. Can you paste a few actual examples of that hp/sp/ep line? My hunch is that, for some reason, the max_* variables are always less than the current values, so you're always drawing the gauges at 100%. It all works for me, so the only thing left is the data coming in via the trigger.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Caelen   (81 posts)  Bio
Date Reply #44 on Tue 01 Mar 2011 06:32 AM (UTC)

Amended on Tue 01 Mar 2011 06:41 AM (UTC) by Caelen

Message
I'm not sure what you're asking for... what I pasted above included the command (hp and hpp respectively), the output from the game (the line with HP quantity and HP %), and then what was printed by the debugg scripts.

What you've simulated there is actually the match for the one trigger that -does- work. I've tested the three triggers, and all three return the proper wildcard values. The third trigger catches the command "hpall", and the mud gives the "Verren Reports: %%%" line (the match I'm using the variable for now).

It's the % ones that are returning incorrect values for current, but the max values are always correct.


hp -- command
HP:306/306  SP:238/238  EP:111/155 -- mud output
HP: 306/306 current/max -- printed by DoGauge called by do_prompt_max
SP: 238/238 current/max -- printed by DoGauge called by do_prompt_max
EP: 111/155 current/max -- printed by DoGauge called by do_prompt_max

hpp -- command
HP:100%  SP:100%  EP:71% -- mud output
HP:306/306%100 -- printed by do_prompt_percent
SP:238/238%100 -- printed by do_prompt_percent
EP:155/155%71 -- printed by do_prompt_percent
HP: 306/306 current/max -- printed by DoGauge called by do_prompt_percent
SP: 238/238 current/max -- printed by DoGauge called by do_prompt_percent
EP: 155/155 current/max -- printed by DoGauge called by do_prompt_percent


Note that EP is the only one that was not at max.
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.


128,632 views.

This is page 3, subject is 4 pages long:  [Previous page]  1  2  3 4  [Next page]

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

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.