So, I want the disable the "knockback" the damaged player gets when he is shot, but I could find anything in the Wiki about this, any help would be appreciated.
:snip: doesn't work... hang on...
[editline]24th May 2016[/editline]
I tried a bunch of stuff, and I think the only way to stop the knockback is by changing the method of which the damage is applied. Something like this disables the knockback:
[CODE]
hook.Add( 'EntityTakeDamage', 'NoDamageKnockback', function( target, dmginfo )
if dmginfo:IsBulletDamage() and target:IsPlayer() then -- if the damage was caused by a bullet and the target was a player
local prevdamage = dmginfo:GetDamage() -- get the damage before it gets set to 0
dmginfo:SetDamage( 0 ) -- set it to 0 (this stops the knockback)
target:SetHealth( target:Health() - prevdamage ) -- change the target's health using a different method
end
end )
[/CODE]
[QUOTE=MPan1;50381773]:snip: doesn't work... hang on...
[editline]24th May 2016[/editline]
I tried a bunch of stuff, and I think the only way to stop the knockback is by changing the method of which the damage is applied. Something like this disables the knockback:
[CODE]
hook.Add( 'EntityTakeDamage', 'NoDamageKnockback', function( target, dmginfo )
if dmginfo:IsBulletDamage() and target:IsPlayer() then -- if the damage was caused by a bullet and the target was a player
local prevdamage = dmginfo:GetDamage() -- get the damage before it gets set to 0
dmginfo:SetDamage( 0 ) -- set it to 0 (this stops the knockback)
target:SetHealth( target:Health() - prevdamage ) -- change the target's health using a different method
end
end )
[/CODE][/QUOTE]
The problem is that this wouldn't be compatible with other damage hooks (ScalePlayerDamage,EntityTakeDamage) plus setting a player's health to 0 or a negative number won't kill him or register as a kill for the other player
[code]
hook.Add("ScalePlayerDamage","Remove Force", function(victim,hitgroup,dmginfo)
local Damage = dmginfo:GetDamage()
local Health = victim:Health()
if Damage < Health then
victim:SetHealth(Health - Damage)
return true
end
end)
[/code]
Didn't test this but if you know lua you should get what I mean.
Only problem is that other damage hooks may not work with this method because you're telling the other hooks to fuck off (plus there's shit like headshots and leg/arm shots to keep track of so a leg shot might still knock you back)
Really you can use this method if you have a special gamemode without any addons that modify damage.
[editline]49[/editline]
I hope that someone else has a better answer, because I've been struggling to know this for quite some time. [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/CTakeDamageInfo/SetDamageForce]CTakeDamageInfo:SetDamageForce[/url] doesn't seem to work.
alright, thanks guys, i'm sort of using mpan1's method now, heres the code:
[CODE]function GM:ScalePlayerDamage(ply, hitgroup, dmginfo)
if(ply == dmginfo:GetAttacker()) then return true; end
if(ply:Team() == dmginfo:GetAttacker():Team()) then return true; end
if(hitgroup == HITGROUP_HEAD) then
dmginfo:ScaleDamage(1337);
for k,v in next, player.GetAll() do
v:ChatPrint(dmginfo:GetAttacker():Name().." got a headshot!");
end
else
dmginfo:ScaleDamage(mults[hitgroup]);
end
end
function GM:EntityTakeDamage(ply, info)
ply:SetHealth(ply:Health() - info:GetDamage());
info:SetDamage(0);
end[/CODE]
Sorry, you need to Log In to post a reply to this thread.