IncomingDamage: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
(Add C# example)
Line 22: Line 22:
     // code
     // code
});
});
</pre>
}}
{{CSharpContainer|
=== Parameters ===
*'''sourcePlayer''': {{RageType|Player}} - player (if sourceEntity is Player type) who deals the damage.
*'''sourceEntity''': {{RageType|Entity}} - entity who deals the damage.
*'''targetEntity''': {{RageType|Entity}} - target getting the damage.
*'''weapon''': {{RageType|UInt64}} - weapon Id used.
*'''boneIndex''': {{RageType|UInt64}} - bone index (not id!) hit.
*'''damage''': {{RageType|Int}} - damage getting dealt (if not canceled).
*'''cancel''': {{RageType|CancelEventArgs}} - used to cancel the event.
== Example ==
<pre>
public MyClass()
{
    OnIncomingDamage += OnIncomingDamageHandler;
}
private void OnIncomingDamageMethod(Player sourcePlayer, Entity sourceEntity, Entity targetEntity, ulong weaponHash, ulong boneIdx, int damage, CancelEventArgs cancel)
{
    // Show bloodscreen if hit from a opponent player from another gang.
    // IsInSameGang in this example is a custom method in the same class.
    if (!IsInSameGang(sourcePlayer))
        ShowBloodscreen();  // Also a custom method you have to implement yourself.
}
</pre>
</pre>
}}
}}

Revision as of 05:55, 27 March 2021

Client-Side Event

 C#  JavaScript


[1.1]

Triggered upon damage that is about to be given to the player.

This event is also cancellable.

JavaScript Syntax

Parameters

  • sourceEntity: Object
  • sourcePlayer: Object
  • targetEntity: Object
  • weapon: Int
  • boneIndex: Int
  • damage: Int

Example

mp.events.add('incomingDamage', (sourceEntity, sourcePlayer, targetEntity, weapon, boneIndex, damage) => {
    // code
});


C# Syntax

Parameters

  • sourcePlayer: Player - player (if sourceEntity is Player type) who deals the damage.
  • sourceEntity: Entity - entity who deals the damage.
  • targetEntity: Entity - target getting the damage.
  • weapon: UInt64 - weapon Id used.
  • boneIndex: UInt64 - bone index (not id!) hit.
  • damage: Int - damage getting dealt (if not canceled).
  • cancel: CancelEventArgs - used to cancel the event.

Example

public MyClass() 
{
    OnIncomingDamage += OnIncomingDamageHandler;
}

private void OnIncomingDamageMethod(Player sourcePlayer, Entity sourceEntity, Entity targetEntity, ulong weaponHash, ulong boneIdx, int damage, CancelEventArgs cancel)
{
    // Show bloodscreen if hit from a opponent player from another gang.
    // IsInSameGang in this example is a custom method in the same class.
    if (!IsInSameGang(sourcePlayer)) 
        ShowBloodscreen();   // Also a custom method you have to implement yourself.
}


See Also

Browser

Checkpoints

Colshapes

Console

Common

Damage

Vehicles

Voice chat

Streaming

Graphics

Waypoint

Misc