Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Add support for custom dmg events #53

Open
michael-harman opened this issue Jun 22, 2021 · 5 comments
Open

Suggestion: Add support for custom dmg events #53

michael-harman opened this issue Jun 22, 2021 · 5 comments

Comments

@michael-harman
Copy link

Would you be able to add support for PlayerTakeRealDamage similar to how you did with TTTEquipmentUse. I have traitor weapons that deal damage that either doesn't get logged or deals damage as an entity so it says "unknown weapon." I've been trying to use a similar method to how you did for equipment but it's a bit more complicated.

@BadgerCode
Copy link
Owner

Hey.

I'll have to look into this.

I had to do something similar for a poison dart weapon and I can't remember exactly how I did it.

@michael-harman
Copy link
Author

image

Funny because I also did a workaround for my poison dart gun. The logs recognize that the other entity does damage it just doesn't know the name. Is there any way I can add the entity name to the weapon name list? I know it's automatic now but in the past when you could add weapons manually.

@BadgerCode
Copy link
Owner

I can't remember the exact logic for how it works out the name of the damaging entity.

I'll have to check it next week as I'm away this week.

@BadgerCode
Copy link
Owner

For a poison dart gun I've worked on, I have a separate entity to do poison damage to the player - ttt_dartgun_poison

Here's how it does the damage

local dmginfo = DamageInfo()
    dmginfo:SetDamage(damageAmount)
    dmginfo:SetAttacker(self:GetOwner())
    dmginfo:SetInflictor(self)
    dmginfo:SetDamageType(DMG_POISON)
self.Target:TakeDamageInfo(dmginfo)

This seems to result in the classname being used in the damage logs.

Here's the logic in the damage logs which determines what name to use for the damage entity.
The result from this will later be translated (if possible). If the entity has a PrintName attribute, that should be used instead.

function Damagelog:WeaponFromDmg(dmg)
    local inf = dmg:GetInflictor()
    local wep = nil
    local isWorldDamage = inf != nil and inf.IsWorld and inf:IsWorld()

    if IsValid(inf) or isWorldDamage then
        if inf:IsWeapon() or inf.Projectile then
            wep = inf
        elseif dmg:IsDamageType(DMG_BLAST) then
            wep = "DMG_BLAST"
        elseif dmg:IsDamageType(DMG_DIRECT) or dmg:IsDamageType(DMG_BURN) then
            wep = "DMG_BURN"
        elseif dmg:IsDamageType(DMG_CRUSH) or dmg:IsDamageType(DMG_FALL) then
            wep = "DMG_CRUSH"
        elseif dmg:IsDamageType(DMG_SLASH) then
            wep = "DMG_SLASH"
        elseif dmg:IsDamageType(DMG_CLUB) then
            wep = "DMG_CLUB"
        elseif dmg:IsDamageType(DMG_SHOCK) then
            wep = "DMG_SHOCK"
        elseif dmg:IsDamageType(DMG_ENERGYBEAM) then
            wep = "DMG_ENERGYBEAM"
        elseif dmg:IsDamageType(DMG_SONIC) then
            wep = "DMG_SONIC"
        elseif dmg:IsDamageType(DMG_PHYSGUN) then
            wep = "DMG_PHYSGUN"
        elseif inf:IsPlayer() then
            wep = inf:GetActiveWeapon()

            if not IsValid(wep) then
                wep = IsValid(inf.dying_wep) and inf.dying_wep
            end
        end
    end

    if type(wep) ~= "string" then
        return IsValid(wep) and wep:GetClass()
    else
        return wep
    end
end

@michael-harman
Copy link
Author

michael-harman commented Jul 20, 2021

local function TurretOwner(ent, dmginfo)
	local inf = dmginfo:GetInflictor()
	if IsValid(inf) and inf.TTTTurret then
		dmginfo:SetAttacker((IsValid(inf.TurretOwner) and inf.TurretOwner) or inf)
	end
end
hook.Add("EntityTakeDamage", "TurretCredit", TurretOwner)

This is how I've been attributing damage with my turret. The damage logs display the attacker (player) but not the inflictor (turret). I have also set the PrintName attribute in the entity.

I have a feeling that maybe this line of code in the damagelogs is why it's not working
if inf:IsWeapon() or inf.Projectile then

I will mess around with it and report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants