Thread: Converting coins and platinum tokens

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 Converting coins and platinum tokens 
    Banned Converting coins and platinum tokens Market Banned

    Join Date
    Jun 2019
    Posts
    90
    Thanks given
    5
    Thanks received
    28
    Rep Power
    0
    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 : https://www.rune-server.ee/members/corey/
    Last edited by Aaron W; 10-16-2020 at 01:30 PM.
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Registered Member
    Optimum's Avatar
    Join Date
    Apr 2012
    Posts
    3,570
    Thanks given
    871
    Thanks received
    1,745
    Rep Power
    5000
    Dude this is fucking sick, you don't mind if i use this?

    Quote Originally Posted by DownGrade View Post
    Don't let these no life creeps get to you, its always the same on here. They'd rather spend hours upon hours in the rune-server spam section then getting laid! ha ha!Its honestly pathetic i haven't seen so many lowlifes in my life its actually insane i wish that this section would just vanish its probably the only way to get these people out of the community...
    PLEASE BE AWARE OF IMPOSTERS MY DISCORD ID: 362240000760348683
    Reply With Quote  
     

  4. Thankful users:


  5. #3  
    Banned Converting coins and platinum tokens Market Banned

    Join Date
    Jun 2019
    Posts
    90
    Thanks given
    5
    Thanks received
    28
    Rep Power
    0
    Quote Originally Posted by Optimum View Post
    Dude this is fucking sick, you don't mind if i use this?
    Due to it being rune-server im not sure if its you being sarcastic, but sure anyone can use.
    Reply With Quote  
     

  6. #4  
    Donator

    Arithium's Avatar
    Join Date
    May 2010
    Age
    31
    Posts
    4,721
    Thanks given
    199
    Thanks received
    1,256
    Rep Power
    1114
    Quote Originally Posted by Aaron W View Post
    Due to it being rune-server im not sure if its you being sarcastic, but sure anyone can use.
    Hes being sarcastic as usual.

    Couple of things here.
    Code:
     int remainding = player.getItems().getItemAmount(13307);
    Move this up above your checks, and use it instead of calling getItemAmount multiple times. Also fix the naming.

    Swap this around.

    Code:
    final int tokenAmount = player.getItems().getItemAmount(13204);
    if (tokenAmount <= 0) {
                    player.sendMessage("You need coins in your inventory to do this.");
                    return;
                }
    Fix all of your calls to check inventory amount with your tokenAmount and remaining values.

    You're gonna have to explain what MAX_TOKEN_VALUE and MAX_VALUE are, because this code is hard to read. You shouldn't be deleting all of the item, then adding back more. There needs to be math to calculate how much space you have left, and only delete whats needed.
    Reply With Quote  
     

  7. #5  
    Registered Member
    Join Date
    Jan 2020
    Posts
    13
    Thanks given
    1
    Thanks received
    4
    Rep Power
    36
    Tested on my Elvarg source.

    Nearly fully functioning conversion, with proper checks. (Instead of not allowing the player to convert any coins to tokens if it would exceeds the max value, the player should exchange up-to the maximum amount)
    Code:
    		//Handle coins <-> platinum tokens.
    		if (itemId == 995 && (object.getDefinition().getName().toLowerCase().equals("bank booth") || object.getDefinition().getName().toLowerCase().equals("bank chest"))) {
    			final int COIN_SIZE = player.getInventory().getAmount(995);
    			if (COIN_SIZE < 1000) {
    				player.getPacketSender().sendMessage("You must have atleast 1,000 coins to exchange for Platinum tokens.");
    				return;
    			}
    			final int PLATINUM_TOKEN_SIZE = player.getInventory().getAmount(13204);
    			System.out.println((long)(PLATINUM_TOKEN_SIZE + (COIN_SIZE / 1000)));
    			if ((long)(PLATINUM_TOKEN_SIZE + (COIN_SIZE / 1000)) < 0) {
    				player.getPacketSender().sendMessage("You can't do this as you will exceed the maximum value.");
    				return;
    			}
    			final int REMAINDER = COIN_SIZE % 1000;
    			if (REMAINDER != 0 && PLATINUM_TOKEN_SIZE == 0 && player.getInventory().getFreeSlots() == 0) {
    				player.getPacketSender().sendMessage("You don't have enough space in your inventory.");
    				return;
    			}
    			player.getInventory().delete(new Item(995, COIN_SIZE - REMAINDER));
    			player.getInventory().add(new Item(13204, COIN_SIZE / 1000));
    			player.getPacketSender().sendMessage("You exchange " + Misc.format(COIN_SIZE) + " Coins for " + Misc.format(player.getInventory().getAmount(13204)) + " Platinum tokens.");
    			return;
    		}
    		if (itemId == 13204 && (object.getDefinition().getName().toLowerCase().equals("bank booth") || object.getDefinition().getName().toLowerCase().equals("bank chest"))) {
    			final int COIN_SIZE = player.getInventory().getAmount(995);
    			final int PLATINUM_TOKEN_SIZE = player.getInventory().getAmount(13204);
    			if ((PLATINUM_TOKEN_SIZE * 1000) < 0 || ((PLATINUM_TOKEN_SIZE * 1000) + COIN_SIZE) < 0) {
    				player.getPacketSender().sendMessage("You can't do this as you will exceed the maximum value.");
    				return;
    			}
    			player.getInventory().delete(new Item(13204, PLATINUM_TOKEN_SIZE));
    			player.getInventory().add(new Item(995, PLATINUM_TOKEN_SIZE * 1000));
    			player.getPacketSender().sendMessage("You exchange " + Misc.format(PLATINUM_TOKEN_SIZE) + " Platinum tokens for " + Misc.format(player.getInventory().getAmount(995)) + " Coins.");
    			return;
    		}
    Last edited by VoidBox; 10-01-2020 at 10:39 AM. Reason: Forgot a return value and fixed overflow.
    Reply With Quote  
     

  8. #6  
    Endeavor

    Mikey`'s Avatar
    Join Date
    Dec 2007
    Posts
    4,434
    Thanks given
    715
    Thanks received
    1,435
    Rep Power
    1202
    Quote Originally Posted by VoidBox View Post
    Tested on my Elvarg source.

    Nearly fully functioning conversion, with proper checks. (Instead of not allowing the player to convert any coins to tokens if it would exceeds the max value, the player should exchange up-to the maximum amount)
    Code:
    		//Handle coins <-> platinum tokens.
    		if (itemId == 995 && (object.getDefinition().getName().toLowerCase().equals("bank booth") || object.getDefinition().getName().toLowerCase().equals("bank chest"))) {
    			final int COIN_SIZE = player.getInventory().getAmount(995);
    			if (COIN_SIZE < 1000) {
    				player.getPacketSender().sendMessage("You must have atleast 1,000 coins to exchange for Platinum tokens.");
    				return;
    			}
    			final int PLATINUM_TOKEN_SIZE = player.getInventory().getAmount(13204);
    			if ((PLATINUM_TOKEN_SIZE + (COIN_SIZE / 1000)) > Integer.MAX_VALUE) {
    				player.getPacketSender().sendMessage("You can't do this as you will exceed the max value.");
    				return;
    			}
    			final int REMAINDER = COIN_SIZE % 1000;
    			if (REMAINDER != 0 && PLATINUM_TOKEN_SIZE == 0 && player.getInventory().getFreeSlots() == 0) {
    				player.getPacketSender().sendMessage("You don't have enough space in your inventory.");
    				return;
    			}
    			player.getInventory().delete(new Item(995, COIN_SIZE - REMAINDER));
    			player.getInventory().add(new Item(13204, COIN_SIZE / 1000));
    			player.getPacketSender().sendMessage("You exchange " + Misc.format(COIN_SIZE) + " Coins for " + Misc.format(player.getInventory().getAmount(13204)) + " Platinum tokens.");
    			return;
    		}
    		if (itemId == 13204 && (object.getDefinition().getName().toLowerCase().equals("bank booth") || object.getDefinition().getName().toLowerCase().equals("bank chest"))) {
    			final int COIN_SIZE = player.getInventory().getAmount(995);
    			final int PLATINUM_TOKEN_SIZE = player.getInventory().getAmount(13204);
    			if (((PLATINUM_TOKEN_SIZE * 1000) + COIN_SIZE) > Integer.MAX_VALUE) {
    				player.getPacketSender().sendMessage("You can't do this as you will exceed the max value.");
    			}
    			player.getInventory().delete(new Item(13204, PLATINUM_TOKEN_SIZE));
    			player.getInventory().add(new Item(995, PLATINUM_TOKEN_SIZE * 1000));
    			player.getPacketSender().sendMessage("You exchange " + Misc.format(PLATINUM_TOKEN_SIZE) + " Platinum tokens for " + Misc.format(player.getInventory().getAmount(995)) + " Coins.");
    			return;
    		}
    You only need to use CAPS_CASE when it's a static final field. I'm also pretty sure you have to cast to long to do your > Integer.MAX_VALUE check or it will overflow.
    Reply With Quote  
     

  9. #7  
    Registered Member
    Join Date
    Jan 2020
    Posts
    13
    Thanks given
    1
    Thanks received
    4
    Rep Power
    36
    Quote Originally Posted by Mikey` View Post
    You only need to use CAPS_CASE when it's a static final field. I'm also pretty sure you have to cast to long to do your > Integer.MAX_VALUE check or it will overflow.
    I prefer caps on final variables, but perhaps this is bad practice. I will change my conventions.

    I am only using Integer.MAX_VALUE as a check for surpassing the maximum amount and am never incrementing past the maximum value. Why do you think this would cause an overflow out of curiosity?
    Reply With Quote  
     

  10. #8  
    Registered Member
    hc747's Avatar
    Join Date
    Dec 2013
    Age
    26
    Posts
    1,474
    Thanks given
    3,312
    Thanks received
    691
    Rep Power
    1098
    Quote Originally Posted by VoidBox View Post
    I prefer caps on final variables, but perhaps this is bad practice. I will change my conventions.

    I am only using Integer.MAX_VALUE as a check for surpassing the maximum amount and am never incrementing past the maximum value. Why do you think this would cause an overflow out of curiosity?
    Because an int(eger) cannot be larger than Integer.MAX_VALUE. Either use a long (which can exceed Integer.MAX_VALUE) or check if current + amount < 0.
    Reply With Quote  
     

  11. #9  
    Registered Member
    Join Date
    Jan 2020
    Posts
    13
    Thanks given
    1
    Thanks received
    4
    Rep Power
    36
    Quote Originally Posted by hc747 View Post
    Because an int(eger) cannot be larger than Integer.MAX_VALUE. Either use a long (which can exceed Integer.MAX_VALUE) or check if current + amount < 0.
    Thank you for the explanation. Can't believe I hadn't even considered the coins/tokens exceeding max(big oof). I checked this and it does not result in an overflow error, but does not give the user the converted item. (Elvarg might have an overflow check?)

    I fixed this and added a return I had forgot.
    Reply With Quote  
     

  12. #10  
    Member of the Imagine Cult

    Join Date
    Feb 2013
    Posts
    519
    Thanks given
    21
    Thanks received
    7
    Rep Power
    59
    Quote Originally Posted by Arithium View Post
    Code:
     int remainding = player.getItems().getItemAmount(13307);
    Help pls, my notepad++ keeps throwing BadSpellingException at this line for some reason...
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Platinum tokens converting
    By replicant in forum Help
    Replies: 3
    Last Post: 07-14-2018, 11:57 PM
  2. [Delta] Coins and Points not refreshing
    By Factfollow in forum Help
    Replies: 0
    Last Post: 06-23-2013, 02:22 AM
  3. converting models and anims to 317
    By sexyrussian in forum Help
    Replies: 0
    Last Post: 11-23-2010, 02:00 AM
  4. Making 10m+ coins, and 100k+ coins Yellow?
    By Mr. Epic in forum Help
    Replies: 1
    Last Post: 12-19-2009, 05:37 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •