Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

calculate the ratio between the death and kills

Comments in 'Plugin Development' started by Praxthisnovcht, Feb 3, 2015.

  1. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    702
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    Yo guys,

    how could thy calculate a ratio between two things?
    like the Kills and Death


    ??
  2. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    You could subtract the deaths from the kills, or you could do what I do. A kill is worth 3 points and a death is worth 1 point.
  3. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    You'd probably have to store the number of kills and deaths in a database of some type and constantly keep an updated number for the ratio (kills/deaths and maybe rounded to the tenths place)
  4. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    702
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    How to have killed one gives 3 points? xD


    I want to make it simple: p
  5. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    PHP:
    $points $kills $deaths;
    Praxthisnovcht likes this.
  6. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    702
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    :)
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Define the word ratio, and you would find that you are looking for kills divided by deaths. So $kills / $deaths of course.
    iJoshuaHD, iksaku and Falk like this.
  8. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    But you will want to truncate or round that to a set amount of decimal places.
    iksaku likes this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    /**
     @param int $kills
     @param int $deaths
     @param int $digits default 3 decimal places

     @return string
     */
    function getKdRatio($kills$deaths$digits 3){
      if(
    $deaths === 0) return "N/A";
      
    $ratio = (string) round($kills $deaths$digits);
      return 
    rtrim($ratio" 0.");
    }
  10. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    702
    Plugins:
    4
    Minecraft User:
    PraxHellTag

    thank you !

Share This Page

Advertisement