Difference between revisions of "Lua:player ondamage"
From Fortress Forever Wiki
Jump to navigationJump to searchm (Player ondamage moved to Lua:Player ondamage) |
|||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | This function is called whenever a player takes damage. The following variables are set in the global lua namespace before this function is called: | + | {{Infobox manual/Header}} |
+ | ==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_damage: The amount of damage that the player will recieve. | ||
*info_attacker: The player that fired the attack. | *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. | *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. Here is an example script that makes the player take no damage from the super shotgun. | + | 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. | ||
<pre> | <pre> | ||
− | function player_ondamage(player_id) | + | function player_ondamage(player_id, damageinfo) |
ConsoleToAll(GetPlayerName(info_attacker).." shot "..GetPlayerName(player_id).." with a "..info_classname.." for "..info_damage.." damage") | ConsoleToAll(GetPlayerName(info_attacker).." shot "..GetPlayerName(player_id).." with a "..info_classname.." for "..info_damage.." damage") | ||
if info_classname == "ff_weapon_supershotgun" then | if info_classname == "ff_weapon_supershotgun" then | ||
Line 28: | Line 38: | ||
− | [[Category:Lua | + | [[Category:Lua Callbacks]] |
+ | {{Infobox manual/Footer}} |
Latest revision as of 10:20, 12 May 2009
player_ondamage(player_id, damageinfo)This function is called whenever a player takes damage. Inputs
VariablesThe following variables are set in the global lua namespace before this function is called:
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. ExampleHere 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 |