Script: print amount of damage dealt?
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
-
- Posts: 57
- Joined: Sun Apr 09, 2006 12:54 pm
- Contact:
Script: print amount of damage dealt?
Do you guys know how I can print a message in the top right corner of the screen that shows how much damage I caused to a monster? So like, I shoot a cyberdemon once with a bfg, and I want to show how much health he lost. I know how to print messages, but I'm not sure how to base the message off of a monster's health.
Re: Script: print amount of damage dealt?
Maybe it's better to make the damage numbers fly to the ceiling from the attacked monster's head (like in Torchlight)?
-
- Posts: 57
- Joined: Sun Apr 09, 2006 12:54 pm
- Contact:
Re: Script: print amount of damage dealt?
Well that's even more too complicated for me to do (I'm a script newbie), but it sounds nice.
-
- Posts: 5043
- Joined: Sun Nov 14, 2010 12:59 am
Re: Script: print amount of damage dealt?
All I can do is direct you to [wiki=hudmessageonactor]this[/wiki] ACS function.
- Matt
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
- Contact:
Re: Script: print amount of damage dealt?
Would anyone know how to get that number though? At least without having to constantly track the actor's health as of the immediately preceding tic?
Re: Script: print amount of damage dealt?
The way I'd do it would be this:
1. Add a user_prevhealth variable.
2. In spawn state, init user_prevhealth to health, using [wiki]A_SetUserVar[/wiki]
3. In pain state, compare health to user_prevhealth and print that with [wiki]A_LogInt[/wiki], then set user_prevhealth to health.
Advantage: DECORATE only.
Drawback: doesn't work when monsters aren't pained by the hit, potentially generates multiple logs from shotgun blasts.
1. Add a user_prevhealth variable.
2. In spawn state, init user_prevhealth to health, using [wiki]A_SetUserVar[/wiki]
3. In pain state, compare health to user_prevhealth and print that with [wiki]A_LogInt[/wiki], then set user_prevhealth to health.
Advantage: DECORATE only.
Drawback: doesn't work when monsters aren't pained by the hit, potentially generates multiple logs from shotgun blasts.
Re: Script: print amount of damage dealt?
Possible solution: Make pain chance 255. Alter the pain state to have no obvious effect (ie immediately return to the see state after activating the checks) but also have a jump in there so that the monster will still sometimes jump to a more normal pain state with roughly the same frequency as its original pain chance would cause.Gez wrote:doesn't work when monsters aren't pained by the hit
Re: Script: print amount of damage dealt?
Still guaranteed to interrupt whatever was going on (such as an attack). I, not being afraid of adding some acs libraries to my project, would probably opt for the constant tracking of health. (Script would execute every tick, and perhaps many instances would be running, but they would perform very few instructions. I think it should be fine for most normal cases.)
The script needs to end if the activator has ceased to exist.
It doesn't mess with pain, so even if it requires acs, I prefer it.
It has issues too, though:
It could be possible to start multiple instances of the script. (Use an idle-state to avoid reexecuting spawn-state, and let the first state under the spawn-label contain A_JumpIf(true, "idle") in case you get back there anyway.)
It could be possible to start 0 instances of the script. (If something disruptive happens inbetween spawn and the first active tick for the new actor.)
The script needs to end if the activator has ceased to exist.
It doesn't mess with pain, so even if it requires acs, I prefer it.
It has issues too, though:
It could be possible to start multiple instances of the script. (Use an idle-state to avoid reexecuting spawn-state, and let the first state under the spawn-label contain A_JumpIf(true, "idle") in case you get back there anyway.)
It could be possible to start 0 instances of the script. (If something disruptive happens inbetween spawn and the first active tick for the new actor.)
Spoiler: To get it robust, stuff may be extensive. I'm saying that it can be done, not that it has been done.No existing feature goes as far as to let you track individual occurences of actual damage. (Health changes can vary in nature, and the ACS solution gets you an aggregate value, not individual occurences. If individual occurences are required, the pain-solution might be the most viable approach.)
Re: Script: print amount of damage dealt?
Doesn't 256, not 255, cause 100% chance of pain?Enjay wrote:Possible solution: Make pain chance 255.Gez wrote:doesn't work when monsters aren't pained by the hit
Re: Script: print amount of damage dealt?
PainChance value
Probability of entering the pain state (256 = always, 0 = never). You can also specify PainChance per damage type. Sources of damage that have the FORCEPAIN flag ignore this property.
Default is 0.
http://zdoom.org/wiki/Actor_properties
Probability of entering the pain state (256 = always, 0 = never). You can also specify PainChance per damage type. Sources of damage that have the FORCEPAIN flag ignore this property.
Default is 0.
http://zdoom.org/wiki/Actor_properties
Re: Script: print amount of damage dealt?
Heh, everybody knows that. But the discussion of 256 vs 255 has been seen before. The idea of "is 255 -actually- 100%" or not.
I've seen the proper answer with explanation before but I've frankly forgotten.
I've seen the proper answer with explanation before but I've frankly forgotten.
Re: Script: print amount of damage dealt?
It depends on whether the operator used is < or <=.
The idea is that a random number generator will be used to generate a number between 0 and 255. The edge case is if 255 is generated.
If <= is used, then it's alright. 255<=255 is true.
But if < is used, then it'll fail in that one case. 255<255 is false. With 256, you should be safe in all cases, except if the comparison number is stored on a single byte, because is 1 00000000b is cropped to a 8-bit value, it turns into 00000000b, which is zero.
The idea is that a random number generator will be used to generate a number between 0 and 255. The edge case is if 255 is generated.
If <= is used, then it's alright. 255<=255 is true.
But if < is used, then it'll fail in that one case. 255<255 is false. With 256, you should be safe in all cases, except if the comparison number is stored on a single byte, because is 1 00000000b is cropped to a 8-bit value, it turns into 00000000b, which is zero.