Converting coins and platinum tokens
So i writen this was awhile ago like 6 month ago, i think i did base it of old codes of rune-servers but i cant remember who or if i actually did, the only reason im releasing it is because it never took me long, and when i searched it up on rune-server to save me time i couldnt find one that had it all perfect. anyways here it is, add it however you want to an object, to an npc but this is the main part of the code.
Platinum Tokens part:
Code:
case 13204:
if (!player.getItems().playerHasItem(13204)) {
player.sendMessage("You need coins in your inventory to do this.");
return;
}
final int tokenAmount = player.getItems().getItemAmount(13204);
if (player.getItems().getItemAmount(13204) + (player.getItems().getItemAmount(13307)/1000) == MAX_VALUE) {
player.sendMessage("You cant do this as you will exceed the max value in tokens.");
return;
}
if (player.getItems().playerHasItem(13307, MAX_VALUE)) {
player.sendMessage("You cant do this as you will exceed the max value");
return;
}
if (tokenAmount >= MAX_TOKEN_VALUE && player.getItems().playerHasItem(13307, MAX_VALUE)) {
player.sendMessage("You cant do this as you will exceed the max value");
return;
}
if (tokenAmount > MAX_TOKEN_VALUE) {
if (player.getItems().getItemAmount(13204) >= MAX_VALUE) {
player.sendMessage("You cant do this as you will exceed the max value");
return;
}
int remaining = player.getItems().getItemAmount(13307);
player.getItems().deleteItem(13204, MAX_TOKEN_VALUE); //3000k- 2147k = 853k
player.getItems().addItem(13307, MAX_VALUE);
player.getItems().addItem(13204, remaining / 1000);
return;
}
player.getItems().deleteItem(13204, 1 * tokenAmount);
player.getItems().addItem(13307, tokenAmount * 1000);
break;
}
break;
Coin part:
Code:
case 995:
if (!player.getItems().playerHasItem(995)) {
player.sendMessage("You need coins in your inventory to do this.");
return;
}
int coinAmount = player.getItems().getItemAmount(995);
final int platinumTokenValue = 1000;
final int platinumTokenAmount = coinAmount / platinumTokenValue;
if (player.getItems().getItemAmount(13204) >= MAX_VALUE) {
player.sendMessage("You already have the maximum tokens possible.");
return;
}
if (platinumTokenAmount > 0) {
player.getItems().deleteItem(995, platinumTokenAmount * platinumTokenValue);
player.getItems().addItem(13204, coinAmount / 1000);
} else {
player.sendMessage("You dont have enough coins to convert.");
}
break;
If you want to improve / make it cleaner or add something to it or see a fault in it that i have somehow missed, feel free to, i did not really use the code much i just needed it at the time of coding my game.
edit: it was a guy called corey i believe that i looked at a comment and found a bit of his code, saved me a good 3 minutes but was good code.
so i guess credits to him for a bit of the code : [Only registered and activated users can see links. Click Here To Register...]