PDA

View Full Version : [562] Fairy Rings Tutorial



Hope
June 7th, 2011, 18:25
Updated some conventions. Thanks David.
Alright so this is just something I put together really fast.

Note: I did this for fun and not for any profit whatsoever. Please don't flame my work, seeing as I'm learning.

Note: I didn't use the regular teleport method so that people can change the teleport graphics for the fairy teleport instead of using the ancients teleport or default one.

Put this in actionbuttonpackethandler.java


case 624: //Fairy rings
if (buttonId == 21) { //1st Plus
if (player.firstColumn >= 15) {
player.firstColumn = 15;
} else {
player.firstColumn++;
}
} else if (buttonId == 22) { //1st Subtract
if (player.firstColumn <= 0) {
player.firstColumn = 0;
} else {
player.firstColumn--;
}
} else if (buttonId == 23) { //2nd Plus
if (player.secondColumn >= 15) {
player.secondColumn = 15;
} else {
player.secondColumn++;
}
} else if (buttonId == 24) { //2nd Subtract
if (player.secondColumn <= 0) {
player.secondColumn = 0;
} else {
player.secondColumn--;
}
} else if (buttonId == 25) { //3rd Plus
if (player.thirdColumn >= 15) {
player.thirdColumn = 15;
} else {
player.thirdColumn++;
}
} else if (buttonId == 26) { //3rd Subtract
if (player.thirdColumn <= 0) {
player.thirdColumn = 0;
} else {
player.thirdColumn--;
}
} else if (buttonId == 69) { //Confirm
FairyRing.ringTele(player, player.firstColumn, player.secondColumn, player.thirdColumn);
}
break;


Make a new file in content, Name it FairyRing and put this into it


/**
*
* @author 'RuneUnited
*/
public final class FairyRing {

public static void ringTele (Player p , int firstColumn, int secondColumn, int thirdColumn) {
if(p.frozen > 0) {
p.getActionSender().sendMessage("You cannot use the fairyring when frozen!");
p.getWalkingQueue().reset();
return;
}
if(p.isTeleBlocked) {
p.sm("You cannot use the fairyring when teleblocked!");
return;
}

/**
* START OF SEQUENCES
*/
if (p.firstColumn == 1 && p.secondColumn == 1 && p.thirdColumn == 1) { //First,Second,Third stand for each number in the interface.
p.getActionSender().sendCloseInterface();
p.resetAttack();
fairyTeleport(p, 2671 ,2593, 0, 0);
} else {
p.sm("That is not a teleport option!");
return;
}
}

private static void fairyTeleport (final Player p, int x, int y, final int height, int distance) {
p.getActionSender().removeTab1();
if(p.SafeZone()) {
p.Attacking = false;
if (distance > 0) {
int type = Misc.random(1);
int offset = Misc.random(distance); //If you don't want offset, just take the distance thing out.
if (type == 1) {
x += -offset;
} else {
x += offset;
}
type = Misc.random(1);
offset = Misc.random(distance);
if (type == 1) {
y += -offset;
} else {
y += offset;
}
}
final int endX = x;
final int endY = y;
p.getWalkingQueue().reset();
p.animate(8939, 0); //Place whatever fairy teleport emote & gfx you want
p.graphics(1681, 0);
World.getWorld().registerEvent(new Event(1800) {
public void execute() {
p.tele(endX, endY, height);
p.animate(8941, 0);//Place whatever fairy teleport emote & gfx you want
p.graphics(1681, 0);
p.getActionSender().sendCloseChatboxInterface();
p.getActionSender().removeTab();
p.getActionSender().sendCloseInterface();
this.stop();
}
});
}
}


public static void refresh(Player player) {
player.FirstColumn = 0;
player.SecondColumn = 0;
player.ThirdColumn = 0;

}
}


In actionsender.java above

if(player.starter == 0) {

Add..


FairyRing.refresh(player);


In player.java add


public int firstColumn = 0, secondColumn = 0, thirdColumn = 0;


Oh, and don't forget to add the imports to actionbutton and actionsender:


import com.rs2hd.content.FairyRing;


How it works:
-This works with interface 624 (Fairy Ring Interface)
- Simple send the interface by using an object or a command to get the interface open.

How to edit more number teleport sequences:
In FairyRing.java find where it says START OF SEQUENCES which I added in the file
-Where it says First column, second, third. They stand for each of the numbers on the interface. So as you see on my example, if a player puts 1, 1, 1 on the interface then it will teleport them to that location i have set. Just simply copy the expression for any other places you want.

Edit the fairy emote and gfx teleport near the bottom under private static void fairyTeleport.

-Any Questions, just drop them by.

David
June 7th, 2011, 18:51
It's a pretty nice tutorial but:



In player.java add


public int FirstColumn = 0;
public int SecondColumn = 0;
public int ThirdColumn = 0;


should be

public int firstColumn = 0, secondColumn = 0, thirdColumn = 0;

Other then that, I see your making progress ;)

