PDA

View Full Version : Making a reward chest :)



tedhead2
January 18th, 2011, 00:54
This is a tutorial(or snip?) on making a reward chest.

In Object1PacketHandler.Java, add this.

NOTE: You can use any object you want, i used an open chest.



case 104: //reward chest, made by tedhead2(jordan) of runelocus!
int [] gifts = {1050, 1038, 1040, 1042, 1044, 1046, 1048, 113, 114, 995, 1540, 995, 995, 995, 995, 995, 995, 1540, 995, 995,

995, 995, 995, 1540, 995, 995, 995, 995, 995, 1540, 995, 995, 995, 995, 995, 1540, 995, 995, 995, 995, 995, 1540, 995, 995, 995, 995, 995,

1540, 995, 995, 995, 995, 995, 1540, 995, 995, 995, 995}; //Rares and A LOT of random crap
int i = Misc.random(60);
if(player.getInventory().contains(1464)){
player.getInventory().deleteItem(1464, 1);
player.getInventory().addItem(gifts[i], 1);
player.sm("Have fun with your new item!");
player.prizechest += 1;
player.sm("You have opened this chest " + player.prizechest + " times!");
} else {
player.sm("You need a ticket to search this chest!");
player.sm("Tickets are rewards from admins for being active!");
}
break;


Where is says "player.prizechest" you can add that if you want, i just did that to tell you have many times you have opened the chest, if you want to keep it, in player.java, add


public int prizechest;

The gifts array is so long becuase you dont want them to get a rare 100% of the time.

The item 1464 is a archery ticket, this can also be changed or completely removed.

Bob
January 18th, 2011, 00:55
Great idea! I hope to use this on my server!

tedhead2
January 18th, 2011, 00:57
Great idea! I hope to use this on my server!

thank you, i'm glad people appreciate my work :)

Bob
January 18th, 2011, 00:58
thank you, i'm glad people appreciate my work :)

First time I've seen your work, mind linking me to some other cool 317 features?

tedhead2
January 18th, 2011, 00:58
First time I've seen your work, mind linking me to some other cool 317 features?

*facepalm* this is 562, not 317.

I do not code 317, and probably never will.

Bob
January 18th, 2011, 01:00
*facepalm* this is 562, not 317.

I do not code 317, and probably never will.

Lol, fuck me, xD. Eh i could try to convert this to 317.

Emily
January 18th, 2011, 01:02
Your code makes no sense. You don't have 60 items declared in that array list you created. So why do you have this?

int i = Misc.random(60);


Curious as why you would have this;



player.prizechest += 1;


Why does it matter how many times you've opened it. You are just adding more to your player.java, and creating larger character files.



public int prizechest;


That makes it save to the player file.



public transient int prizeChest;


That is using proper java declaration. And makes it not save. Although everytime you log out and back in, it will set it to 0. Although I don't see why that part is needed at all.

tedhead2
January 18th, 2011, 01:02
Lol, fuck me, xD. Eh i could try to convert this to 317.

"(525+) Server Development"

not hard to read, and it isn't hidden XD

@Emily:

Emily, "int i" is what choses the random item, tyvm.

Bob
January 18th, 2011, 01:04
"(525+) Server Development"

not hard to read, and it isn't hidden XD

Didn't find this in the 500+ forum, found it on the latest posts.

Emily
January 18th, 2011, 01:15
@Emily:

Emily, "int i" is what choses the random item, tyvm.

You didn't make this then, you apparently just looked at a source already using this and reconstructed it. You don't understand the code you are using, nor can provide an adequate answer to my full question.

Since you won't know, I'll just explain it.

Your array, is a list of something, in this case items. You call this by arrayName[placeInArray]

The array starts at 0, and goes up infinite.

