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

Just as the title says, I've got cordax's armor on the server and none of the armors block the percent amount of damage that they say they will.

Console is spammed with the message:
Add-Ons/Item_CordaxArmor/server.cs (increasing number) : Unable to find objects: '0' attempting to call function 'getName'
BackTrace: ->[cushionpackage]Armor::onImpact->Armor::onImpact->[Slayer_Gamemode_OMA]Player::Damage->[CustomHealth]ShapeBase::Damage->ShapeBase::Damage->[BotHolePackage]Armor::Damage->[Event_onBotDamageStuff]Armor::Damage->[SD_MedArmorPackage]Armor::Damage

Any help would be wonderful, and if there's any more info you'd need let me know

This is prob my fault because i got lazy with the little coding i had to do to make it work.
I don't know how to fix this, so someone who has prior experience with this kind of stuff, pls help

The damage script does not check if armor exists before its name is checked. Adding a check to see if the helmet exists and another check to see if the chestplate exists seems to remove the error messages. I was not able to get damage to reduce yet, though.

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.

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.
I'm only really starting to code myself, but if codax doesn't want to, I could help with implementing changes
I mean unless you're gonna do the changes yourself

I'm only really starting to code myself, but if codax doesn't want to, I could help with implementing changes
I mean unless you're gonna do the changes yourself
I should do it myself but if i start i might as well redo the thing like i said at the very end, which would take a bit of time.
Nothing toooo much, but i can't right now.

I'm not knowledgeable enough to be able to fix this. If anyone would like to give it a shot, go ahead. I'll give credit on the topic

anyone going to fix this?

This needs to be solved

Also it seems any mods use damage will break custom health systems (package priorities), been a known problem when the first few custom health mods were ever made. The new health system (rewritten) is on its way to solve these kinds of problems. I had to basically rewrite the source function for this to work properly.

Might be the armor's fault in this case but other add-ons related also have the issues above when custom health does not work. If someone has a link to download the armor I can fix it as soon as possible

Well ATM I'm trying to get the version of the armors used on the Med RP. It will include several suggested features and fix the health problem.

nvm he changed his mind
« Last Edit: June 11, 2017, 06:52:13 PM by 8hbc »

If someone has a link to download the armor I can fix it as soon as possible

It's still on the add-on topic...
The search tool is your friend https://forum.blockland.us/index.php?topic=306150.0