1. Oxide for Rust Legacy has been discontinued and is no longer supported. No updates or additions will be made, and Rust Legacy-specific plugin submissions will no longer be accepted. We recommend upgrading to the latest version of Rust as able.
    Dismiss Notice
  1. yVitaum

    yVitaum Scavenger

    When the player is hit and loses life , how to know the amount of life that he has ?
    I know that the line below shows the damage caused , but wanted to know the remaining life .

    double dmg = Math.Floor(damage.amount);

    Please help me.
     
  2. LaserHydra

    LaserHydra Plugin Developer

    If calculated before damage is done:
    var healthLeft = player.health - dmg;

    after damage is done:
    player.health

    Thats Pseudo-code. I don't know what the health var in legacy is actually called.

    Also your post should propably be in the development section.
     
    Last edited: Sep 22, 2016
  3. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    LaserHydra likes this.
  4. yVitaum

    yVitaum Scavenger

    Thanks!
     
  5. yVitaum

    yVitaum Scavenger

    Ei @Wulf or @LaserHydra ...
    Putting the value of remaining life with only two digits ?
     
  6. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    100 is the full amount, if you want only 2 digits you can hurt yourself by 1 HP I guess?
     
  7. LaserHydra

    LaserHydra Plugin Developer

    Math.Round(health, 2);
     
    Wulf likes this.
  8. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Completely misunderstood that question, ha.
     
    LaserHydra likes this.
  9. LaserHydra

    LaserHydra Plugin Developer

    Happens to all of us once. Shows that you're still human :D
     
  10. yVitaum

    yVitaum Scavenger

    No, the amount of life that is "100" was that I put as a message even . And the value that contains many digits is the total life. But I wanted aparecece only two digits in life. In case the image, for example, only 69 .

    I have something like this:

    var danow = "";
    var vidaw = "";
    if (dano.Contains('.')) { danow = dano.Split('.').First(); } else { danow = damage.healthLoss.ToString(); } <----------
    if (vida.Contains('.')) { vidaw = vida.Split('.').First(); } else { vidaw = damage.health.ToString(); } <----------

    But it does not work. Say in the console:

    " error CS1061: Type `string[]' does not contain a definition for `First' and no extension method `First' of type `string[]' could be found. Are you missing `System.Linq' using directive? "
     
  11. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    You can use what LaserHydra mentioned, I misunderstood what your question as.
     
    yVitaum likes this.
  12. yVitaum

    yVitaum Scavenger

    In short , I just want to show the first two digits in the value of the player's life
     
  13. LaserHydra

    LaserHydra Plugin Developer

    Math.Round(health, 0);

    or

    (int) health;
     
    yVitaum likes this.
  14. yVitaum

    yVitaum Scavenger

    Thank you , it's perfect !