General > Developers Corner

Help with Shotgun damage changer

<< < (2/2)

BlueNova:
SWEP:SecondaryAttack

That may be more what you want. The secondary attack function rather than looking for them pressing RMB.

Rex744:

--- Code: ---function DamageHook( key, ent, dmginfo )
if ( key == IN_ATTACK ) then
        if not ent:IsNPC() and not ent:IsPlayer() then return end
        local attacker = dmginfo:GetAttacker()
        if attacker:IsPlayer() and attacker:GetActiveWeapon():GetClass() == "weapon_shotgun" then
                dmginfo:SetDamage( 1 )
        else return
        end
    end
end
hook.Add( "EntityTakeDamage", "ShotgunDamage", DamageHook )

function DamageHook2( key, ent, dmginfo )
if ( key == IN_ATTACK2 ) then
        if not ent:IsNPC() and not ent:IsPlayer() then return end
        local attacker = dmginfo:GetAttacker()
        if attacker:IsPlayer() and attacker:GetActiveWeapon():GetClass() == "weapon_shotgun" then
                dmginfo:SetDamage( 1 )
        else return
        end
    end
end
hook.Add( "EntityTakeDamage", "ShotgunDamage2", DamageHook2 )
--- End code ---

I've tried both ways, the one I found and the SWEP.SecondaryAttack, but something is strange, the shotgun damage isn't being modified at all now.
It is killing in 1-2 hits regardless of what the setdamage value is at.

Rex744:
I've tried again and again with different versions of the same code, currently this is what I got to, nothing is working, I did fix the strange error where nothing changed damage, this changes the damage (I think) but right-click kills in 2 hits and so does left-click so I'm back to where I started.

I still need some help.


--- Code: ---function Attack2( key )
if ( key == IN_ATTACK2 ) then
ShotgunAttack2()
end
end
hook.Add( "KeyPress", "Attack2", Attack2 )

function Attack( key )
if ( key == IN_ATTACK ) then
ShotgunAttack()
end
end
hook.Add( "KeyPress", "Attack", Attack )

function ShotgunAttack2(ply, dmginfo)
        local attacker = dmginfo:GetAttacker()
        if ply:GetActiveWeapon():GetClass() == "weapon_shotgun" then
                dmginfo:SetDamage( 25 )
        else return
        end
end

function ShotgunAttack(ply, dmginfo)
        local attacker = dmginfo:GetAttacker()
        if ply:GetActiveWeapon():GetClass() == "weapon_shotgun" then
                dmginfo:SetDamage( 6 )
        else return
        end
end
--- End code ---

Edit:
I've started another thread at Facepunch for the same thing:
https://facepunch.com/showthread.php?t=1559420

Navigation

[0] Message Index

[*] Previous page

Go to full version