Author Topic: [PI] My New Player Area Method [PI]  (Read 88 times)

Offline robgob

  • Adamant Member
  • *
  • Posts: 120
  • Rep 5
  • I swarm like locust
  • Location: Michigan
    • View Profile
[PI] My New Player Area Method [PI]
« on: March 10, 2011, 11:35:57 pm »
First add this class to your "world" folder in your sever(src\server\world):
name is Area.java
Code: [Select]
package server.world;

import java.util.Random;

public class Area {

int lowX;
int highX;
int lowY;
int highY;
Random rand;

public Area(int lowX, int lowY, int highX, int highY) {
this.lowX = lowX;
this.lowY = lowY;
this.highX = highX;
this.highY = highY;
}

public Tile getRandomTile() {
return new Tile(random(lowX, lowY), random(highX, highY));
}

public int random(int min, int max) {
return rand.nextInt(Math.abs(max - min)) + min;
}

public int getHX() {
return highX;
}

public int getHY() {
return highY;
}

public int getLY() {
return lowY;
}

public int getLX() {
return lowX;
}

}


Then open your Player.java and import this:
Code: [Select]
import server.world.Area;
then add these 2 methods below:
Code: [Select]

public boolean inArea(Area a) {
return (absX >= a.getLX() && absX <= a.getHX() && absY >= a.getLY() && absY <= a.getHY());
}

public boolean inArea(Area[] a) {
for (Area b : a) {
if (absX >= b.getLX() && absX <= b.getHX() && absY >= b.getLY() && absY <= b.getHY())
return true;
}
return false;
}

And that's it.

Examples:

Instead of having the methods:
Code: [Select]
public boolean inDuelArena() {
return ((absX > 3322 && absX < 3394 && absY > 3195 && absY < 3291) || (absX > 3311 && absX < 3323 && absY > 3223 && absY < 3248));
}
or
Code: [Select]
public boolean inFightCaves() {
return absX >= 2360 && absX <= 2445 && absY >= 5045 && absY <= 5125;
}

you would have these:
Code: [Select]
public Area[] duelArena = {
new Area(3322, 3195, 3394, 3291),
new Area(3311, 3223, 3323, 3248)};
public Area fightCave = new Area(2360, 5045, 2445, 5125);

and everywhere the method inFightCaves() and inDuelArena() are called they would now be:
Code: [Select]
inArea(fightCave)
and
inArea(duelArena)

Example for teleporting:
Code: [Select]
if (c.inArea(c.fightCave) || c.inArea(c.duelArena)) {
c.sendMessage("You cannot teleport away!");
return;
}
God-Wars Chambers:
Code: [Select]
public Area[] godChamber = {
new Area(2864, 5296, 2876, 5369), // Bandos
new Area(2824, 5296, 2842, 5308), // Armadyl
new Area(2889, 5258, 2907, 5276), // Saradomin
new Area(2918, 5318, 2936, 5331) // Zamorak
};


Have fun converting.



Bug Fixes
If you don't have Tile loading remove this from your Area.java
Code: [Select]
public Tile getRandomTile() {
return new Tile(random(lowX, lowY), random(highX, highY));
}

Share on Bluesky Share on Facebook


Offline brandon

  • Veteran
  • Dragon Member
  • *
  • Posts: 240
  • Rep 12
    • View Profile
Re: [PI] My New Player Area Method [PI]
« Reply #1 on: March 10, 2011, 11:42:30 pm »
Very nice Robgob.

Offline robgob

  • Adamant Member
  • *
  • Posts: 120
  • Rep 5
  • I swarm like locust
  • Location: Michigan
    • View Profile
Re: [PI] My New Player Area Method [PI]
« Reply #2 on: March 10, 2011, 11:49:05 pm »
thanks ^_^