RuneScape 2 Development > Server Tutorials

[639] Kill/Death Ratio with saving and command [639]

(1/2) >>>

Eclipse639:
So basically I'm gonna be helping you add a new buffer to be saved in your player files, which will be your KDR, Aswell as a new command to Show Off you leet skills

player.java
add this near the top

--- Code: --- private double pvpKills = 0;
private double pvpDeaths = 0;

public int getPvpKills() {
return (int) pvpKills;
}
public int getPvpDeaths() {
return (int) pvpDeaths;
}

public void increasePvpKills() {
pvpKills++;
}
public void increasePvpDeaths() {
pvpDeaths++;
}
public double getKDR() {
if (pvpKills > pvpDeaths) {
if (pvpDeaths == 0) return 0;
return pvpKills / pvpDeaths;
}
if (pvpDeaths > pvpKills) {
if (pvpKills == 0) return 0;
return 0 -(pvpKills / pvpDeaths);
}
return 0;
}
--- End code ---

Somewhere in your buffers

--- Code: --- if (buffer.remaining() > 0) {
pvpKills = buffer.getInt();
}
if (buffer.remaining() > 0) {
pvpDeaths = buffer.getInt();
}
--- End code ---

Search for

--- Code: --- buffer.writeByte(starter ? 1 : 0);
buffer.writeShort(settings.getSpecialAmount());
--- End code ---

Underneath that add:

--- Code: --- buffer.writeInt((int) pvpKills);
buffer.writeInt((int) pvpDeaths);
--- End code ---

Search for

--- Code: --- public void sendDead() {
/*if (true) {
              hitPoints = 990;
              return;
          }*/
          if (dead) {
          return;
          }
--- End code ---
Under that add:

--- Code: ---  final Mob last = player.getCombatExecutor().getLastAttacker();
  if (last != null) {
  player.getCombatExecutor().setLastKiller(last);
  if (last.isPlayer()) {
  player.increasePvpDeaths();
  final Player lp = (Player)last;
  World.getWorld().submit(new Tick(2 + player.getDeathDelay()) {
  @Override
  public void execute() {
  lp.sendMessage("You now have " + lp.getPvpKills() + " kills!");
  lp.sendMessage("Your kill/death ratio is " + lp.getKDR());
  this.stop();
  }
  });
  }
  }
--- End code ---


CombatExecutor.java
add

--- Code: --- public Mob getLastKiller() {
return lastKiller;
}

public void setLastKiller(Mob killer) {
this.lastKiller = killer;
}
--- End code ---

Mob.java

--- Code: --- private final Map<Mob, Integer> enemyHits = new HashMap<Mob, Integer>();
--- End code ---

Add somewhere

--- Code: --- public Mob getKiller() {
Mob killer = null;
int mostDamage = 0;
for(Map.Entry<Mob, Integer> entry : enemyHits.entrySet()) {
if(entry.getValue() > mostDamage) {
killer = entry.getKey();
mostDamage = entry.getValue();
}
}
return killer;
}
--- End code ---

Save & close

Commands.java

--- Code: --- if (command[0].equalsIgnoreCase("kdr")) {
player.forceText("My Kill Death Ratio Is: Kills: " + player.getKDR());
player.sendMessage("Kills: " + player.getPvpKills() + "   Deaths: " + player.getPvpDeaths());
player.sendMessage("Kill/Death Ratio: " + player.getKDR());
}
if (command[0].equalsIgnoreCase("kills")) {
player.forceText("My Current Kills and Deaths are: Kills: " + player.getPvpKills() + "   Deaths: " + player.getPvpDeaths());
player.sendMessage("Kills: " + player.getPvpKills() + "   Deaths: " + player.getPvpDeaths());
player.sendMessage("Kill/Death Ratio: " + player.getKDR());
}
--- End code ---

Rep is not necessary but always appreciated.

QuestMaster 2K10:
First post!

wildskiller:

--- Quote from: QuestMaster 2K10 on December 22, 2011, 10:09:23 AM ---First post!

--- End quote ---

This isn't download section.

@Eclipse Nice  :D Maybe you might release a pk system

Rodgerwilco:
When you will you ever have 1.## kills?


--- Code: ---        private double pvpKills = 0;
--- End code ---

Maybe if your calculating k/d ratio I can see the use of double in Player class. Keep it in the command class...

Nookumdip:
Compiling RS2Server...
src\org\dementhium\model\player\Skills.java:99: cannot find symbol
                                  World.getWorld().submit(new Tick(2 + player.ge
tDeathDelay()) {
                                                                             ^
  symbol:   method getDeathDelay()
  location: class Player
src\org\dementhium\model\player\Skills.java:99: operator + cannot be applied to
int,getDeathDelay
                                  World.getWorld().submit(new Tick(2 + player.ge
tDeathDelay()) {
                                                                   ^
src\org\dementhium\model\player\Skills.java:99: constructor Tick in class Tick c
annot be applied to given types
                                  World.getWorld().submit(new Tick(2 + player.ge
tDeathDelay()) {
                                                          ^
  required: int
  found: <null>
src\org\dementhium\model\player\Skills.java:99: constructor Tick in class Tick c
annot be applied to given types
                                  World.getWorld().submit(new Tick(2 + player.ge
tDeathDelay()) {

               ^
  required: int
  found: no arguments
src\org\dementhium\model\player\Skills.java:110: last is already defined in send
Dead()
          Mob last = player.getCombatExecutor().getLastAttacker();
              ^
src\org\dementhium\model\combat\CombatExecutor.java:60: cannot find symbol
                return lastKiller;
                       ^
  symbol:   variable lastKiller
  location: class CombatExecutor
src\org\dementhium\model\combat\CombatExecutor.java:64: cannot find symbol
                this.lastKiller = killer;
                    ^
  symbol:   variable lastKiller
  location: class CombatExecutor
7 errors
Complete
Press any key to continue . . .

:[[

Navigation

[0] Message Index

[#] Next page

Go to full version
Powered by SMFPacks SEO Pro Mod |