IncomingDamage: Difference between revisions

From RAGE Multiplayer Wiki
(Add C# example)
(Add null check to example)
 
Line 46: Line 46:
     // Show bloodscreen if hit from a opponent player from another gang.
     // Show bloodscreen if hit from a opponent player from another gang.
     // IsInSameGang in this example is a custom method in the same class.
     // IsInSameGang in this example is a custom method in the same class.
     if (!IsInSameGang(sourcePlayer))  
     if (sourcePlayer != null && !IsInSameGang(sourcePlayer))  
         ShowBloodscreen();  // Also a custom method you have to implement yourself.
         ShowBloodscreen();  // Also a custom method you have to implement yourself.
}
}

Latest revision as of 05:56, 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 (sourcePlayer != null && !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