KAyo

PlayerDamage

Recommended Posts

I tried the PlayerDamage event on server and client side which only outputs a text to the chat for testing at first.
But on both variants the events didnt got triggered. Why?

mp.events.add("playerDamage", (player, healthLoss, armorLoss) => {
    mp.gui.chat.push("You lost: " + healthLoss);
});

 

 

Share this post


Link to post
Share on other sites
Posted (edited)

Hello, I have the same issue (using C#).

Any workaround? Or shall I just move to node.js which seems better maintained?

 

Thanks ;)

Edited by Jorhoto

Share this post


Link to post
Share on other sites
Posted (edited)

Render and save health in variables.

 

For example in JS:

var lastHealth = 0;
const localPlayer = mp.players.local;

mp.events.add('render',  function() {
    var healthLoss = 0;
    if(lastHealth != localPlayer.getHealth()) {
        healthLoss = lastHealth - localPlayer.getHealth();
        lastHealth = localPlayer.getHealth();
    }
    if(healthLoss > 0) {
        // your code
    }
});

 

Edited by Legend

Share this post


Link to post
Share on other sites
Posted (edited)

Ok, so the workaround is to fabricate yourself the event.

Thanks ;)

Edited by Jorhoto

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.