ULX

Author Topic: Help with Shotgun damage changer  (Read 2354 times)

0 Members and 1 Guest are viewing this topic.

Offline Rex744

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Help with Shotgun damage changer
« on: April 04, 2017, 03:39:45 PM »
Code: [Select]
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 )

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.
« Last Edit: April 05, 2017, 07:43:25 PM by Rex744 »

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with Shotgun damage changer
« Reply #1 on: April 04, 2017, 05:45:46 PM »
I'm confused, what are you trying to accomplish with this code?
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Rex744

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: Help with Shotgun damage changer
« Reply #2 on: April 04, 2017, 06:15:10 PM »
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.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help with Shotgun damage changer
« Reply #3 on: April 04, 2017, 07:21:36 PM »
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
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Rex744

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: Help with Shotgun damage changer
« Reply #4 on: April 04, 2017, 07:38:20 PM »
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.
« Last Edit: April 04, 2017, 07:41:57 PM by Rex744 »

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Re: Help with Shotgun damage changer
« Reply #5 on: April 04, 2017, 08:11:35 PM »
SWEP:SecondaryAttack

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

Offline Rex744

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: Help with Shotgun damage changer
« Reply #6 on: April 04, 2017, 08:47:06 PM »
Code: [Select]
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 )

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.
« Last Edit: April 04, 2017, 08:48:46 PM by Rex744 »

Offline Rex744

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: Help with Shotgun damage changer
« Reply #7 on: April 05, 2017, 10:27:15 AM »
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: [Select]
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

Edit:
I've started another thread at Facepunch for the same thing:
https://facepunch.com/showthread.php?t=1559420
« Last Edit: April 05, 2017, 11:13:25 AM by Rex744 »