Post what the code looks like i might be able to help you out.
|
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
Post what the code looks like i might be able to help you out.
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); }
kills * deaths / 100 = kdr i think
Try "((double)c.KC/(double)c.DC) >= 1.00" instead. That's essentially what Jason says (he uses doubles instead of casting to double).
didnt work but this is the codeCode: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;
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
Add this import at the top of your PlayerAssistant.
Replace your case 251 with this.Code:import java.text.DecimalFormat;
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 . . .
EDIT:
No, In that case add the import to the top of actionhandler.java.
Then replace your case 251 with.Code:import java.text.DecimalFormat;
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;
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |