Is there a way to see if the player died when playershouldtakedamage is called?
I'm setting the attackers entity with setnwentity but it's only supposed to set it when he didn't die but does take damage
I would recommend you either use [url=http://wiki.garrysmod.com/page/GM/ScalePlayerDamage]ScalePlayerDamage[/url] or [url=http://wiki.garrysmod.com/page/GM/EntityTakeDamage]EntityTakeDamage[/url] which provide you with the dmginfo object, giving you information about the damage the player is about to take, allowing you to do something like this:
[lua]
hook.Add( "EntityTakeDamage", "DetectDeath", function( ent, dmg )
if not ent:IsPlayer() then return end -- Don't run with a non-player entity
if ent:Health() -dmg:GetDamage() <= 0 then
-- player died
dmg:SetDamage( 0 ) -- let's set the damage to 0
end
return dmg -- return the new damageinfo object
end )
hook.Add( "ScalePlayerDamage", "DetectDeath", function( ply, hitgroup, dmg )
if ply:Health() -dmg:GetDamage() <= 0 then
-- player died
dmg:ScaleDamage( 0 ) -- same thing...
end
end )
[/lua]
[editline]16th June 2014[/editline]
Also, take a look at the [url=http://wiki.garrysmod.com/page/Category:CTakeDamageInfo]CTakeDamageInfo[/url] structure.
Even better, you shouldn't even need this if you just want to tell the victim who killed them, just use a [url=http://wiki.garrysmod.com/page/Net_Library_Usage]net message[/url] and net.WriteEntity( attacker ) so you can do whatever you want client side:
[lua]util.AddNetworkString( "send_player_killer" )
hook.Add( "PlayerDeath", "SendKiller", function( ply, wep, att )
net.Start( "send_player_killer" )
net.WriteEntity( att )
net.Send( ply )
end )[/lua]
[QUOTE=Internet1001;45119108]I would recommend you either use [url=http://wiki.garrysmod.com/page/GM/ScalePlayerDamage]ScalePlayerDamage[/url] or [url=http://wiki.garrysmod.com/page/GM/EntityTakeDamage]EntityTakeDamage[/url] which provide you with the dmginfo object, giving you information about the damage the player is about to take, allowing you to do something like this:
[lua]
hook.Add( "EntityTakeDamage", "DetectDeath", function( ent, dmg )
if not ent:IsPlayer() then return end -- Don't run with a non-player entity
if ent:Health() -dmg:GetDamage() <= 0 then
-- player died
dmg:SetDamage( 0 ) -- let's set the damage to 0
end
return dmg -- return the new damageinfo object
end )
hook.Add( "ScalePlayerDamage", "DetectDeath", function( ply, hitgroup, dmg )
if ply:Health() -dmg:GetDamage() <= 0 then
-- player died
dmg:ScaleDamage( 0 ) -- same thing...
end
end )
[/lua]
[/QUOTE]
Thanks, exactly what i needed!
Sorry, you need to Log In to post a reply to this thread.