MattJeanes / PewPew

Divran's old GCombat remake now up to date for Garry's Mod 13.
7 stars 9 forks source link

ShouldDoBlastDamage ignores return false. #36

Closed bloxgate closed 9 years ago

bloxgate commented 9 years ago

I'm running the following code in a hook:

hook.Add("PewPew_ShouldDoBlastDamage", "PPBlastDMGHook", function(hookSelf, TargetEntity, pos, rad, dam)
    if TargetEntity.SC_CoreEnt != nil then
        local dtd = (dam)/2
        local damage2 = {EM=0, EXP=dtd, KIN=0, THERM=dtd}

            if TargetEntity:IsValid() and TargetEntity:GetClass() == "shield" then  --Do some shield damage

                TargetEntity.Parent.Strength = math.Clamp(TargetEntity.Parent.Strength-((((damage/2)/SC_SG_Shield_MaxDamage())*100)/(TargetEntity.Parent.StrengthMultiplier[1]*TargetEntity.Parent.StrengthConfigMultiplier)),0,100)
                TargetEntity:Hit(TargetEntity,src,1.0) --So it still plays the shields hit effect

            else
        SC_ApplyDamage(TargetEntity, damage2)
        return false
    end
end)

However pewpew explosives are still doing normal damage and removing parts of people's contraptions AND calling the SC_ApplyDamage function at the same time. Looking through the code this should only be stopping the actual blast damage.

MattJeanes commented 9 years ago

Yeah looking at the pewpew code I can confirm this. Hang on while I deploy a fix

MattJeanes commented 9 years ago

Can you test the GitHub version of this to make sure it works before I deploy to workshop? Thanks

bloxgate commented 9 years ago

Sadly the only place running the exact code that's problematic is a live server that has a lot of people on it right now so it may be a while.

Divran commented 9 years ago

I've talked to Matt about this and the logic was already correct. Something in your code must be wrong for that to happen.

Also note that pewpew calls util.BlastDamage alongside its BlastDamage function, in order to deal damage to players mainly. This could have an unwanted side effect if you have an addon that treats util.BlastDamage as damage that can destroy any prop. To prevent this, use both a PewPew_ShouldDoBlastDamage and a EntityTakeDamage hook at the same time. (http://wiki.garrysmod.com/page/GM/EntityTakeDamage)

bloxgate commented 9 years ago

I'll look into that now.

bloxgate commented 9 years ago

Looks like our EntityTakeDamage hook was missing a return false and some quirk in earlier versions of the script where I used the ShouldTakeBlastDamage hook was avoiding this somehow so when we changed to a better one this problem came up.