victim.DamageMobJ is not dealing damage?

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!)
Post Reply
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

victim.DamageMobJ is not dealing damage?

Post by XASSASSINX »

Hello everyone, i've made this nailgun weapon that hits multiple enemies, but i want its damage to reduce for each enemy that it hits. If i put any random intenger there, it works fine but without said damage reduction. However, if i use some custom variable, the damage does not work? Or rather, it seems to work only at random minium distances, which is even more confusing. Here is the code for it:

Code: Select all

Class Scalliano_PlayerNail : FastProjectile
{
 int HitTimes;
 int HitMax;
 int NailGunDamage;
 actor HitMonster;
 Default
 {
  Damage 0;
  Speed 40;
  MissileHeight 8;
  MissileType "Scalliano_PlayerNailTrail";
  Radius 3;
  Height 2;
  Decal "FadingBulletChip";
 }
  
   override Void PostBeginPlay()
   {
    int NailGunDamage = 20;
   }
  
   override int SpecialMissileHit(actor victim) 
    {
        if (victim && target && victim != target && victim != HitMonster) 
        {   
	        victim.DamageMobj(self,target, NailGunDamage, "Normal");
			A_SpawnItemEx("Blood");
			HitTimes++;
            HitMonster = victim;            
        }
        return 1;                        
    }
 
 States
 {
 Spawn:
  TNT1 A 0 NoDelay { HitMax = random(2, 4); }
 SpawnLoop:
  TNT1 A 1
  {
   if (HitTimes > HitMax)
    return ResolveState("XDeath");
   return ResolveState(null);
  }
  Loop;
  
  ...
  
Why is this happening?

Small edit: the reason it is a fast projectile with 40 speed is because i thought the collision system for fast projectiles was bugging it, alas i put it to 40 speed, but its actually a very fast 150 speed projectile.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: victim.DamageMobJ is not dealing damage?

Post by Jarewill »

Taking a quick glance at the code, I suspect it's because you define NailGunDamage as a new variable in PostBeginPlay, which means that it will only have a value of 20 in that function.
Anywhere else it will remain 0, remove int before NailGunDamage and it should work.
You could also put the code in the Spawn state into PostBeginPlay as well.
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: victim.DamageMobJ is not dealing damage?

Post by XASSASSINX »

Oh yeah, that was a dumb mistake of mine. That made it a temporary variable. Even so, i did what you said earlier of putting it in the first tic of the spawn state with NoDelay and yet it wans't working, sometimes rather. Anyways this fixed it, thank you!
Post Reply

Return to “Scripting”