Lua:player ondamage

From Fortress Forever Wiki
(Redirected from Lua:Player ondamage)
Jump to navigationJump to search


player_ondamage(player_id, damageinfo)

This function is called whenever a player takes damage.

Inputs

  • player_id(CFFPlayer) The player who is being damaged
  • damageinfo(CTakeDamageInfo) An info packet about the damage being dealt. See Damageinfo_functions.

Variables

The following variables are set in the global lua namespace before this function is called:

  • info_damage: The amount of damage that the player will recieve.
  • info_attacker: The player that fired the attack.
  • info_classname: The classname of the weapon that hit the player. Note that this may be the classname of the projectile for projectile weapons, or the classname of the weapon for non-projectile weapons.

This function may modify the info_damage global variable in the global scope. If it does, the damage the player takes will be changed. This means that the script for a map can make players recieve more or less damage through scripting.

Example

Here is an example script that makes the player take no damage from the super shotgun.

function player_ondamage(player_id, damageinfo)
	ConsoleToAll(GetPlayerName(info_attacker).." shot "..GetPlayerName(player_id).." with a "..info_classname.." for "..info_damage.." damage")
	if info_classname == "ff_weapon_supershotgun" then
		ConsoleToAll("Take no damage from supershotty")
		info_damage = 0
	end
end

Here's another example in case you wanted to not take damage from your own rockets:

function player_ondamage( player_id )

	-- Don't take rocket damage from ourselves
	if ( player_id == info_attacker ) then
		if ( info_classname == "rocket" ) then
			info_damage = 0
		end
	end
end