OutgoingDamage: Difference between revisions

From RAGE Multiplayer Wiki
(Add C# example for OutgoingDamage)
(Add null check to example)
Line 49: Line 49:
     // Cancel damage from you to players in same gang.
     // Cancel damage from you to players in same gang.
     // IsPlayerInSameGang in this example is a custom method somewhere in the same class
     // IsPlayerInSameGang in this example is a custom method somewhere in the same class
     if (IsPlayerInSameGang(sourcePlayer))  
     if (sourcePlayer != null && IsPlayerInSameGang(sourcePlayer))  
     {
     {
         cancel.Cancel = true;
         cancel.Cancel = true;

Revision as of 05:47, 27 March 2021

Client-Side Event

 C#  JavaScript


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 (sourcePlayer != null && IsPlayerInSameGang(sourcePlayer)) 
    {
        cancel.Cancel = true;
        return;
    }
}


See Also

Browser

Checkpoints

Colshapes

Console

Common

Damage

Vehicles

Voice chat

Streaming

Graphics

Waypoint

Misc