How to set projectile damage on the fly?

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
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

How to set projectile damage on the fly?

Post by ramon.dexter »

So, here is my situation:
I got a inventory item "pwrLevel" that indicates player's "power" - health&damage.

How do I modify projectile's damage on the fly? I dont want to make a long A_JumpIfInventory list, so I want to use zscript to modify the projectile's damage.
When I used this:

Code: Select all

TNT1 A 0
			{
				if(countinv("pwrlevel") == 1)
				{
					wrstCannonProjectile.damage = 4;					
				}
			
			}
The parser returned following error:
"Unable to access 'wrstCannonProjectile.Damage' in a static context"

So, how do I modify the projectile's damage/damagefunction?

edit: Also, I dont want to use powerup, because it modifies damage of all weapons. I need to raise damage of one weapon.
Blue Shadow
Posts: 5038
Joined: Sun Nov 14, 2010 12:59 am

Re: How to set projectile damage on the fly?

Post by Blue Shadow »

Create a function which would calculate and return the damage, and pass it to DamageFunction:

Code: Select all

class BlahProjectile : Actor
{
    Default
    {
        DamageFunction GetDamage();
    }

    int GetDamage ()
    {
        int dmg = 30;

        // The target of a projectile is its shooter.
        if (target && target.CountInv("Something"))
        {
            // Multiply the base damage by 2 if the shooter has the item.
            dmg *= 2;
        }

        return dmg;
    }
}
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: How to set projectile damage on the fly?

Post by ramon.dexter »

Thanks, works as expected :)

edit: Need to thank you again, this time I tested it and it it really a gem, thank you a lot!

One more thing to ask: When "target" is projectile's shooter, how is the ... umm ... target, point the projectile heads to, called?

Return to “Scripting”