Possible to Assign DamageType Without Replacing Actor?
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!)
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!)
-
- Posts: 212
- Joined: Fri Aug 05, 2016 8:41 am
Possible to Assign DamageType Without Replacing Actor?
The title says all. I'm looking to assign a custom damagetype to Doom's BFGBall without actually replacing it. Is this possible, somehow?
-
- Posts: 272
- Joined: Tue Jan 19, 2010 5:07 pm
Re: Possible to Assign DamageType Without Replacing Actor?
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.
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.
-
- Posts: 212
- Joined: Fri Aug 05, 2016 8:41 am
Re: Possible to Assign DamageType Without Replacing Actor?
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?
-
- Posts: 272
- Joined: Tue Jan 19, 2010 5:07 pm
Re: Possible to Assign DamageType Without Replacing Actor?
So this would only apply to actors that inherit from a parent class, say, MyActor
With this, you need all your actors that you want that changed damage type to apply, to inherit from MyActor, not Actor, so:
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.
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);
}
}
Code: Select all
Class MyZombieman : MyActor replaces Zombieman
{
//Copy code from Zombieman
}
-
- Posts: 212
- Joined: Fri Aug 05, 2016 8:41 am
Re: Possible to Assign DamageType Without Replacing Actor?
Wow, thanks a billion! This saved me a lot of headache!
-
- Posts: 212
- Joined: Fri Aug 05, 2016 8:41 am
Re: Possible to Assign DamageType Without Replacing Actor?
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);
}
}
-
- Posts: 1235
- Joined: Thu Nov 06, 2014 1:53 pm
Re: Possible to Assign DamageType Without Replacing Actor?
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.
-
- Posts: 212
- Joined: Fri Aug 05, 2016 8:41 am
Re: Possible to Assign DamageType Without Replacing Actor?
That makes sense. Thanks, works like a charm.