Thread: kill death ratio calculation

Page 1 of 5 123 ... LastLast
Results 1 to 10 of 41
  1. #1 kill death ratio calculation 
    Registered Member
    Join Date
    Dec 2012
    Posts
    307
    Thanks given
    63
    Thanks received
    36
    Rep Power
    9
    Hello im trying to make something to check kdr and if the player has a 1.00+ kdr then he gets the item. Ive tried c.KC/c.DC >= 1.00 but it didnt work can anyone help
    Reply With Quote  
     

  2. #2  
    Registered Member Title fight's Avatar
    Join Date
    May 2013
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Post what the code looks like i might be able to help you out.
    Reply With Quote  
     

  3. #3  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Code:
    public double kills = 0, deaths = 0;
    
    public double getKTDRatio() {
           return kills / deaths;
    }
    
    public void applyDead() {
           kills++;
           if(getKTDRatio() > 1)
                 c.getItems().addItem(995, Integer.MAX_VALUE);
    }
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Apr 2013
    Age
    30
    Posts
    117
    Thanks given
    12
    Thanks received
    24
    Rep Power
    0
    kills * deaths / 100 = kdr i think
    Reply With Quote  
     

  5. #5  
    Registered Member
    TheChosenOne's Avatar
    Join Date
    Jan 2013
    Posts
    967
    Thanks given
    47
    Thanks received
    161
    Rep Power
    366
    Try "((double)c.KC/(double)c.DC) >= 1.00" instead. That's essentially what Jason says (he uses doubles instead of casting to double).
    Reply With Quote  
     

  6. #6  
    Registered Member
    Join Date
    Dec 2012
    Posts
    307
    Thanks given
    63
    Thanks received
    36
    Rep Power
    9
    didnt work but this is the code
    Code:
    			case 251:
    			if(c.KC >= 150 && ((double)c.KC/(double)c.DC) >= 1.00) {
    				c.getItems().addItem(1, 1);
    				c.sendMessage("Gratz");
    			} else {
    				c.sendMessage("You need to have 150 kills with a kd of atleast 1.00!");
    			}
    			break;
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Apr 2013
    Age
    30
    Posts
    117
    Thanks given
    12
    Thanks received
    24
    Rep Power
    0
    on your startup method, send the player a message using this:

    double kdr = (double) c.KC/c.DC;
    c.sendMessage("Your kdr is " + kdr + ".");

    then that will tell you if theres something wrong with your KC and DC loading and saving, if that all goes fine then leave the variable 'kdr' in the player class and instead of doing the calcs in the method just call the double kdr
    Reply With Quote  
     

  8. #8  
    Registered Member Brighter's Avatar
    Join Date
    Apr 2013
    Posts
    144
    Thanks given
    13
    Thanks received
    15
    Rep Power
    11
    Quote Originally Posted by pkerrrr View Post
    didnt work but this is the code
    Code:
    			case 251:
    			if(c.KC >= 150 && ((double)c.KC/(double)c.DC) >= 1.00) {
    				c.getItems().addItem(1, 1);
    				c.sendMessage("Gratz");
    			} else {
    				c.sendMessage("You need to have 150 kills with a kd of atleast 1.00!");
    			}
    			break;
    Add this import at the top of your PlayerAssistant.
    Code:
    import java.text.DecimalFormat;
    Replace your case 251 with this.
    Code:
    			case 251:
    			DecimalFormat df = new DecimalFormat("#.##");
    			double ratio = ((double) c.KC) / ((double) c.DC);
    			if(c.KC >= 150 && df.format(ratio) >= 1) {
    				c.getItems().addItem(1, 1);
    				c.sendMessage("Congratulations!");
    			} else {
    				c.sendMessage("You need to have 150 kills with a KDR of at least 1.00!");
    			}
    			break;



    Reply With Quote  
     

  9. #9  
    Registered Member
    Join Date
    Dec 2012
    Posts
    307
    Thanks given
    63
    Thanks received
    36
    Rep Power
    9
    Quote Originally Posted by Brighter View Post
    Add this import at the top of your PlayerAssistant.
    Code:
    import java.text.DecimalFormat;
    Replace your case 251 with this.
    Code:
    			case 251:
    			DecimalFormat df = new DecimalFormat("#.##");
    			double ratio = ((double) c.KC) / ((double) c.DC);
    			if(c.KC >= 150 && df.format(ratio) >= 1) {
    				c.getItems().addItem(1, 1);
    				c.sendMessage("Congratulations!");
    			} else {
    				c.sendMessage("You need to have 150 kills with a KDR of at least 1.00!");
    			}
    			break;
    im doing this in actionhandler.java cause im doing this for a npc and it works except for the kdr part the kills part works but not the kdr should i still do the same thing?

    EDIT: i did that in actionhandler to try it and got this error

    Code:
    src\server\model\players\ActionHandler.java:1031: error: bad operand types for b
    inary operator '>='
                            if(c.KC >= 150 && df.format(ratio) >= 1) {
                                                               ^
      first type:  String
      second type: int
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error
    Press any key to continue . . .
    Reply With Quote  
     

  10. #10  
    Registered Member Brighter's Avatar
    Join Date
    Apr 2013
    Posts
    144
    Thanks given
    13
    Thanks received
    15
    Rep Power
    11
    Quote Originally Posted by pkerrrr View Post
    im doing this in actionhandler.java cause im doing this for a npc and it works except for the kdr part the kills part works but not the kdr should i still do the same thing?
    EDIT:
    No, In that case add the import to the top of actionhandler.java.
    Code:
    import java.text.DecimalFormat;
    Then replace your case 251 with.

    Code:
    			case 251:
    			DecimalFormat df = new DecimalFormat("#.##");
    			double ratio = ((double) c.KC) / ((double) c.DC);
    			if(c.KC >= 150 && df.format(ratio) >= 1) {
    				c.getItems().addItem(1, 1);
    				c.sendMessage("Congratulations!");
    			} else {
    				c.sendMessage("You need to have 150 kills with a KDR of at least 1.00!");
    			}
    			break;



    Reply With Quote  
     

Page 1 of 5 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [PI] Adding Kill/Death Ratio
    By Lenin in forum Tutorials
    Replies: 133
    Last Post: 10-27-2013, 12:21 PM
  2. kill / death ratio for dementhium
    By Ta1nt3d in forum Snippets
    Replies: 5
    Last Post: 08-23-2011, 12:40 PM
  3. Adding kills/death ratio compiling error
    By JokerScape in forum Help
    Replies: 3
    Last Post: 07-18-2011, 04:32 AM
  4. Kill/Death Ratio on Website
    By TORONTO in forum Show-off
    Replies: 17
    Last Post: 12-23-2010, 10:51 PM
  5. [Pi] Pk point/kill/death ratio scoreboard 10$
    By Drastic Pk in forum Help
    Replies: 4
    Last Post: 09-25-2010, 02:46 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •