Line capture to guage for Mudlet?

Hello! I think I'll just jump straight in to my issue. This can be resolved here, or private messages.. Also feel free to send me an OOC message or tell if you can help in game? I'm trying to make myself a little mini Mudlet system, just general stuff for bashing and influencing, not PVP combat (yet?) and I'm working on a health/mana/ego/etcetera bar.

So far I've made the gauge, set it up in the location I want, set up the colours, and I've made it show a custom text. BUT, I would like for it to echo each prompt into the respective gauge, for example- if I have 4309h I would like for it to capture that and echo it onto the gauge instead of on the screen, then it's simply a matter of deleting the line and having it only show in my bars at the bottom of my screen.

How would I do that? Is a gauge even the way I should be going, or should I have made a window or table instead? Anyone with extensive Mudlet knowledge, please help...

So far I have:

createGauge("healthBar", 100, 20, 0, 600, nil, "red")

setGauge("healthBar", 200, 200, "HEALTH")

Where 'HEALTH' would most obviously be the captured text.

Best Answer

  • edited April 2017 Accepted Answer
    I will begin by admitting that I have never used gauges in Mudlet, but I'll assume that your code for creating and setting is fine.

    You don't need a capture for this, every line the game sends a packet of information known as 'GMCP'.

    Your health is reported in string format in GMCP under gmcp.Char.Vitals.hp, along with gmcp.Char.Vitals.maxhp which is handy because you won't need to store either of them as variables for producing your health% to be displayed in the gauge. 

    This is how I'd do it:
    setGauge("healthBar", tonumber(gmcp.Char.Vitals.hp)/tonumber(gmcp.Char.Vitals.maxhp) *200, 200, "Health")

    Where the above function is called every prompt (or, if you're fancy, an event where something internal changes).

    tonumber(gmcp.Char.Vitals.hp)/tonumber(gmcp.Char.Vitals.maxhp) - tonumber(x) isn't probably required because lua is pretty good at being flexible but I generally prefer to be explicit. This number is the fraction of current health to maximum health, which will always be a number between 0 - 1 unless you're overhealed. When the number between 0 - 1 is multiplied by the full length you get the respective width of bar for your current % health. 

    Edit: Extend:
    When you're overhealed, however, you'll notice that your bar is longer than 200px. There are some fancy things you can do like running a second gauge backwards or superimposed over the top. or changing the colour and using the excess as the complete gauge. You could simply restrict the fraction under math.max(hp/maxhp, 1) but I'll leave how you decide to handle that to yourself.

    Also, I haven't tested this, I'm just assuming it'll work.

    I may have misunderstood your qestion. If you wish to show the number in black text over the red, you can just use 

    setGauge("healthBar", 200, 200, gmcp.Char.Vitals.hp)

    But I would have used a text window for that. 
    (I'm the mom of Hallifax btw, so if you are in Hallifax please call me mom.)

    == Professional Girl Gamer == 
    Yes I play games
    Yes I'm a girl
    get over it


  • Update: I have (\d+)h saved as health_bar in my triggers. I think I just have to remember how to get health_bar to put itself into the script.
  • I'd be careful about updating a gauge as often as every gmcp character vitals event. Might want to put some sort of cooldown timer on it. Of course, if you don't notice any side-effect to doing it this way, all good. Depending on your hardware, though, it may very well cause severe lag.
    Discord: Pharanyx#4357
  • Thank you, everyone!
Sign In or Register to comment.