Advanced Hudmessageonactor
Forum rules
Before posting your Resource, please make sure you can answer YES to any of the following questions:
Consult the Resource/Request Posting Guidelines for more information.
Please don't put requests here! They have their own forum --> here. Thank you!
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?
Consult the Resource/Request Posting Guidelines for more information.
Please don't put requests here! They have their own forum --> here. Thank you!
Advanced Hudmessageonactor
Hello, I've been poking around with ACS for a while, and I found HudMessageOnActor.
When I found it wouldn't work, I decided to modify it.
I have fixed it, and made it more flexible as well.
(The problem was, that value "dist" was way too high, so in the script, I changed the if statement to use "&& dist / 100000 < Range")
So, what I added was this:
- Distance value is lowered to represent map units
- You can now make your message / sprite display on said actor, no matter what.
- You can now restrict the message to only change vertically or horizontally.
- You can invert the position of your message
- You can change message color through this command
Here the command in ACS:
hudmessageonactor(int TID, int Range, bool IgnoreAll, str Sprite, str Text, int Id, str Color, Bool horiz, Bool verti, Bool invert, Bool clip);
TID = Thing ID
Range = How close in map units you have to be to said actor for the message to appear
Sprite = Display a graphic instead, set this to -1 to disable it.
Text = Put text on HUD instead of a graphic, enter what you want it to say here. If sprite is not -1, this argument is ignored.
ID = Message ID (This is for the ID argument in the normal hudmessage command)
Color = Put things like CR_RED or CR_UNTRANSLATED here.
Horiz = Allows the message position to be changed horizontally.
Verti = Allows the message position to be changed vertically.
Invert = Inverts the position output of the message.
Clip = If the message exceeds a limit, it's position is set to that limit, 0.1 units closer to the middle of the screen
Sometimes the function may divide by zero, I'm not sure why, but I have a good guess.
It's probably due to the sine of the pitch/angle being divided by the cosine of the pitch/angle.
I have fixed this for pitch, but I need to also fix it for angle.
(Division by zero due to the angle can only happen if "ignoreall" is "1"
Command to set hudmessage position limits, so that way text will just stay at the edge of those limits. (So by default, if the text goes to the far-right of the screen, it won't go off-screen, it will just stay there)
(X numbers must be 0-640, Y numbers must be 0-400, since hudsize is changed to 640x400)
SetHudMessageLimits(int minx1, int miny1, int maxx1, int maxy1)
minx1 = How far to the left any message that moves horizontally can go.
miny1 = How far up any message that moves vertically can go.
maxx1 = How far to the right any message that moves horizontally can go.
maxy1 = How far down any message that moves vertically can go.
Here's a video demonstration:
(If you can't see the text, try watching in HD, fullscreen, or both)
(Does not show off clipping feature)
You can grab the function source as a text document below.
Hope you enjoy it!
(I hope the actual code doesn't look like a mess, since I did add a lot if statements)
When I found it wouldn't work, I decided to modify it.
I have fixed it, and made it more flexible as well.
(The problem was, that value "dist" was way too high, so in the script, I changed the if statement to use "&& dist / 100000 < Range")
So, what I added was this:
- Distance value is lowered to represent map units
- You can now make your message / sprite display on said actor, no matter what.
- You can now restrict the message to only change vertically or horizontally.
- You can invert the position of your message
- You can change message color through this command
Here the command in ACS:
hudmessageonactor(int TID, int Range, bool IgnoreAll, str Sprite, str Text, int Id, str Color, Bool horiz, Bool verti, Bool invert, Bool clip);
TID = Thing ID
Range = How close in map units you have to be to said actor for the message to appear
Sprite = Display a graphic instead, set this to -1 to disable it.
Text = Put text on HUD instead of a graphic, enter what you want it to say here. If sprite is not -1, this argument is ignored.
ID = Message ID (This is for the ID argument in the normal hudmessage command)
Color = Put things like CR_RED or CR_UNTRANSLATED here.
Horiz = Allows the message position to be changed horizontally.
Verti = Allows the message position to be changed vertically.
Invert = Inverts the position output of the message.
Clip = If the message exceeds a limit, it's position is set to that limit, 0.1 units closer to the middle of the screen
Sometimes the function may divide by zero, I'm not sure why, but I have a good guess.
It's probably due to the sine of the pitch/angle being divided by the cosine of the pitch/angle.
I have fixed this for pitch, but I need to also fix it for angle.
(Division by zero due to the angle can only happen if "ignoreall" is "1"
Command to set hudmessage position limits, so that way text will just stay at the edge of those limits. (So by default, if the text goes to the far-right of the screen, it won't go off-screen, it will just stay there)
(X numbers must be 0-640, Y numbers must be 0-400, since hudsize is changed to 640x400)
SetHudMessageLimits(int minx1, int miny1, int maxx1, int maxy1)
minx1 = How far to the left any message that moves horizontally can go.
miny1 = How far up any message that moves vertically can go.
maxx1 = How far to the right any message that moves horizontally can go.
maxy1 = How far down any message that moves vertically can go.
Here's a video demonstration:
(If you can't see the text, try watching in HD, fullscreen, or both)
(Does not show off clipping feature)
You can grab the function source as a text document below.
Hope you enjoy it!
(I hope the actual code doesn't look like a mess, since I did add a lot if statements)
- Attachments
-
- Hudmessageonactor.txt
- Now divides "dist" by 65536.
- (3.64 KiB) Downloaded 296 times
Last edited by HeXaGoN on Sat Aug 11, 2012 1:35 pm, edited 4 times in total.
Re: Advanced Hudmessageonactor
Why didn't you update the [wiki]hudmessageonactor[/wiki] article itself?
Re: Advanced Hudmessageonactor
I only fixed the function to use mapunits (So yes, I have updated the wiki article), since I really didn't want to put this advanced one the zdoom wiki (Because the new arguments are a bunch of if statements with in the function).Gez wrote:Why didn't you update the [wiki]hudmessageonactor[/wiki] article itself?
Plus the advanced one I made uses a lot of arguments.
I also made 2 functions.
I specifically changed this If statement:
if ((ang < 0.2 || ang > 0.8) && dist < range)
To this:
if ((ang < 0.2 || ang > 0.8) && dist / 100000 < range)
That way, the value dist, will be scaled down to map units, since I figured out the value would become over 100,000.
Re: Advanced Hudmessageonactor
Map units are expressed in [wiki]fixed point[/wiki] numbers, so you ought to divide by 65536 instead of 100000.
Re: Advanced Hudmessageonactor
I'll try that, but I'm not trying to be as accurate as possible, since I'm trying to make numbers like 25600000 into 256. (Because when I'm 256 map units away, dist is about 25600000)
Edit: Thanks Gez, that makes the check perfectly accurate.
Edit: Thanks Gez, that makes the check perfectly accurate.
Last edited by HeXaGoN on Sat Aug 11, 2012 1:17 pm, edited 2 times in total.
Re: Advanced Hudmessageonactor
Did you know that if you type 256.0, it will be interpreted as a fixed point number (so, 256*65536) and be perfectly accurate? If you do that, you don't need to divide by 65536 afterwards.
Re: Advanced Hudmessageonactor
Partially, I just was thinking of the wrong number.
I tested this, by putting the player exactly 256 map units away from the actor the command is targeting.
I made a script that would print the value of dist.
It printed: 16777216
I divided this value by 65536, and I got '256'
If I set the range to only display the message with in 256 map units, I would not just leave 'dist' at 16777216, would I?
Or do you mean multiply the 'range' value by 65536?
Either way, it would have the same output.
Well, I only divide so that you can make range a value that would represent 65536, since dist is already multiplied by 65536.Gez wrote:If you do that, you don't need to divide by 65536 afterwards.
I tested this, by putting the player exactly 256 map units away from the actor the command is targeting.
I made a script that would print the value of dist.
It printed: 16777216
I divided this value by 65536, and I got '256'
If I set the range to only display the message with in 256 map units, I would not just leave 'dist' at 16777216, would I?
Or do you mean multiply the 'range' value by 65536?
Either way, it would have the same output.
-
darkmessenger84
- Posts: 8
- Joined: Mon May 04, 2015 9:49 am
- Location: Grantham, UK
Re: Advanced Hudmessageonactor
I hate to bump an old thread. But I've brought much needed improvements to this function as well as some bug fixes. The Wiki page has been updated to reflect this.
Code: Select all
function void hudmessageonactor(int tid, int msgID, int xOffset, int yOffset, int range, str sprite, str text, str font)
{
int dist, angle, vang, pitch, x, y;
int HUDX = 800;
int HUDY = 600;
if(sprite != -1)
{
SetFont(sprite);
text = "A";
//offset = 0.1;
} else {
SetFont(font);
}
SetHudSize(HUDX, HUDY, 1);
x = GetActorX(tid) - GetActorX(0);
y = GetActorY(tid) - GetActorY(0);
vang = VectorAngle(x,y);
angle = (vang - GetActorAngle(0) + 1.0) % 1.0;
if(((vang+0.125)%0.5) > 0.25) dist = FixedDiv(y, sin(vang));
else dist = FixedDiv(x, cos(vang));
if ((angle < 0.2 || angle > 0.8) && dist / 65536 < range)
{
if (GetActorPitch(0) >= -16383 && GetActorPitch(0) <= 16383) // Pitch threshold
{
pitch = VectorAngle(dist, GetActorZ(tid) - (GetActorZ(0) + 41.0));
pitch = (pitch + GetActorPitch(0) + 1.0) % 1.0;
if ((HUDX/2) * sin(angle) != 0 && cos(angle) != 0 && (HUDX/2) * sin(pitch) != 0 && cos(pitch) != 0) // Fixes divide by zero
{
x = HUDX/2 - ((HUDX/2) * sin(angle) / cos(angle));
y = HUDY/2 - ((HUDX/2) * sin(pitch) / cos(pitch));
x = x+xOffset;
y = y+yOffset;
HudMessage(s:text; HUDMSG_PLAIN, msgID, CR_WHITE, (x * 1.0), (y * 1.0), 0);
} else {
// Division by 0
HudMessage(s:""; HUDMSG_PLAIN, msgID, CR_WHITE, 0, 0, 0);
}
} else {
// Outside pitch threshold
HudMessage(s:""; HUDMSG_PLAIN, msgID, CR_WHITE, 0, 0, 0);
}
} else {
// Out of range or not visible
HudMessage(s:""; HUDMSG_PLAIN, msgID, CR_WHITE, 0, 0, 0);
}
}- The Zombie Killer
- Posts: 1528
- Joined: Thu Jul 14, 2011 12:06 am
- Location: Gold Coast, Queensland, Australia
Re: Advanced Hudmessageonactor
Tidied up the function some more, because it's always bothered me that this function has been an absolute mess of differing programming styles.
I also removed redundant features (now it acts more like HudMessage, just use SetFont to display sprites, no need to implement it directly, and don't hardcode the hud size)
http://pastebin.com/38sGrzHY
I also removed redundant features (now it acts more like HudMessage, just use SetFont to display sprites, no need to implement it directly, and don't hardcode the hud size)
http://pastebin.com/38sGrzHY
Re: Advanced Hudmessageonactor
TBH when I originally made this thread I was still getting the ropes to programming, and I was much more of an idiot. 
-
darkmessenger84
- Posts: 8
- Joined: Mon May 04, 2015 9:49 am
- Location: Grantham, UK
Re: Advanced Hudmessageonactor
Thanks for your contributions, though.
Re: Advanced Hudmessageonactor
I've question is that function works only for the player who activated it or could works for all players in activity.
I would like to use it on Zandronum to put some objectives on actors like "defend it" or "kill it", is it possible ?
I would like to use it on Zandronum to put some objectives on actors like "defend it" or "kill it", is it possible ?
-
darkmessenger84
- Posts: 8
- Joined: Mon May 04, 2015 9:49 am
- Location: Grantham, UK
Re: Advanced Hudmessageonactor
To do that, you would need to give an actor a thing ID and call the function in a while(true) loop.
I've also noticed that The Zombie Killer's version of the function makes use of the alpha parameter in HudMessage, which is not supported by Zandronum but ZDoom 2.7.1 only.
Here's a small example of what I've done with the function.

I've also noticed that The Zombie Killer's version of the function makes use of the alpha parameter in HudMessage, which is not supported by Zandronum but ZDoom 2.7.1 only.
Here's a small example of what I've done with the function.

- NachtIntellect
- Posts: 312
- Joined: Wed Feb 29, 2012 2:10 pm
- Location: Bienenstock, Germany
Re: Advanced Hudmessageonactor
That's pretty amazing, think we can find a way to get it to print the monsters health using an image like you can do with Status bar? If so that'd be really, really handy.
- The Zombie Killer
- Posts: 1528
- Joined: Thu Jul 14, 2011 12:06 am
- Location: Gold Coast, Queensland, Australia
Re: Advanced Hudmessageonactor
It's just there for completeness' sake, I'm pretty sure the parameter just gets ignored in Zandronum. I think Zandronum 3.0 supports it (or at least it's planned, considering Zan3.0 is intended to be up to date with 2.7.1 soon)darkmessenger84 wrote:I've also noticed that The Zombie Killer's version of the function makes use of the alpha parameter in HudMessage, which is not supported by Zandronum but ZDoom 2.7.1 only.