In your case (didn't waste the time to count) you have like ~20/30 places in the array. So the highest value you can call if you want to get something from the array is arrayName[20/30].

Your Misc.random statement, randomly selects a value from 0 to what ever value you set the Misc.random to, in this case 60. So the array will add an item from anywhere from placeInArray 0 to placeInArray 60. But since you have no values greater then lets say 20/30, you will not receive a reward from the chest.

Your code at the end, is redundant and in my opinion pointless. Why does it matter how many times you open the chest. The larger your player files are, the longer it takes for the player to load, and the decrease in performance.

Divine-X
January 18th, 2011, 01:31
Your code makes no sense. You don't have 60 items declared in that array list you created. So why do you have this?

int i = Misc.random(60);


Curious as why you would have this;



player.prizechest += 1;


Why does it matter how many times you've opened it. You are just adding more to your player.java, and creating larger character files.



public int prizechest;


That makes it save to the player file.



public transient int prizeChest;


That is using proper java declaration. And makes it not save. Although everytime you log out and back in, it will set it to 0. Although I don't see why that part is needed at all.

Come on Emily chill. :\


You didn't make this then, you apparently just looked at a source already using this and reconstructed it. You don't understand the code you are using, nor can provide an adequate answer to my full question.

Since you won't know, I'll just explain it.

Your array, is a list of something, in this case items. You call this by arrayName[placeInArray]

The array starts at 0, and goes up infinite.

In your case (didn't waste the time to count) you have like ~20/30 places in the array. So the highest value you can call if you want to get something from the array is arrayName[20/30].

Your Misc.random statement, randomly selects a value from 0 to what ever value you set the Misc.random to, in this case 60. So the array will add an item from anywhere from placeInArray 0 to placeInArray 60. But since you have no values greater then lets say 20/30, you will not receive a reward from the chest.

Your code at the end, is redundant and in my opinion pointless. Why does it matter how many times you open the chest. The larger your player files are, the longer it takes for the player to load, and the decrease in performance.

@Emily again chill..

@tedhead2 good job.

Emily
January 18th, 2011, 01:37
Come on Emily chill. :\

@tedhead2 good job.

I'm providing information that is useful. Also explaining things that the OP doesn't know about his code. I don't see why I should chill when I'm trying to educate the members of the community.

Divine-X
January 18th, 2011, 01:39
I'm providing information that is useful. Also explaining things that the OP doesn't know about his code. I don't see why I should chill when I'm trying to educate the members of the community.

But from how it sounds(I know hearing how the person speaks threw internet XD) it sounds as if your mad..

samuraiblood2
January 18th, 2011, 01:46
Using an array like that is also pretty retarded. Adding more of the same value to the array will certainty increase the chance of getting that item, but all that really does is clog up the array with an unnecessary amount of indices.

Divine-X
January 18th, 2011, 01:54
God another person Flaming with Java.. Why can't you guys & girls just say "You can do this another way and easier but good job, keep working at it and you'll be good in no time." Instead of giving some gay Java flaming.

GkCha0z
January 18th, 2011, 02:07
divine SHHHHHHHHHHH there trying to help cant u see that

Divine-X
January 18th, 2011, 02:08
divine SHHHHHHHHHHH there trying to help cant u see that

Yes but in a bad way. :\

GkCha0z
January 18th, 2011, 02:10
thats your opinion tho they aint flaming

Divine-X
January 18th, 2011, 02:11
Kay then if it my opinion why is you talking to me about it then. <_<

samuraiblood2
January 18th, 2011, 02:26
God another person Flaming with Java.. Why can't you guys & girls just say "You can do this another way and easier but good job, keep working at it and you'll be good in no time." Instead of giving some gay Java flaming.
I'm not flaming; I'm giving constructive criticism. If you're so sensitive that someone cant comment on the code you gave without buttering it up with "good job", "easy but good", "thanks for this", then you're going to be in for a rude awakening later in life. I suggest taking Emilies and my comments to heart, and see if you cant improve your code and actually learn what you're doing wrong. Of course, if you need any help, Ill be more than glad to point you in the right direction and I'm sure others are as well.

You should also note that being so defensive is very rude in a context such as this.

tedhead2
January 18th, 2011, 12:19
I'm not flaming; I'm giving constructive criticism. If you're so sensitive that someone cant comment on the code you gave without buttering it up with "good job", "easy but good", "thanks for this", then you're going to be in for a rude awakening later in life. I suggest taking Emilies and my comments to heart, and see if you cant improve your code and actually learn what you're doing wrong. Of course, if you need any help, Ill be more than glad to point you in the right direction and I'm sure others are as well.

You should also note that being so defensive is very rude in a context such as this.

Let me clear some stuff up here:

I wrote this myself.
The "i" int was a mistake, i mis-counted the items in the array.
Yes, i know there is a better way to do this, but for the sake of peoples minds i made it simpler.
And, if you do know a better way of doing this, then feel free to post how to do so.

A N I M A L
January 18th, 2011, 13:52
You didn't make this then, you apparently just looked at a source already using this and reconstructed it. You don't understand the code you are using, nor can provide an adequate answer to my full question.

Since you won't know, I'll just explain it.

Your array, is a list of something, in this case items. You call this by arrayName[placeInArray]

The array starts at 0, and goes up infinite.

In your case (didn't waste the time to count) you have like ~20/30 places in the array. So the highest value you can call if you want to get something from the array is arrayName[20/30].

Your Misc.random statement, randomly selects a value from 0 to what ever value you set the Misc.random to, in this case 60. So the array will add an item from anywhere from placeInArray 0 to placeInArray 60. But since you have no values greater then lets say 20/30, you will not receive a reward from the chest.

Your code at the end, is redundant and in my opinion pointless. Why does it matter how many times you open the chest. The larger your player files are, the longer it takes for the player to load, and the decrease in performance.

Pwned.

Codeusa
January 18th, 2011, 13:55
Let me clear some stuff up here:

I wrote this myself.
The "i" int was a mistake, i mis-counted the items in the array.
Yes, i know there is a better way to do this, but for the sake of peoples minds i made it simpler.
And, if you do know a better way of doing this, then feel free to post how to do so.
For the sake of peoples mind? Explain the color red.

tedhead2
January 18th, 2011, 15:04
For the sake of peoples mind? Explain the color red.

Explain the word flame -.-'

I put in the prize chest counting thing for me, so i can look in th player file and check how many times they have opened it, to see if they have opened it more then the tickets they've been given.

samuraiblood2
January 18th, 2011, 20:45
Let me clear some stuff up here:

I wrote this myself.
The "i" int was a mistake, i mis-counted the items in the array.
Yes, i know there is a better way to do this, but for the sake of peoples minds i made it simpler.

It seems I misunderstood and thought the OP was the other person; my apologize. Although, my point still stands.

And, if you do know a better way of doing this, then feel free to post how to do so.
I'm reluctant to spoon-feed you, but I suppose with a proper example you may understand more.


Hashtable<Double, Integer> items = new Hashtable<Double, Integer>();
items.put(.75D, 995);
items.put(.50D, 4151);
items.put(.20D, 1050);

final int REQUIREMENT = 1464;
if (!player.getInventory().contains(REQUIREMENT)) {
player.sm("You need a ticket to search this chest!");
player.sm("Tickets are rewards from admins for being active!");
return;
}

Random rand = new Random();
double luck = rand.nextDouble();
for (Enumeration<Double> keys = items.keys(); keys.hasMoreElements();) {
double chance = keys.nextElement();
if (luck <= chance) {
player.getInventory().deleteItem(REQUIREMENT, 1);
player.getInventory().addItem(items.get(chance), 1);
player.sm("Have fun with your new item!");
}
}
Obviously you should load the items inside the chest via some other method, but for an example that should suffice.

g3n3
January 18th, 2011, 21:49
good job tedhead. keep it up.

davidpaceway
May 1st, 2011, 06:15
I'm gonna use this for a quest ;D

coruption
August 14th, 2011, 04:21
I should have released this A LONG TIME AGO. I was like one of the first (or the first) to have this on my server. (SeasonX 562). I don't host this server anymore but that's where everyone got this idea from -.- I should really have released it and got creds for it. Oh well, my loss :S

Niator
August 14th, 2011, 20:26
I should have released this A LONG TIME AGO. I was like one of the first (or the first) to have this on my server. (SeasonX 562). I don't host this server anymore but that's where everyone got this idea from -.- I should really have released it and got creds for it. Oh well, my loss :S

Lol no.

coruption
August 15th, 2011, 04:47
Lol no.
Lol yes. How would you know? Do you think I wouldn't know shit because of my posts? Because if you think that you're obviously an idiot. Posts don't mean anything.. Also, I had this on my 562 early-mid last year. When I had it I didn't know any other server with it.

boemboem2
January 4th, 2012, 15:00
but where can i place the chest i want it in my home.

I R SAD
January 4th, 2012, 15:07
Wrong section this isnt a tutorial.
Objectmanager.java

zamatv
May 9th, 2012, 06:01
i got this error can anyone help? im new


starting...
src\com\rs\net\decoders\handlers\ObjectHandler.jav a:601: error: incompatible typ
es
case 104: //reward chest, made by tedhead2(jordan) of runelocus!
^
required: String
found: int
src\com\rs\net\decoders\handlers\ObjectHandler.jav a:607: error: cannot find symb
ol
int i = Misc.random(60);
^
symbol: variable Misc
src\com\rs\net\decoders\handlers\ObjectHandler.jav a:608: error: cannot find symb
ol
if(player.getInventory().contains(1464)){
^
symbol: method contains(int)
location: class Inventory
src\com\rs\net\decoders\handlers\ObjectHandler.jav a:611: error: cannot find symb
ol
player.sm("Have fun with your new item!");
^
symbol: method sm(String)
location: variable player of type Player
src\com\rs\net\decoders\handlers\ObjectHandler.jav a:613: error: cannot find symb
ol
player.sm("You have opened this chest " + player.prizechest + "
times!");
^
symbol: method sm(String)
location: variable player of type Player
src\com\rs\net\decoders\handlers\ObjectHandler.jav a:615: error: cannot find symb
ol
player.sm("You need a ticket to search this chest!");
^
symbol: method sm(String)
location: variable player of type Player
src\com\rs\net\decoders\handlers\ObjectHandler.jav a:616: error: cannot find symb
ol
player.sm("Tickets are rewards from admins for being active!");
^
symbol: method sm(String)
location: variable player of type Player
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
7 errors
Press any key to continue . . .

Divine-X
May 10th, 2012, 21:39
i got this error can anyone help? im new
This tutorial is for RS2HD servers.