-
Food Eating #508
Description: Create an accurate, fast, stable and reliable, Food class.
Assumed Knowledge: How to follow Instruction's.
How to change import's.
Tested Server: Palidino76's Framework.
Files/Classes modified: Player.Java, ItemSelect.Java.
Files/Classes added: Food.Java.
Difficulty: 1-2/10, With assumed knowledge.
Step 1:
Create a backup of your Server, and then create a new Class, preferably in your Content folder, otherwise you may have to edit your import's, call this new Class, Food.Java. Now paste this code below into the Class you have made.
[SPOIL]package Source.content;
import Source.model.Player;
import Source.util.Misc;
import Source.model.*;
import Source.Engine;
public class Food {
private Player p;
public Food(Player p) {
this.p = p;
}
private long timer = 0;
public void doFood(int id, int difference, String name, int itemSlot) {
if (System.currentTimeMillis() - timer >= 1630) {
p.combatDelay += 2;
p.requestAnim(829, 0);
p.updateHP(difference, true);
p.frames.sendMessage(p, "You eat the " +name+".");
p.frames.sendMessage(p, "It heals some health.");
Engine.playerItems.deleteItem(p, id, itemSlot, 1);
timer = System.currentTimeMillis();
}
}
public void eat(int id, int itemSlot) {
switch (id) {
case 385:
doFood(id, 20, "Shark", itemSlot);
break;
case 391:
doFood(id, 22, "Manta ray", itemSlot);
break;
}
}
}[/SPOIL]
Step 2:
Add the code below into Player.Java.
[SPOIL] private final transient Food food = new Food(this);
public Food getFood() {
return food;
}[/SPOIL]
Step 3:
Add the code below into ItemSelect.Java.
[SPOIL]p.getFood().eat(itemId, itemSlot);[/SPOIL]
Step 4:
Compile and you're done.
-
-
-
no need for a food instance for every player.
-
Clean, and nice, good job.
-
Hey I get an error when I do this, something about Cannot find symbol? :S
".\paladino76\rs2\players\Player.Java:662: cannot find symbol
symbol : class Food
location : class paladino76.rs2.players.Player
private final transient Food good = new Food<this>;
-
Add this into Player.java.
import paladino76.rs2.content.*;