Gamemode.PlayerShouldTakeDamage

From GMod Wiki

Jump to: navigation, search
Event Hook
Hook NamePlayerShouldTakeDamage
SyntaxGM:PlayerShouldTakeDamage( Player victim , Entity attacker )
DescriptionCalled whenever a player gets hurt.
ReturnsBoolean - true for "take damage", false for "ignore the damage"
Lua StateNewerServer.png
BBCode[b][url=wiki.garrysmod.com/?title=Gamemode.PlayerShouldTakeDamage]Gamemode.PlayerShouldTakeDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionMake it so admins can't take damage.
Used onNewerServer.png
Code
 
-- Because it's always returning something you should use function GM:PlayerShouldTakeDamage() instead.
function playershouldtakedamage(victim, attacker)
	return (not victim:IsAdmin()) --Note: not reverses the boolean value of IsAdmin()
end
 
hook.Add( "PlayerShouldTakeDamage", "playershouldtakedamage", playershouldtakedamage)
 
OutputN/A



DescriptionThis examples shows how, in a team based gamemode, you can use this to turn friendly fire on and off using mp_friendlyfire.
Used onNewerServer.png
Code
 
function GM:PlayerShouldTakeDamage( victim, pl )
if pl:IsPlayer() then -- check the attacker is player 	
if( pl:Team() == victim:Team() and GetConVarNumber( "mp_friendlyfire" ) == 0 ) then -- check the teams are equal and that friendly fire is off.
		return false -- do not damage the player
	end
end
 
	return true -- damage the player
end
 
OutputN/A
Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox