General > Developers Corner

Help with Shotgun damage changer

(1/2) > >>

Rex744:

--- Code: ---function DamageHook( ent, dmginfo )
        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( 25 )
        else return
        end
end
hook.Add( "EntityTakeDamage", "ShotgunDamage", DamageHook )
--- End code ---

This code works OK, however right-clicking the shotgun will deal the same damage as left-clicking, if I use this code everyone will want to left-click instead since it's a quicker way to kill.

Can someone help me out?

Fixed, a workaround is to just scale the damage, no one really knows how to make seperate set damages, but there really is no need to anyways.

iViscosity:
I'm confused, what are you trying to accomplish with this code?

Rex744:
Thank you for the help on the last post btw!

I want to change the shotgun damage, let's say I want it to kill someone in 4 hits, it should take 2 right-clicks and 4 left-clicks to kill the person, in this case it's 2 left-clicks to kill and 2-right clicks to kill.

JamminR:
You're going to have to find a way to determine if secondary fire was used.
As your code is now, it only tests if damage was applied, not how.
To be honest, I can't tell from the Wiki if TakeDamageInfo has a way to determine if a secondary fire of shotgun was used.
https://wiki.garrysmod.com/page/Category:CTakeDamageInfo

Rex744:
https://wiki.garrysmod.com/page/GM/KeyPress might be the way?
I'll have to mess with it when I get home.

Edit:
Yep IN_ATTACK2 seems to be it.

Navigation

[0] Message Index

[#] Next page

Go to full version