Reducing Damage (With InventoryAddon Item)?

So I’m attempting to create a custom item for this beautiful piece of work: http://www.garrysmod.org/downloads/?a=view&id=70734

And I know nearly jack shit about Lua.
I managed to edit the rebel clothes item to make the player “wear” body armor (sets playermodel to Metrocop), and then add a “clothes” item to the player’s inventory when used (and vice versa - when clothes are worn, the body armor item is added and the model is changed to male_02).

That part works flawlessly for now, so I’d like to move on to the part I’ve been having trouble with - the actual armor part.

I hopelessly attempted an autorun script that would check for damage and reduce it if the armor value (from the body armor) wasn’t zero.

Of course, I have no idea if that script is running or not (or if it would even work when it ran, for that matter).

I’ve coded the armor and clothes to correctly update “armorval” (at least I think I did).

(The ply:SetArmor in each was originally how I was going to handle damage calculation, but then realized that I had no way of saving the suit value of each body armor item, so it would end up resetting itself if the player removed the armor then put it back on again.)

And yes, I know the math I did for the failed attempt at damage reduction is stupid, and could be done WAY more efficiently, but that’s not the issue at the moment.

If anybody could give me some advice, or just flat-out tell me what to do, I’d really appreciate it.

takeDmg is not running, you need to hook it to a gamemode function. Add this to the code, under the functions. [lua]hook.Add(“ScalePlayerDamage”, “anyuniquenamehere”, takeDmg)[/lua]

What do you mean by “hook it to a gamemode function”?
(Sorry, as mentioned in my post up there I know jack shit about Lua.)

hook it so that it is called when the function GM.ScalePlayerDamage is called.

[lua]function takeDmg(ply,hitgroup,dmginfo)

if(ply.armorval == .75) then
	dmginfo:SubtractDamage(dmginfo:GetDamage * 0.75)
end	

end

function assignArmorVal(ply,armorval)
armorval = 0
end

–Here? ---------------------------------
hook.Add(“ScalePlayerDamage”, “anyuniquenamehere”, takeDmg)
----------------------------------------- [/lua]

There?
I know, I’m a hopeless noob… :frowning:

Yes

Alright, cool…
Now, I noticed that either armorval isn’t even being set to .75 upon “equipping” the body armor, or I screwed up the if().

[lua]function takeDmg(ply,hitgroup,dmginfo)

if(ply.armorval == .75) then
	dmginfo:SubtractDamage(dmginfo:GetDamage * 0.75)
	InventoryAddon:SendMessage( "It works, lol!", ply, false )
end	

end

function assignArmorVal(ply,armorval)
armorval = 0
end

hook.Add(“ScalePlayerDamage”, “anyuniquenamehere”, takeDmg)[/lua]

When I take damage, nothing happens (no damage reduction - it’s still applied normally, and no message).