Ulysses
General => Developers Corner => Topic started by: Rex744 on April 04, 2017, 03:39:45 PM
-
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.
-
I'm confused, what are you trying to accomplish with this code?
-
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.
-
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
-
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.
-
(http://wiki.garrysmod.com/favicon.ico) SWEP:SecondaryAttack (http://wiki.garrysmod.com/page/WEAPON/SecondaryAttack)
That may be more what you want. The secondary attack function rather than looking for them pressing RMB.
-
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.
-
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.
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