Author Topic: Cordax Armor not blocking damage  (Read 5062 times)

Been awfully busy, I could make an attempt to fix the problem but I won't be able to test it

Looked at the add-on, you have TONS of if statements in the damage function, if a lot of people are being damaged at once it can possibly lag the server, unfortunately I do not want to waste a lot of time fixing that but I will look into why

It's not blocking damage because every if statement checks to see if they are 'headshots' - I am not going to spend hours doing repetitive code
OP is also getting console spam because it doesn't check if image slot 1 has an image, it just thinks it always has one.

The code otherwise looks fine to me, just remove your old health system and download the new health system - Could of been the problem for it not blocking damage but I'm not completely sure.



A good practice in the future when you have so many datablocks, putting a variable on your helmet/armor datablocks saying it is either armor or a helmet along with a damage resistance variable. Then in the damage code you just do a few simple checks (also useful if you ever add more helmets and the function won't be slower) and then apply the new damage. This saves A LOT of time in case you messed up on something, especially when every check is using a headshot (?) check.
« Last Edit: July 11, 2017, 04:56:34 PM by Kyuande »

Can i just quote what i posted, since it is the problem and a lot of tips on how to improve the code?
I'm gonna do it anyway:
I recommend putting in some checks to prevent console spam.
For example, this at the start of the onDamage packaged function:
Code: [Select]
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:
Code: [Select]
%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:
Code: [Select]
function Armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
To this:
Code: [Select]
function Armor::damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
And this line:
Code: [Select]
parent::damage(%this, %obj, %sourceObject, %position, %damage, %damageType);
To this:
Code: [Select]
parent::damage(%this, %obj, %sourceObject, %pos, %damage, %damageType);
This is the best way to do it in your current code.
Alternatively, you could do:
Code: [Select]
%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.

hate to be that guy, but any progress made?

Doesn't seem so. I'm not fixing it. It would take a chunk of hours to fix what happened here because it was a copy-paste code for each armor using the wrong detection, and also many checks in a package resulting in the server being slower when a player gets damaged, bad practice. It's not worth my time fixing it - unless I was paid to do it.

i gave him some code that would just check if the mounted images had damage reduction values and applied it if present, but I don't think he understood how to use it completely. unfortunately i didnt have the time then as well to hand-hold him through the process, but i gave him multiple examples as well as an edited version of one of the armors he had so it would work with my system.

cordax, if you're still around and working on this pack, you can ask for help here or on the blockland content creator discord.