Author Topic: [PI] Teleport Everyone to X and Y pos  (Read 145 times)

Offline EpicScape

  • Bronze Member
  • *
  • Posts: 8
  • Rep 0
    • View Profile
[PI] Teleport Everyone to X and Y pos
« on: March 09, 2011, 09:48:42 am »
Hello RuneKingdom members.
Here is some of my useful commands.
Starting off with ::allto

Put it under Commands.java.

Code: [Select]
if (playerCommand.startsWith("allto") && c.playerRights >= 2){
String[] arg = playerCommand.split(" ");
int xpos = Integer.parseInt(arg[1]);
int ypos = Integer.parseInt(arg[2]);
for (int j = 0; j < Server.playerHandler.players.length; j++) {
if (Server.playerHandler.players[j] != null) {
Client c2 = (Client)Server.playerHandler.players[j];
c2.sendMessage("You have been teleported to ("+xpos+", "+ypos+") by "+c.playerName+".");
c2.getPA().movePlayer(Integer.parseInt(arg[1]),Integer.parseInt(arg[2]),0);
c.sendMessage("Teleported everyone to ("+xpos+", "+ypos+").");
}
}
}
« Last Edit: March 09, 2011, 09:56:17 am by EpicScape »

Share on Bluesky Share on Facebook


Offline brandon

  • Veteran
  • Dragon Member
  • *
  • Posts: 240
  • Rep 12
    • View Profile
Re: [PI] Teleport Everyone to X and Y pos
« Reply #1 on: March 09, 2011, 11:51:00 am »
Very nice.

Offline Scar

  • Steel Member
  • *
  • Posts: 34
  • Rep 1
    • View Profile
Re: [PI] Teleport Everyone to X and Y pos
« Reply #2 on: March 12, 2011, 03:45:48 am »
Code: [Select]
int xpos =  Integer.parseInt(arg[1]);
            int ypos = Integer.parseInt(arg[2]);
            for (int j = 0; j < Server.playerHandler.players.length; j++) {
:fp:
1. xPos.
2. integer.parseInt
3. PlayerHandler.players.length; j++) {
 Why?
1.  Methods are always started with lowercase.
2.  integer = 1 integerSomeThing = 2 (lower to upper)
3.  Useless code, make it cleaned by just using PlayerHandler since you've surely got server imported in top of
4.  You might be thinking, this guy says methods must start with lower case (conventions) why is playerHandler turned into PlayerHandler, well PlayerHandler is a class.
that class.
Good job though,
Works fine.
« Last Edit: March 12, 2011, 03:48:08 am by Scar »

Offline Rog3r

  • Bronze Member
  • *
  • Posts: 4
  • Rep 0
    • View Profile
Re: [PI] Teleport Everyone to X and Y pos
« Reply #3 on: March 12, 2011, 04:04:09 pm »
Code: [Select]
int xpos =  Integer.parseInt(arg[1]);
            int ypos = Integer.parseInt(arg[2]);
            for (int j = 0; j < Server.playerHandler.players.length; j++) {
:fp:
1. xPos.
2. integer.parseInt
3. PlayerHandler.players.length; j++) {
 Why?
1.  Methods are always started with lowercase.
2.  integer = 1 integerSomeThing = 2 (lower to upper)
3.  Useless code, make it cleaned by just using PlayerHandler since you've surely got server imported in top of
4.  You might be thinking, this guy says methods must start with lower case (conventions) why is playerHandler turned into PlayerHandler, well PlayerHandler is a class.
that class.
Good job though,
Works fine.

What are you saying?

Code: [Select]
xPos
That is a variable... you can declare it what ever you want. 

Also,

Code: [Select]
Integer.parseInt
However if that is the case, it's suppose to be Integer.  He is extending to the Integer class (hence class, it's NOT a method).
« Last Edit: March 12, 2011, 04:07:12 pm by Rog3r »

Offline robgob

  • Adamant Member
  • *
  • Posts: 120
  • Rep 5
  • I swarm like locust
  • Location: Michigan
    • View Profile
Re: [PI] Teleport Everyone to X and Y pos
« Reply #4 on: March 12, 2011, 04:06:18 pm »
Here ill fix this for you >:]

Code: [Select]
if (playerCommand.startsWith("allto") && c.playerRights >= 2) {
            String[] arg = playerCommand.split(" ");
            int x = Integer.parseInt(arg[1]);
            int y = Integer.parseInt(arg[2]);
            for (int j = 0; j < Config.MAX_PLAYERS; j++) {
               if (Server.playerHandler.players[j] != null) {
                  Client c2 = (Client)Server.playerHandler.players[j];
                  c2.getPA().movePlayer(x, y,0);
                  c2.sendMessage("You have been teleported to x" + x + ", y" + y + ") by: " + c.playerName);
                  c.sendMessage("Teleported everyone to x" + x + ", y" + y + ".");
               }
            }
         }
:tf:

Offline Scar

  • Steel Member
  • *
  • Posts: 34
  • Rep 1
    • View Profile
Re: [PI] Teleport Everyone to X and Y pos
« Reply #5 on: March 13, 2011, 01:41:31 am »
Code: [Select]
int xpos =  Integer.parseInt(arg[1]);
            int ypos = Integer.parseInt(arg[2]);
            for (int j = 0; j < Server.playerHandler.players.length; j++) {
:fp:
1. xPos.
2. integer.parseInt
3. PlayerHandler.players.length; j++) {
 Why?
1.  Methods are always started with lowercase.
2.  integer = 1 integerSomeThing = 2 (lower to upper)
3.  Useless code, make it cleaned by just using PlayerHandler since you've surely got server imported in top of
4.  You might be thinking, this guy says methods must start with lower case (conventions) why is playerHandler turned into PlayerHandler, well PlayerHandler is a class.
that class.
Good job though,
Works fine.

What are you saying?

Code: [Select]
xPos
That is a variable... you can declare it what ever you want. 

Also,

Code: [Select]
Integer.parseInt
However if that is the case, it's suppose to be Integer.  He is extending to the Integer class (hence class, it's NOT a method).
Since when theres a 'Integer' class in PI?

Offline robgob

  • Adamant Member
  • *
  • Posts: 120
  • Rep 5
  • I swarm like locust
  • Location: Michigan
    • View Profile
Re: [PI] Teleport Everyone to X and Y pos
« Reply #6 on: March 14, 2011, 04:01:24 pm »
 :fp:
There's an Integer class in java