EDIT: Oh and

if(buttonId == 22) { //1st Subtract
if(player.FirstColumn <= 0) {
player.FirstColumn = 0;
} else {
player.FirstColumn -= 1;
}
}


should be


if(buttonId == 22) { //1st Subtract
if(player.FirstColumn <= 0) {
player.FirstColumn = 0;
} else {
player.FirstColumn -= 1;
}
}


The rest also ofcourse, and the int's renamed like I said.

Hope
June 7th, 2011, 18:59
Yeah you know, I forget sometimes about the little things, but sometimes the little things are the big things :P Anyway, thanks David.

Josh
June 7th, 2011, 19:03
Look good man. :P

David
June 7th, 2011, 19:04
Yeah you know, I forget sometimes about the little things, but sometimes the little things are the big things :P Anyway, thanks David.

Haha okay, you might want to start using an IDE then, since it'll mostly check the things that you forgot. I prefer Eclipse myself, but NetBeans is very good too.

Cjay0091
June 7th, 2011, 19:11
It's a pretty nice tutorial but:



should be

public int firstColumn = 0, secondColumn = 0, thirdColumn = 0;

Other then that, I see your making progress ;)

EDIT: Oh and

if(buttonId == 22) { //1st Subtract
if(player.FirstColumn <= 0) {
player.FirstColumn = 0;
} else {
player.FirstColumn -= 1;
}
}


should be


if(buttonId == 22) { //1st Subtract
if(player.FirstColumn <= 0) {
player.FirstColumn = 0;
} else {
player.FirstColumn -= 1;
}
}


The rest also ofcourse, and the int's renamed like I said.


JVM takes the code the same anyways. so there is no real difference between

this



private int i = 0;
private int j = 0;


and this



private int i = 0, j = 0;

SkrilleX
June 7th, 2011, 19:51
Nice job man keep it up :)

David
June 7th, 2011, 19:53
JVM takes the code the same anyways. so there is no real difference between

this



private int i = 0;
private int j = 0;


and this



private int i = 0, j = 0;


I know, but my point was about the first letter capitalized.

Josh
June 7th, 2011, 19:57
It's called coventions. :s

SkrilleX
June 7th, 2011, 20:10
It's called coventions. :s

Whos need conventions lmfao
*sarcasm*

Steve
June 7th, 2011, 20:14
You forgot to tell him that the decrement operator exists David,

if(buttonId == 22) { //1st Subtract
if(player.FirstColumn <= 0) {
player.FirstColumn = 0;
} else {
player.FirstColumn--;
}
}

SkrilleX
June 7th, 2011, 20:20
Hey dude i saw your forum when i got board and i saw you needed help with the show-occ and the web client, i can make you a webclient if you want me to and i can take the showocc out its pretty easy ? Unless you know how ?

David
June 7th, 2011, 20:22
You forgot to tell him that the decrement operator exists David,

if(buttonId == 22) { //1st Subtract
if(player.FirstColumn <= 0) {
player.FirstColumn = 0;
} else {
player.FirstColumn--;
}
}


Yes, and the increment operator ofcourse.

Hope
June 7th, 2011, 21:10
Yes, and the increment operator ofcourse.

I knew that it existed, but I obviously haven't learned to think outside the box yet :P



Hey dude i saw your forum when i got board and i saw you needed help with the show-occ and the web client, i can make you a webclient if you want me to and i can take the showocc out its pretty easy ? Unless you know how ?


I have a webclient?

Vesta Main
June 7th, 2011, 21:22
Good job :)

SkrilleX
June 7th, 2011, 21:26
I knew that it existed, but I obviously haven't learned to think outside the box yet :P

I have a webclient?
I know i just posted i was on the wrong tab :P
Sorry man,my bad i edited the post

Nouish
June 7th, 2011, 22:30
case 624: //Fairy rings
if (buttonId == 21) { //1st Plus
if (player.FirstColumn >= 15) {
player.FirstColumn = 15;
} else {
player.FirstColumn += 1;
}
} else if (buttonId == 22) { //1st Subtract
if (player.FirstColumn <= 0) {
player.FirstColumn = 0;
} else {
player.FirstColumn -= 1;
}
} else if (buttonId == 23) { //2nd Plus
if (player.SecondColumn >= 15) {
player.SecondColumn = 15;
} else {
player.SecondColumn += 1;
}
} else if (buttonId == 24) { //2nd Subtract
if (player.SecondColumn <= 0) {
player.SecondColumn = 0;
} else {
player.SecondColumn -= 1;
}
} else if (buttonId == 25) { //3rd Plus
if (player.ThirdColumn >= 15) {
player.ThirdColumn = 15;
} else {
player.ThirdColumn += 1;
}
} else if (buttonId == 26) { //3rd Subtract
if (player.ThirdColumn <= 0) {
player.ThirdColumn = 0;
} else {
player.ThirdColumn -= 1;
}
} else if (buttonId == 69) { //Confirm
FairyRing.ringTele(player, player.FirstColumn, player.SecondColumn, player.ThirdColumn);
}
break;

