Thread: A better magic notepaper

Results 1 to 6 of 6
  1. #1 A better magic notepaper 
    Owner of Zerion
    robstever's Avatar
    Join Date
    Jun 2013
    Posts
    139
    Thanks given
    42
    Thanks received
    18
    Rep Power
    48

    Magic Notepaper Release

    There has been some of these released before, but this one handles notepaper in both directions, as well as takes into account if you already have the item noted. if you have enough notepaper, or not, as well as checks if you actually have the item, making it a cleaner way to handle the notepaper.



    MagicNotepaper.java

    Code:
    package com.rs.game.player.content.custom;
    
    import com.rs.game.item.Item;
    import com.rs.game.player.Player;
    import com.rs.io.InputStream;
    /**
     * 
     * @author bob/zerion/pancakepal#4318
     * 2/9/21
     *
     */
    public class MagicNotepaper {
    	
    	public static void noteViaPaper (Player player, Item usedWith, Item itemUsed, InputStream stream) {
    			int amountUsed = player.getInventory().getAmountOf(usedWith.getId());
    			int paperHeld = player.getInventory().getAmountOf(itemUsed.getId());
    			if (usedWith.getDefinitions().isNoted() || usedWith.getDefinitions().isStackable() || usedWith.getDefinitions().getCertId() == -1) {
    				player.sm("You can't note this item.");
    			return;
    		}
    			else if ( paperHeld < amountUsed) {
    				 
    				  if (usedWith.getDefinitions().getCertId() != -1) {
    						if (!player.getInventory().containsItem(usedWith.getId(), 1)) 
    																						
    																						
    																						
    							return;
    						if (player.getInventory().getFreeSlots() >= 1 || player.getInventory().contains(usedWith.getDefinitions().getCertId())) {
    							player.getInventory().deleteItem(usedWith.getId(), paperHeld);
    							player.getInventory().deleteItem(30372, paperHeld);
    							player.getInventory().addItem((usedWith.getDefinitions().getCertId()), paperHeld);
    							player.sendSimpleDialogue("You did not have enough magic notepaper to note all of your " +usedWith.getName()+"!");
    						} else
    							player.sm("You need at least one free inventory space to do this.");
    					}
    				 
    				 
    			 }
    				 
    			 
    			else if (usedWith.getDefinitions().getCertId() != -1) {
    				if (!player.getInventory().containsItem(usedWith.getId(), 1)) 
    																				/
    																				
    																				
    					return;
    				if (player.getInventory().getFreeSlots() >= 1 || player.getInventory().contains(usedWith.getDefinitions().getCertId())) {
    					player.getInventory().deleteItem(usedWith.getId(), amountUsed);
    					player.getInventory().deleteItem(30372, amountUsed);
    					player.getInventory().addItem((usedWith.getDefinitions().getCertId()), amountUsed);
    
    					player.sendSimpleDialogue("Your items have been noted!");
    				} else
    					player.sm("You need at least one free inventory space to do this.");
    			}
    		
    	}
    	
    	public static void noteViaItem (Player player, Item usedWith, Item itemUsed, InputStream stream) {
    		int paperHeld = player.getInventory().getAmountOf(usedWith.getId());
    		int amountUsed = player.getInventory().getAmountOf(itemUsed.getId());
    		if (itemUsed.getDefinitions().isNoted() || itemUsed.getDefinitions().isStackable() || itemUsed.getDefinitions().getCertId() == -1) {
    			player.sm("You can't note this item.");
    			return;
    		}
    		else if ( paperHeld < amountUsed) {
    			 
    			  if (itemUsed.getDefinitions().getCertId() != -1) {
    					if (!player.getInventory().containsItem(itemUsed.getId(), 1)) 
    																					
    																					
    																					
    						return;
    					if (player.getInventory().getFreeSlots() >= 1 || player.getInventory().contains(itemUsed.getDefinitions().getCertId())) {
    						player.getInventory().deleteItem(itemUsed.getId(), paperHeld);
    						player.getInventory().deleteItem(30372, paperHeld);
    						player.getInventory().addItem((itemUsed.getDefinitions().getCertId()), paperHeld);
    
    						player.sendSimpleDialogue("You did not have enough magic notepaper to note all of your " + itemUsed.getName()+"!");
    					} else
    						player.sm("You need at least one free inventory space to do this.");
    				}
    			 
    			 
    		 }
    			 
    		 
    		else if (itemUsed.getDefinitions().getCertId() != -1 || player.getInventory().contains(itemUsed.getDefinitions().getCertId())) {
    			if (!player.getInventory().containsItem(itemUsed.getId(), 1)) 
    																			
    																			
    																			
    				return;
    			if (player.getInventory().getFreeSlots() >= 1 || player.getInventory().contains(itemUsed.getDefinitions().getCertId())) {
    				player.getInventory().deleteItem(itemUsed.getId(), paperHeld);
    				player.getInventory().deleteItem(30372, amountUsed);
    				player.getInventory().addItem((itemUsed.getDefinitions().getCertId()), amountUsed);
    
    				player.sendSimpleDialogue("Your items have been noted!");
    			} else
    				player.sm("You need at least one free inventory space to do this.");
    		}
    
    	
    	
    	
    	}
    }
    Put this inside your src->com->rs->game->player->content->custom. Then head into your InventoryOptionsHandler.java and put this into it in the itemOnItem method being sure to check for any existing notepaper handling in here :

    InventoryOptionsHandler.java

    Code:
    if (usedWith.getId() == 30372) {
                MagicNotepaper.noteViaItem(player, usedWith, itemUsed, stream);
                return;
                }
                
                if (itemUsed.getId() == 30372) {
                    MagicNotepaper.noteViaPaper(player, usedWith, itemUsed, stream);
                    return;
                }
    Important!

    If you don't have this method in Inventory.java :

    Code:
    public boolean contains(int itemId) {
            return items.contains(new Item(itemId, 1));
        }
    You can replace this line instead :

    Code:
    if (player.getInventory().getFreeSlots() >= 1 || player.getInventory().contains(itemUsed.getDefinitions().getCertId())) {
    With :

    Code:
    if (player.getInventory().getFreeSlots() >= 1 || player.getInventory().containsItems(itemUsed.getDefinitions().getCertId(), 1)) {
    AND I CANNOT FORGET TO OFFER A HUGE SHOUTOUT TO MY MAN QUANTUM FOR TAKING THE TIME OUT OF HIS DAY TO MAKE THIS THREAD POST FOR ME! MUCH LOVE!!
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Chemist

    Advocatus's Avatar
    Join Date
    Dec 2009
    Age
    28
    Posts
    2,526
    Thanks given
    192
    Thanks received
    746
    Rep Power
    1315
    You are much helper. Big thank. Big help for server. Top goat release.
    Quote Originally Posted by blakeman8192 View Post
    Quitting is the only true failure.
    Reply With Quote  
     

  4. Thankful user:


  5. #3  
    Owner of Zerion
    robstever's Avatar
    Join Date
    Jun 2013
    Posts
    139
    Thanks given
    42
    Thanks received
    18
    Rep Power
    48
    Quote Originally Posted by Advocatus View Post
    You are much helper. Big thank. Big help for server. Top goat release.
    Hey man. I never said it was game changing content. Just my take on a cleaner, nicer way, figured some new folks could benefit from it. No hate!
    Reply With Quote  
     

  6. #4  
    Banned

    Join Date
    Jun 2010
    Age
    23
    Posts
    4,728
    Thanks given
    1,646
    Thanks received
    1,522
    Rep Power
    0
    I don't understand what kind of goat this is that you released. What is a magic notepaper? Can you add some goat pics? Thx.
    Reply With Quote  
     

  7. #5  
    Chemist

    Advocatus's Avatar
    Join Date
    Dec 2009
    Age
    28
    Posts
    2,526
    Thanks given
    192
    Thanks received
    746
    Rep Power
    1315
    Quote Originally Posted by robstever View Post
    Hey man. I never said it was game changing content. Just my take on a cleaner, nicer way, figured some new folks could benefit from it. No hate!
    man.

    It would be pretty simple to cut the amount of code here in half.
    Code:
    if (usedWith.getId() == 30372 || itemUsed.getId() == 30372) {
                MagicNotepaper.handle(player, usedWith, itemUsed, stream);
                return;
                }
    both of the methods there are basically identical with the usedWith being swapped for itemUsed in the other. You could do a check via a ternary or something to combine those methods easily.
    Quote Originally Posted by blakeman8192 View Post
    Quitting is the only true failure.
    Reply With Quote  
     

  8. Thankful user:


  9. #6  
    Owner of Zerion
    robstever's Avatar
    Join Date
    Jun 2013
    Posts
    139
    Thanks given
    42
    Thanks received
    18
    Rep Power
    48
    Quote Originally Posted by Advocatus View Post
    man.

    It would be pretty simple to cut the amount of code here in half.
    Code:
    if (usedWith.getId() == 30372 || itemUsed.getId() == 30372) {
                MagicNotepaper.handle(player, usedWith, itemUsed, stream);
                return;
                }
    both of the methods there are basically identical with the usedWith being swapped for itemUsed in the other. You could do a check via a ternary or something to combine those methods easily.
    Thank you! I definitely knew that, but I really wasnt thinking any further about it once I had condensed the handler as much as I had already. This is what these things are all about! Improvements from a simple overlook!
    Reply With Quote  
     


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. Magic notepaper - Matrix RS3
    By Dinh in forum Help
    Replies: 7
    Last Post: 06-28-2016, 10:56 AM
  2. Replies: 15
    Last Post: 07-17-2014, 07:52 AM
  3. better Magic system for Delta?
    By Mr. Epic in forum Requests
    Replies: 1
    Last Post: 10-15-2009, 05:16 AM
  4. A way to make magic hit better with better bonuses
    By bmxxscape in forum Tutorials
    Replies: 5
    Last Post: 06-27-2008, 09:59 PM
  5. which one of the halo sigs do u like better?
    By man777 in forum Showcase
    Replies: 0
    Last Post: 04-01-2007, 05:22 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
  •