I recommend putting in some checks to prevent console spam.
For example, this at the start of the onDamage packaged function:
if (!isObject(%obj))
return parent::damage(%this, %obj, %sourceObject, %position, %damage, %damageType);
Just in case the function gets called without a valid object.
But above all, the following the fix the mentioned console spam which has not much to do with the damage not being reduced by the way:
%image = %obj.getMountedImage(NUMBERGOESHERE);
if (isObject(%image))
{
%imageName = %image.getName();
//After this you can redo all the check for the names and then the position of the impact
//Like this
if (%imageName $= "IMAGENAMEGOESHERE")
{
if(getWord(%pos,2) < getWord(%obj.getWorldBoxCenter(),2) - 3.3 * getWord(%obj.getScale(), 2))
{
%damage *= MULTIPLYERGOESHERE;
}
}
if (%imageName $= "IMAGENAMEGOESHERE")
{
if(getWord(%pos,2) < getWord(%obj.getWorldBoxCenter(),2) - 3.3 * getWord(%obj.getScale(), 2))
{
%damage *= MULTIPLYERGOESHERE;
}
}
}
The reason why damage is (probably, have not checked but i see no further complications) not being applied is a small mistake in the code.
In your damage position check you use %pos, but %pos is never known in this function, so the check never goes through.
What DOES exist in this contect is %position, which you know from the functions' parameters.
I recommend changing this line:
function Armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
To this:
function Armor::damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
And this line:
parent::damage(%this, %obj, %sourceObject, %position, %damage, %damageType);
To this:
parent::damage(%this, %obj, %sourceObject, %pos, %damage, %damageType);
This is the best way to do it in your current code.
Alternatively, you could do:
%pos = %position;
At the start of your damage function, but that would be quite silly.
Or you can replace all %pos references with %position, that is also possible.
After looking at the code i see a lot of repeated code. If you want i can help you make it a bit easier for you to change things around by redoing the code for the armor calculations to be more automated.
Like for example, you only need a couple of lines in the damage function and every mounted image of your armors contains a line like: damageReduction = 0.5;
And probably a line to state the minimum height and maximum height of the impact to potentially reduce the damage of.
I think that might even be what stops the damage from reducing still if you done the above suggested changes right, since you check if the impact position is lower then 3.3 torque units below the middle of the player (scaled) for every piece of armor.
I am not sure anymore how big the player is in torqueunits, but that looks more like it would protect the legs or the feet maybe.