Hope
June 7th, 2011, 22:46
Thanks Nouish, Just updated it.

David
June 8th, 2011, 10:51
case 624: //Fairy rings
if (buttonId == 21) { //1st Plus
if (player.firstColumn >= 15) {
player.firstColumn = 15;
} else {
player.firstColumn++;
}
} else if (buttonId == 22) { //1st Subtract
if (player.firstColumn <= 0) {
player.firstColumn = 0;
} else {
player.firstColumn--;
}
} else if (buttonId == 23) { //2nd Plus
if (player.secondColumn >= 15) {
player.secondColumn = 15;
} else {
player.secondColumn++;
}
} else if (buttonId == 24) { //2nd Subtract
if (player.secondColumn <= 0) {
player.secondColumn = 0;
} else {
player.secondColumn--;
}
} else if (buttonId == 25) { //3rd Plus
if (player.thirdColumn >= 15) {
player.thirdColumn = 15;
} else {
player.thirdColumn++;
}
} else if (buttonId == 26) { //3rd Subtract
if (player.thirdColumn <= 0) {
player.thirdColumn = 0;
} else {
player.thirdColumn--;
}
} else if (buttonId == 69) { //Confirm
FairyRing.ringTele(player, player.firstColumn, player.secondColumn, player.thirdColumn);
}
break;
That's one


package com.rs2hd.content;

import com.rs2hd.model.Player;
import com.rs2hd.util.Misc;
import com.rs2hd.model.World;
import com.rs2hd.model.Location;
import com.rs2hd.event.*;

/**
*
* @author 'RuneUnited
*/
public final class FairyRing {

public static void ringTele (Player p , int firstColumn, int secondColumn, int thirdColumn) {
if(p.frozen > 0) {
p.getActionSender().sendMessage("You cannot use the fairyring when frozen!");
p.getWalkingQueue().reset();
return;
}
if(p.isTeleBlocked) {
p.sm("You cannot use the fairyring when teleblocked!");
return;
}

/**
* START OF SEQUENCES
*/
if (p.firstColumn == 1 && p.secondColumn == 1 && p.thirdColumn == 1) { //First,Second,Third stand for each number in the interface.
p.getActionSender().sendCloseInterface();
p.resetAttack();
fairyTeleport(p, 2671 ,2593, 0, 0);
} else {
p.sm("That is not a teleport option!");
return;
}
}

private static void fairyTeleport (final Player p, int x, int y, final int height, int distance) {
p.getActionSender().removeTab1();
if(p.SafeZone()) {
p.Attacking = false;
if (distance > 0) {
int type = Misc.random(1);
int offset = Misc.random(distance); //If you don't want offset, just take the distance thing out.
if (type == 1) {
x += -offset;
} else {
x += offset;
}
type = Misc.random(1);
offset = Misc.random(distance);
if (type == 1) {
y += -offset;
} else {
y += offset;
}
}
final int endX = x;
final int endY = y;
p.getWalkingQueue().reset();
p.animate(8939, 0); //Place whatever fairy teleport emote & gfx you want
p.graphics(1681, 0);
World.getWorld().registerEvent(new Event(1800) {
public void execute() {
p.tele(endX, endY, height);
p.animate(8941, 0);//Place whatever fairy teleport emote & gfx you want
p.graphics(1681, 0);
p.getActionSender().sendCloseChatboxInterface();
p.getActionSender().removeTab();
p.getActionSender().sendCloseInterface();
this.stop();
}
});
}
}


public static void refresh(Player player) {
player.FirstColumn = 0;
player.SecondColumn = 0;
player.ThirdColumn = 0;

}
}
That's two

public int firstColumn = 0;
public int secondColumn = 0;
public int thirdColumn = 0;
or

public int firstColumn = 0, secondColumn = 0, thirdColumn = 0;

And there you go

The Only Cj
June 12th, 2011, 15:18
No point giving alternatives on how to put the code, cause either way, it still works -_- these sort of things cause flame, just let the guy post what hes posting, no need to get involved in his progress. Nice work RuneUnited.!