Possible to Assign DamageType Without Replacing Actor?

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!)
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Possible to Assign DamageType Without Replacing Actor?

Post by MrJohnny »

The title says all. I'm looking to assign a custom damagetype to Doom's BFGBall without actually replacing it. Is this possible, somehow?
User avatar
krokots
Posts: 272
Joined: Tue Jan 19, 2010 5:07 pm

Re: Possible to Assign DamageType Without Replacing Actor?

Post by krokots »

Well in ZScript you could do following, but this means you need to make an additional Class from which all your mod's actors would need to inherit.
In this class you would override "DamageMobj" and inside, you would just check if the inflictor class name is "BFGBall". If it is, you could just change damage type (it's called 'mod' in this function) to some other type.
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Re: Possible to Assign DamageType Without Replacing Actor?

Post by MrJohnny »

Sorry to be a bother, but I'm sort of new to the whole zscript scene. If it's no trouble, would you mind providing a rough example?
User avatar
krokots
Posts: 272
Joined: Tue Jan 19, 2010 5:07 pm

Re: Possible to Assign DamageType Without Replacing Actor?

Post by krokots »

So this would only apply to actors that inherit from a parent class, say, MyActor

Code: Select all

Class MyActor : Actor
{
	override int DamageMobj(Actor inflictor, Actor source, int damage, Name mod, int flags = 0, double angle = 0)
	{
		if(inflictor.GetClassName() == "BFGBall")
		{
			mod = 'ChangedDamageType';
		}
		return Super.DamageMobj(inflictor, source, damage, mod, flags, angle);
	}
}
With this, you need all your actors that you want that changed damage type to apply, to inherit from MyActor, not Actor, so:

Code: Select all

Class MyZombieman : MyActor replaces Zombieman
{
	//Copy code from Zombieman
}
Unfortunately this as you can see is not perfect, because you need to copy all the classes you want to use just to inherit from MyActor. The positive is that you will have then great control over this actors, because of cool virtual functions, like DamageMobj, or Die.
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Re: Possible to Assign DamageType Without Replacing Actor?

Post by MrJohnny »

Wow, thanks a billion! This saved me a lot of headache!
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Re: Possible to Assign DamageType Without Replacing Actor?

Post by MrJohnny »

Okay, so I've run into a problem. Apparently, whenever an actor that inherits from the class is crushed, GZDoom crashes and throws the following error: "vm execution aborted: tried to read from address zero. Called from AllowDamagetypes.DamageMobj at NOUV.pk3: zscript, line 7"

Code: Select all

version "2.5"

Class AllowDamagetypes : ACTOR
{
	override int DamageMobj(Actor inflictor, Actor source, int damage, Name mod, int flags = 0, double angle = 0)
	{
		if(inflictor.GetClassName() == "BFGBall") 
		{
			mod = 'BFG';
		}		
      return Super.DamageMobj(inflictor, source, damage, mod, flags, angle);
	}
}
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm

Re: Possible to Assign DamageType Without Replacing Actor?

Post by Arctangent »

You're not checking if inflictor is null, so when the actor dies to the world ( and thus there's no inflictor ) it tries to call GetClassName() from a non-existent object.
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Re: Possible to Assign DamageType Without Replacing Actor?

Post by MrJohnny »

That makes sense. Thanks, works like a charm.

Return to “Scripting”