ZScript HudMessage

Sprites, textures, sounds, code, and other resources belong here. Share and share-alike!
Forum rules
Before posting your Resource, please make sure you can answer YES to any of the following questions:
  • Is the resource ENTIRELY my own work?
  • If no to the previous one, do I have permission from the original author?
  • If no to the previous one, did I put a reasonable amount of work into the resource myself, such that the changes are noticeably different from the source that I could take credit for them?
If you answered no to all three, maybe you should consider taking your stuff somewhere other than the Resources forum.

Consult the Resource/Request Posting Guidelines for more information.

Please don't put requests here! They have their own forum --> here. Thank you!
User avatar
Jekyll Grim Payne
Global Moderator
Posts: 1117
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

ZScript HudMessage

Post by Jekyll Grim Payne »

Repository: https://github.com/jekyllgrim/ZScript-H ... /tree/main



I'm not the first to do it, and I'm also not completely satisfied with my current implementation, but it works (even though it can only be called from play scope).

All documentation is at the repository. The hudmessage relies on an event handler (you can implement the event and the array into your own event handler if you're using them) and a class that handles the drawing. There's only one function that can be used as a combination of HUDMSG_TYPEON and HUDMSG_FADEINOUT HudMessage styles.

If you plan to use this in your project, I recommend using Find & Replace to replace "JGP_" with your own prefix.

To draw the hud message, call JGP_HudMessage.Create from anywhere in play context. Currently cannot be called in UI scope.

Code: Select all

static JGP_HudMessage Create(string text, uint id = 0, name fontname = 'NewSmallFont', int fontColor = Font.CR_Red, vector2 pos = (160, 50), int alignment = ALIGN_LEFT, uint fadeInTime = 0, uint typeTime = 0, uint holdTime = 35, uint fadeOutTime = 0, vector2 scale = (1,1), PlayerInfo viewer = null)
Arguments:
  • text — the string of text to print. LANGUAGE references are supported.
  • id (default: 0) — the ID of the message. If non-zero, new messages will override older messages with the same ID.
  • fontname (default: 'NewSmallFont') — the name of the font to be used.
  • fontcolor (default: Font.CR_Red) — the color of the font (as defined in the Font struct).
  • pos (default: (160, 50)) — the position of the message in a virtual 320x200 grid. Note, this is virtual resolution, so (0, 0) corresponds to top left corner of the screen.
  • alignment (default: ALIGN_LEFT) — the alignment of the text relative to the pos.
    JGP_HudMessage.ALIGN_CENTER — center alignment
    JGP_HudMessage.ALIGN_LEFT — left alignment (default)
    JGP_HudMessage.ALIGN_RIGHT — right alignment
  • fadeInTime (default: 0) — the time in tics it takes the message to fade in. If non-zero, holdTime will begin the countdown after the message fully faded in.
  • typeTime (default: 0) — if non-zero, each character will take this amount of time in tics to type out each character in the string. If fadeInTime is non-zero, typing and fade-in will overlap, and holdTime will begin counting after whatever took longer (fade-in or type-out) has finished.
  • holdTime (default: 35) — the time in tics the message will stay on the screen (fade-in, fade-out and type-out are added on top of this).
  • fadeOutTime (default: 0) — the time in tics the message will take to fade out before disappearing.
  • scale (default: (1, 1)) — the scale of the text.
  • viewer (default: null) — a PlayerInfo pointer. If non-null, the message will only be visibled to the specified player. Otherwise it'll be visible to everyone.
If you want to imitate HUDMSG_TYPEON, make sure typeTime is above 0. If you want FADEINOUT, make sure fadeInTime and fadeOutTime are non-zero. Typing and fading can be combined.
Last edited by Jekyll Grim Payne on Mon Sep 25, 2023 6:12 am, edited 1 time in total.
Reason: added streamable video
User avatar
Brohnesorge
Posts: 499
Joined: Sat Oct 08, 2016 9:10 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Win10
Graphics Processor: nVidia with Vulkan support

Re: ZScript HudMessage

Post by Brohnesorge »

Holy shit, this is something I've been wanting and bashing my head against for damn near 3 years now. It is beyond exciting to see this being a thing, thank you.

Return to “Resources”