[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUDs
. -> [Folder]  General
. . -> [Subject]  Using Health_Bar_Miniwindow_Telnet and others.
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Using Health_Bar_Miniwindow_Telnet and others.

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


Pages: 1 2  

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Sun 07 Feb 2010 01:48 AM (UTC)
Message
I'm looking to figure how to show a groups hp/mana bar as well as the victim you're fighting.

So in WoW terms, when you add a member to your group then a box will pop up with his health and mana. Then whenever I'm fighting, a health/mana bar will pop up when we are engaged.

After looking through the Health_Bar_Miniwindow_Telnet part I didnt' really see where it was sending ch's input rather then the victims input. Is this something done in the src files first and then in a plugin?

Is there a direction I need to go in? I am running a smaug code with your diff changes and everything is working so far (the health, room desc, and exp bar).
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #1 on Sun 07 Feb 2010 02:19 AM (UTC)
Message
So I'm guessing here:


function OnPluginTelnetOption (option)

  local t = {}  -- incoming server variables will go into table t
  setfenv (assert (loadstring (option)), t) () -- compile and load into t
  
  if t.tt ~= "status" then
    return
  end
   
  -- require "tprint"
  -- tprint (t)
  
  local background_colour = ColourNameToRGB "lightgreen"
  if t.dead then
    background_colour = ColourNameToRGB "mistyrose"
  elseif t.combat then 
    background_colour = ColourNameToRGB "rosybrown"
  end -- if
  
  -- fill entire box to clear it
  WindowRectOp (win, 2, 0, 0, 0, 0, background_colour)  -- fill entire box

  -- a green inside border indicates you are poisoned
  if t.poisoned then
    WindowCircleOp(win, 2,         -- draw rectangle
                   0, 0, 0, 0,     -- entire window
                   ColourNameToRGB "olivedrab", 6, 4, -- pen, inside border, width 4
                   0, 1)  -- no brush
  end -- if
    
  -- Edge around box rectangle
  WindowCircleOp (win, 3, 0, 0, 0, 0, ColourNameToRGB "darkgray", 0, 2, 0, 1)

  -- stats don't really matter if you are dead
  if t.dead then
    local dead_message = "<You are dead>"
    local width = WindowTextWidth (win, FONT_ID, dead_message)
    local left = (WINDOW_WIDTH - width) / 2
    local top = (window_height - font_height) / 2
    WindowText (win, FONT_ID, dead_message, left, top, 0, 0, ColourNameToRGB "darkred")
  else
    vertical = 6  -- pixel to start at
  
    DoGauge ("HP: ",   t.hp,    t.maxhp,    ColourNameToRGB "darkgreen")
    DoGauge ("Mana: ", t.mana,  t.maxmana,  ColourNameToRGB "mediumblue")
    DoGauge ("Move: ", t.move,  t.maxmove,  ColourNameToRGB "gold")
  end -- if


Is where we are getting OUR hp/mana/move. How do I get t.hp to show the victim.hp?

After going over your posts again in the other topic I figure I don't change much in code since it has the show_status finding who the victim is, just need to figure out how to get the hp=%d for victim rather then my char.

I'll continue to look into this, any help or direction would be great.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 07 Feb 2010 02:26 AM (UTC)
Message
For the victim part, if you look at the data being sent during a fight from page 1 of the other thread:


"victim":
  "level"=1
  "maxhp"=11
  "name"="the kobold"
  "hp"=11
"move"=110
"poisoned"=false
"mana"=94
"maxhp"=43
"hp"=40
"tt"="status"
"combat"=true
"level"=2
"maxxp"=7084
"gold"=900
"xp"=2116
"maxmove"=110
"maxmana"=94
"dead"=false


Your HP is t.hp, but the victim's HP is t.victim.hp, and his max HP is t.victim.maxhp.

(The victim table might be empty or nil if not in a fight).

As for the group stuff, I know what you mean. You would probably need to find the group list (at the server end) and then add extra table items for each group member. Conceptually it would be similar to sending the stuff for the victim, but you would need to allow for more than one of them.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #3 on Sun 07 Feb 2010 03:16 AM (UTC)
Message
Here's what I have so far:


  if t.combat then
    vertical = 6  -- pixel to start at
  
    DoGauge (t.victim.name,   t.victim.hp,    t.victim.maxhp,    ColourNameToRGB "darkgreen")
    -- DoGauge ("Mana: ", t.victim.mana,  t.victim.maxmana,  ColourNameToRGB "mediumblue")
    -- DoGauge ("Move: ", t.move,  t.maxmove,  ColourNameToRGB "gold")
  end --if
  
  -- make sure window visible
  if t.combat then
  WindowShow (win, true)
  else
  WindowShow (win, false)
  end --if

end -- function OnPluginTelnetOption


]]>
</script>

</muclient>


This gives me a window that pops up when I fight. It's supposed to show the name of the person being fought but it shows like the color code [0:37m or whatever and doesn't have enough room for the actual short descr. The room descriptions do this to for the room name.

