OutgoingDamage: Difference between revisions
(targetEntity type check, fixed wrong parameter name) |
(Add C# example for OutgoingDamage) |
||
| Line 23: | Line 23: | ||
} | } | ||
}); | }); | ||
</pre> | |||
}} | |||
}} | |||
{{CSharpContainer| | |||
=== Parameters === | |||
*'''sourceEntity''': {{RageType|Entity}} - entity who received the damage. | |||
*'''targetEntity''': {{RageType|Entity}} - entity who dealt the damage. | |||
*'''sourcePlayer''': {{RageType|Player}} - player who received the damage. | |||
*'''weapon''': {{RageType|UInt64}} - weapon which did the damage. | |||
*'''boneIndex''': {{RageType|UInt64}} - hit BoneIndex (not the BoneId!) | |||
*'''damage''': {{RageType|Int}} - damage it will deal (if not canceled) | |||
*'''cancel''': {{RageType|CancelEventArgs}} - cancel to disable the damage. | |||
== Example == | |||
{{ClientsideCode| | |||
<pre> | |||
public MyClass() | |||
{ | |||
OnOutgoingDamage += OnOutgoingDamageHandler; | |||
} | |||
private void OnOutgoingDamageHandler(Entity sourceEntity, Entity targetEntity, Player sourcePlayer, ulong weaponHash, ulong boneIdx, int damage, CancelEventArgs cancel) | |||
{ | |||
// Cancel damage from you to players in same gang. | |||
// IsPlayerInSameGang in this example is a custom method somewhere in the same class | |||
if (IsPlayerInSameGang(sourcePlayer)) | |||
{ | |||
cancel.Cancel = true; | |||
return; | |||
} | |||
} | |||
</pre> | </pre> | ||
}} | }} | ||
Revision as of 05:47, 27 March 2021
Client-Side Event
Triggered upon damage that an entity is about to give another entity.
This event is also cancellable.
JavaScript Syntax
Parameters
- sourceEntity: Object
- targetEntity: Object
- sourcePlayer: Object
- weapon: Int
- boneIndex: Int
- damage: Int
Example
Client-Side
mp.events.add('outgoingDamage', (sourceEntity, targetEntity, sourcePlayer, weapon, boneIndex, damage) => {
if (targetEntity.type === 'player' && boneIndex === 20) {
return true; // disable outgoing headshot damage
}
});
C# Syntax
Parameters
- sourceEntity: Entity - entity who received the damage.
- targetEntity: Entity - entity who dealt the damage.
- sourcePlayer: Player - player who received the damage.
- weapon: UInt64 - weapon which did the damage.
- boneIndex: UInt64 - hit BoneIndex (not the BoneId!)
- damage: Int - damage it will deal (if not canceled)
- cancel: CancelEventArgs - cancel to disable the damage.
Example
Client-Side
public MyClass()
{
OnOutgoingDamage += OnOutgoingDamageHandler;
}
private void OnOutgoingDamageHandler(Entity sourceEntity, Entity targetEntity, Player sourcePlayer, ulong weaponHash, ulong boneIdx, int damage, CancelEventArgs cancel)
{
// Cancel damage from you to players in same gang.
// IsPlayerInSameGang in this example is a custom method somewhere in the same class
if (IsPlayerInSameGang(sourcePlayer))
{
cancel.Cancel = true;
return;
}
}
See Also
Browser
Checkpoints
Colshapes
Console
Common
- click
- playerChat
- playerCommand
- playerDeath
- playerJoin
- playerQuit
- playerReady
- playerResurrect
- playerRuleTriggered
- playerSpawn
- playerWeaponShot
- addDataHandler
- dummyEntityCreated
- dummyEntityDestroyed
- entityControllerChange
- replayEditorRequest
- pauseMenuItemSelect
- pauseMenuItemChange