Author Topic: Weapon Damage  (Read 1573 times)

I want to know how to make weapon damage vary between two numbers. For instance, I want to make the damage of a projectile have a possibility of doing damage between 70 and 100. How would I do this? Would I edit this line of code?
Code: [Select]
directDamage        = 70;

What you could do is package your projectile's damage function and do your varying stuff there.
Take a look here: http://forum.blockland.us/index.php?topic=14090.0

What you could do is package your projectile's damage function and do your varying stuff there.
Take a look here: http://forum.blockland.us/index.php?topic=14090.0

I'm not very smart with torque script. I read that entire topic twice but I am still confused.

Ok, lets say that you're weapon's projectile is blahProjectile.

First set that variable you mentioned earlier to 70.

Then you would do this (read the comments):
Code: [Select]
function blahProjectile::damage(%this,%obj,%col,%fade,%pos,%normal)
{
   if(%this.directDamage <= 0)
   {
      return;
   }

   %damageType = $DamageType::Direct;
   if(%this.DirectDamageType)
   {
      %damageType = %this.DirectDamageType;
   }

    //%directDamage is your projectile's damage,
    //defined by the datablock. It should be 70, because
    //you set it to be that

    %directDamage = %this.directDamage;

    //now vary it - get a random number between 0 and 30
    //and add it
    %add = getRandom(0, 30);
    %directDamage = %directDamage + %add;

   if(%col.getType() & $TypeMasks::PlayerObjectType)
   {
      %col.damage(%obj, %pos, %directDamage, %damageType);
   }
   else
   {
      %col.damage(%obj, %pos, %directDamage, %damageType);
   }
}

I didn't test this but it's a good generalization of what I was talking about.

why don't you just define %directDamage all in one go?

Code: [Select]
function blahProjectile::damage(%this,%obj,%col,%fade,%pos,%normal)
{
   if(%this.directDamage <= 0)
      return;

   %damageType = $DamageType::Direct;
   if(%this.DirectDamageType)
      %damageType = %this.DirectDamageType;

   %directDamage = %this.directDamage + getRandom(0,30);

   if(%col.getType() & $TypeMasks::PlayerObjectType)
      %col.damage(%obj, %pos, %directDamage, %damageType);

   else
      %col.damage(%obj, %pos, %directDamage, %damageType);
}

Modified version inspired by phflack!
« Last Edit: December 21, 2012, 01:39:11 AM by Honorabl3 »

some people like to split it up, others do not
similar to how some people like to put {}s after if's when unneeded

I hate it when people add the extra { and }.. X.X

directDamage = getRandom(70, 100);



Is this what you mean?

Oo, didn't think of that.

No, that won't work. It'll set the direct damage to a random value when it loads, not every time it's fired. There's a reason we didn't say that.

why don't you just define %directDamage all in one go?

Modified version inspired by phflack!
I'm well aware of better methods of doing this, but I split it up for the reason of the op's better understanding. It's just easier to get what I'm explaining imo.