I copied this from the health_bar miniwindow and replaced the HP with the victim name. I guess I need to figure out how to make it longer to show it and then figure out how to strip the color code or something.

Can't post my whole script because of the 6000 characters.
Thoughts?
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #4 on Sun 07 Feb 2010 03:59 AM (UTC)
Message
I've done this to make the box bigger:


  if t.combat then
    vertical = 6  -- pixel to start at
    WindowText (win, FONT_ID, t.victim.name, 5, 5, 0, 0, ColourNameToRGB "saddlebrown")
    vertical = vertical + font_height * 2 -- leave blank line
    DoGauge ("HP: ",   t.victim.hp,    t.victim.maxhp,    ColourNameToRGB "darkgreen")
  end --if


Now I just need to figure out how to get those color codes out of there.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sun 07 Feb 2010 04:21 AM (UTC)
Message
If you uncomment these two lines:


  -- require "tprint"
  -- tprint (t)


... then you will see what t.victim.name really is. In my example earlier it was "the kobold" so I don't see how you would see "[0:37m" on your screen.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #6 on Sun 07 Feb 2010 04:26 AM (UTC)
Message
My short desc has colors in them. So if I'm fighting a guy with the name &RRalph, the armorer&w then the equivalent of &R and &w color codes will display before and after the name.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Sun 07 Feb 2010 04:32 AM (UTC)
Message
So you called something that converted them to colours? No wonder you see the funny numbers. You could just strip out the @R stuff. I had a routine in mw.lua that did that:


-- take a string, and remove colour codes from it (eg. "@Ghello" becomes "hello"
function strip_colours (s)
  s = s:gsub ("@%-", "~")    -- fix tildes
  s = s:gsub ("@@", "\0")  -- change @@ to 0x00
  s = s:gsub ("@%a([^@]*)", "%1")
  return (s:gsub ("%z", "@")) -- put @ back
end -- strip_colours


If you want to see the colours you might have to do more work. In mw.lua is a routine "colourtext" that shows the general idea. Remember, miniwindows don't interpret ANSI colour codes.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #8 on Sun 07 Feb 2010 04:39 AM (UTC)
Message
Is this how I'm supposed to use it?


  -- take a string, and remove colour codes from it (eg. "@Ghello" becomes "hello"
  function strip_colours (s)
    s = s:gsub ("&%-", "~")    -- fix tildes
    s = s:gsub ("&&", "\0")  -- change @@ to 0x00
    s = s:gsub ("&%a([^&]*)", "%1")
    return (s:gsub ("%z", "&")) -- put @ back
  end -- strip_colours

  if t.combat then
    vertical = 6  -- pixel to start at
    WindowText (win, FONT_ID, strip_colours(t.victim.name), 5, 5, 0, 0, ColourNameToRGB "saddlebrown")
    vertical = vertical + font_height * 2 -- leave blank line
    DoGauge ("HP: ",   t.victim.hp,    t.victim.maxhp,    ColourNameToRGB "darkgreen")
  end --if


It's not working like this. Might not be doing it right though.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Sun 07 Feb 2010 05:14 AM (UTC)
Message
Orik said:

My short desc has colors in them. So if I'm fighting a guy with the name &RRalph, the armorer&w then the equivalent of &R and &w color codes will display before and after the name.


OK, well &RRalph does not have codes like "[0:37m" in it, right? You would expect to see "&RRalph" not "[0:37mRalph". That means, at the server end, you must have called some function that converts the description as stored into ANSI colour codes. Well, don't call that function, just pass down the string you actually have stored.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #10 on Sun 07 Feb 2010 05:19 AM (UTC)
Message
In the show_status function in comm.c?
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #11 on Sun 07 Feb 2010 06:08 AM (UTC)
Message
Ok. I wrote a color_strip command to take out the & and it seems to be working.

One other thing, seems that when I hotboot on smaug, my victim prompt doesn't return again. Not sure what that's about. Will have to look into it later.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Sun 07 Feb 2010 09:05 PM (UTC)
Message
Maybe the hotboot resets the flag which says to send telnet codes. Maybe you need to save and restore the flag, or re-query the negotiation. Probably saving and restoring the flag is best, as the client may not respond twice to the same query (from its point of view).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #13 on Sat 13 Feb 2010 02:50 AM (UTC)
Message
I've added my coin types into the show_status and am trying to figure out how to simply just draw a box with the money types in it. I've looked over health bar and exp bar but didn't really see how to do it. I have been up for almost 24 hours and kinda blurry vision...heh. I'm sure I missed something.
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #14 on Sat 13 Feb 2010 01:45 PM (UTC)
Message
So I've done this:


    WindowText (win, FONT_ID, string.format ("Plat: %i Gold: %i Silver: %i Copper %i", 
											  t.plat, t.gold, t.silver, t.copper), left, top, 0, 0, ColourNameToRGB "gold")


It puts it all on one line. How do I put a return in there to show on consecutive lines?

I tried \r, \n, and \r\n and it didn't seem to work. What am I doing wrong?
[Go to top] 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.


16,311 views.

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

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]