OnLocalPlayerDamaged

From GT-MP
Jump to: navigation, search
OnLocalPlayerDamaged
Client-Side Function
System-users.png Client-Side Javascript.png JavaScript

This event is triggered when the local player takes damage.

Syntax

In Javascript
Client-Side Function

API.onLocalPlayerDamaged.connect(function callback);

Required Arguments

  • callback: parameter input should be in function type.
    • enemy: Handle of the entity that damaged the local player. (LocalHandle)
    • weapon: The weapon used to damage the local player. (int)
    • bone: The bone that got damaged. (int)

Damage Causes

Dialog-warning.png

This event is only called when the local player gets shot by another player in version 0.1.6.

This issue has been fixed in 0.1.7, the event now also triggers when any damage caused by any vehicle, world, ped or object happens.

This event will also detect melee hits in 0.1.7, bone ID will be -1 for melee hits. (will be fixed in the future)

If the local player takes damage from a source that is not another player, enemy handle will be 0 and weapon will be one of these:

Weapon Name ID
Object 0
Vehicle 1
PedOrWorld 2

Usage example(s)

In Javascript
Client-Side Function

Instant death when shot in the head:

API.onLocalPlayerDamaged.connect(function(enemy, weapon, bone) {
    if (bone == 31086) // Head
    {
        API.setPlayerHealth(-1);
    }
});

References