World thing damage question

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

World thing damage question

Post by Apeirogon »

How change damage using world thing damage?

This

Code: Select all

	override void WorldThingDamaged(WorldEvent e)
	{
	if(e.thing is "playerpawn")
	{e.damage * 0;} and {e.damage *= 0;} 
       }
dont work.
Blue Shadow
Posts: 5039
Joined: Sun Nov 14, 2010 12:59 am

Re: World thing damage question

Post by Blue Shadow »

You can't. The event is triggered after the damage is inflicted.
User avatar
Eliot_L
Posts: 38
Joined: Thu Mar 08, 2018 3:40 am

Re: World thing damage question

Post by Eliot_L »

Though with a custom actor I believe you can by changing the return value of DamageMObj
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: World thing damage question

Post by krokots »

Apeirogon wrote:How change damage using world thing damage?

This

Code: Select all

	override void WorldThingDamaged(WorldEvent e)
	{
	if(e.thing is "playerpawn")
	{e.damage * 0;} and {e.damage *= 0;} 
       }
dont work.
You would need to "heal" this thing damaged, and then apply some other damage.
User avatar
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

Re: World thing damage question

Post by Matt »

krokots wrote:You would need to "heal" this thing damaged, and then apply some other damage.
I haven't tried it, but given how everything else works I'd be willing to be at least three drinks that anything that's taken a lethal amount of damage would be dead by this point, so it would only work for non-lethal hits.
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: World thing damage question

Post by krokots »

Matt wrote:
krokots wrote:You would need to "heal" this thing damaged, and then apply some other damage.
I haven't tried it, but given how everything else works I'd be willing to be at least three drinks that anything that's taken a lethal amount of damage would be dead by this point, so it would only work for non-lethal hits.
Yes of course, that only counts if the victim hasn't died. I would suggest to make own Actor class (MyActor), and make all monsters inherit from this class. Inside MyActor override DamageMobj and do whatever you want with it.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: World thing damage question

Post by Apeirogon »

Reason I ask this not because I dont know how override virtual function and inherit one actor from another.

I made monster randomization mod, which among other things, change damage of monsters. And I made it based on inventory items, for compatibility with all other mods.
But it can change only damage of a projectile, since projectile can point to actor which shot it. Hitscan and splash damage cant be changed in such way, because to force puff point to actor which "shot" it I must change flags on it before it spawn.

I found way to bypass this limitation, make another inventory item which add to actor buddha flag and then await command to remove it.
But this way hurt to performance and now I search way to force engine "ignore" monsters, which player dont see, as much as possible.
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: World thing damage question

Post by krokots »

Apeirogon wrote:Reason I ask this not because I dont know how override virtual function and inherit one actor from another.

I made monster randomization mod, which among other things, change damage of monsters. And I made it based on inventory items, for compatibility with all other mods.
But it can change only damage of a projectile, since projectile can point to actor which shot it. Hitscan and splash damage cant be changed in such way, because to force puff point to actor which "shot" it I must change flags on it before it spawn.

I found way to bypass this limitation, make another inventory item which add to actor buddha flag and then await command to remove it.
But this way hurt to performance and now I search way to force engine "ignore" monsters, which player dont see, as much as possible.
If you can afford to change EVERY monster in your mod to inherit from a custom actor class, then do it. The only downside is, if your monsters already inherit from some other monsters. So, if you have a CustomZombieman : Zombieman, and only differance between him and default zombieman is, say, health, that sucks, because you'll need to COPY all code from zombieman, inside gzdoom.pk3.
For a monster to inherit from an custom actor, you need to:
1) Every monster will have to have this after name:

Code: Select all

Class CustomZombieman : CustomActor
{
	(...)
}
As I said, this means you can't inherit from other monsters, so will have to copy some monsters code here if you did that.
2) Create CustomActor class

Code: Select all

Class CustomActor : Actor
{
	//This is empty
}
3) Create an overriden function DamageMobj in CustomActor

Code: Select all

Class CustomActor : Actor
{
	override int DamageMobj(Actor inflictor, Actor source, int damage, Name mod, int flags = 0, double angle = 0)
	{
		return Super.DamageMobj(inflictor, source, damage, mod, flags, angle);
	}
}
Now you can change the damage and other stuff and it will count for EVERY monster that is inheriting from CustomActor

Code: Select all

Class CustomActor : Actor
{
	override int DamageMobj(Actor inflictor, Actor source, int damage, Name mod, int flags = 0, double angle = 0)
	{
		damage *= 0.5;	//Example - all damage is halved
		return Super.DamageMobj(inflictor, source, damage, mod, flags, angle);
	}
}
User avatar
Eliot_L
Posts: 38
Joined: Thu Mar 08, 2018 3:40 am

Re: World thing damage question

Post by Eliot_L »

If you are going with this approach you could also just subclass and replace all the monsters in the target iwad to avoid having to copy-paste the implementation around.
So maybe something like this - using an external function would help in case you need to tweak the logic later since it's only in one place:

Code: Select all

class DamageProcessor
{
    static int ScaleDamage(Actor target, int damage) {
        return damage * 0.5;
    }
}
And then:

Code: Select all

class CustomZombieman : Zombieman replaces Zombieman
{
   override int DamageMobj(Actor inflictor, Actor source, int damage, Name mod, int flags = 0, double angle = 0)
   {
      damage = DamageProcessor.ScaleDamage(self, damage);
      return Super.DamageMobj(inflictor, source, damage, mod, flags, angle);
   }
}
Unfortunately, I think any actor replacement technique would probably conflict with other mods that do the same thing, if that sort of compatibility is a goal (sounds like it may be.)
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: World thing damage question

Post by Apeirogon »

Apeirogon wrote:And I made it based on inventory items, for compatibility with all other MONSTER REPLACING mods.
That what I means.

Try this with any monster mod.
fade_out.wad
You do not have the required permissions to view the files attached to this post.

Return to “Scripting”