This is a shitty little bit of code i wrote when trying to add Agility into rs2d,
I got it to auto move, though i need to figure some bits and bobs out first...
I added the crumbling wall in Falador as a test obstical and well... instead of going west the player walks north lol.
I wasnt realy sure what i was doing with the rs2d source as it gets a bit confusing...
This is based on Jim's RS2DBase Version 1.
First of all you need to make a new class in the net.varek.rs2d.content.skills and call it Agility, once done place all this in it;
Code:
package net.varek.rs2d.content.skills;
import net.varek.rs2d.model.*;
import net.varek.rs2d.packetbuilder.*;
/**
* Created by IntelliJ IDEA.
* User: Ian
* Date: 22-Jun-2008
* Time: 05:35:15
*
* @TODO Finish off and fix this fucker!
*/
public class Agility implements SkillConstants {
public static boolean do_obstical(int objectID, int objectX, int objectY, Player player) {
int reqlvl = 0;
int emote = 0;
int timer = 0;
int pathX =0, pathY = 0;
double xp = 0;
boolean isTeleport = false;
boolean wasRunning = false;
String message ="";
if(player.isRunning()){
player.setRunning(false);
wasRunning = true;
}
if(objectID == 2295){ // Log balance - gnome
timer = 8;
reqlvl = 1;
xp = 15;
pathX = 8;
pathY = 0;
emote = 762;
message = "You balance across the log.";
} else if(objectID == 11844){ // Crumbling wall - falador
timer = 3;
reqlvl = 1; //5
xp = 15;
pathX = 0;
pathY = -2;
emote = 882;
message = "You climb over the crumbling wall.";
} else return false;
if(player.getMaxStat(AGILITY) >= reqlvl){
player.addXP(xp, AGILITY);
player.getActionSender().sendMessage(message);
if(wasRunning)
player.setRunning(true);
if(isTeleport){
player.setLocation(Point.location(pathX, pathY), true);
isTeleport = false;
} else {
player.setObsticalTimer(timer);
player.setObsticalUse(true);
player.getPathHandler().addPoint(Point.location((player.getX()+pathX), (player.getY()+pathY)));
PlayerUpdate.changeDefaultAnimation(2, emote); //Is 1 walking emote?
}
} else {
player.getActionSender().sendMessage("You need a Agility level of "+reqlvl+" to do this obstical.");
}
return true;
}
}
Now open net.varek.rs2d.packethandler.ObjectAction and find;
Code:
@SuppressWarnings("unused")
static void handleFirstClick(Packet p, Player player, ActionSender sender){
int x = p.readLEShort();
int id = p.readShort();
int y = p.readShortA();
if(id == 2213){ //Bank booth
player.getActionSender().sendBagInterface(5292,5063);
player.getActionSender().sendResetInventory(5064);
}
}
and replace it with;
Code:
@SuppressWarnings("unused")
static void handleFirstClick(Packet p, Player player, ActionSender sender){
int x = p.readLEShort();
int id = p.readShort();
int y = p.readShortA();
if(Agility.do_obstical(id, x,y,player)) return;
if(id == 2213){ //Bank booth
player.getActionSender().sendBagInterface(5292,5063);
player.getActionSender().sendResetInventory(5064);
}
}
after that go into net.varek.rs2d.model.Player and add these methods and variables;
Code:
private int obsticalTimer = 0;
private boolean usingObstical = false;
Code:
public void setObsticalTimer(int time) {
this.obsticalTimer = time;
}
public int getObsticalTimer() {
return obsticalTimer;
}
public void setObsticalUse(boolean using) {
this.usingObstical = using;
}
public boolean getObsticalUse() {
return usingObstical;
}
Now once that is done, go to net.varek.rs2d.packetbuilder.PlayerUpdate
and find;
Code:
private final static int[] ANIMATION_INDICES = {
0x328, 0x337, 0x333, 0x334, 0x335, 0x336, 0x338
};
and replace it with this;
Code:
private static int[] ANIMATION_INDICES = {
0x328, 0x337, 0x333, 0x334, 0x335, 0x336, 0x338
};
public static void changeDefaultAnimation(int i, int changeTo){
ANIMATION_INDICES[i] = changeTo;
}
Now go into net.varek.rs2d.ClientUpdater and search for
Code:
//Reset NPC data
for(NPC n : npcs){
n.setSprite(-1); //needed this to stop them from moving every half second
}
underneath that add;
Code:
//Reset Agility
for(Player p : players) {
if(p.getObsticalTimer() > 0) {
p.setObsticalTimer(p.getObsticalTimer()-1);
}
if(p.getObsticalUse() && p.getObsticalTimer() == 0) {
PlayerUpdate.changeDefaultAnimation(1, 0x328);
}
}
I think that is all, remember this was just a test to see if i could get it working or not lol, and well i failed so i decided to give u all the code i had, maybe you can build it up from the ashes
