Thread: [667/***] Ash scattering

Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1 [667/***] Ash scattering 
    Registered Member
    Join Date
    Apr 2014
    Posts
    75
    Thanks given
    32
    Thanks received
    4
    Rep Power
    12
    I didn't see it anywhere (might be blind). So here y'all go.

    AshScattering.java
    Code:
    package com.rs.game.player.content;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import com.rs.game.Animation;
    import com.rs.game.Graphics;
    import com.rs.game.item.Item;
    import com.rs.game.player.Player;
    import com.rs.game.player.Skills;
    import com.rs.game.tasks.WorldTask;
    import com.rs.game.tasks.WorldTasksManager;
    import com.rs.utils.Utils;
    
    /**
     * 
     * @author Ronan & Arham 4 for improvements
     *
     */
    
    public class AshScattering {
    
    	public enum Ash {
    		IMPIOUS(20264, 4, new Graphics(56)), 
    		ACCURSED(20266, 12.5, new Graphics(47)), 
    		INFERNAL(20268, 62.5, new Graphics(40));
    
    		private int id;
    		private double experience;
    		private Graphics graphics;
    
    		private static Map<Integer, Ash> ashes = new HashMap<Integer, Ash>();
    		private static Ash[] values = values();
    
    		public static Ash[] valuesCached() {
    			return values;
    		}
    
    		static {
    			for (Ash ash : valuesCached()) {
    				ashes.put(ash.getId(), ash);
    			}
    		}
    
    		public static Ash forId(int id) {
    			return ashes.get(id);
    		}
    
    		private Ash(int id, double experience, Graphics graphics) {
    			this.id = id;
    			this.experience = experience;
    			this.graphics = graphics;
    		}
    
    		public int getId() {
    			return id;
    		}
    
    		public double getExperience() {
    			return experience;
    		}
    
    		public Graphics getGraphics() {
    			return graphics;
    		}
    
    		public static boolean Scatter(final Player player, int slotId) {
    			final Item item = player.getInventory().getItem(slotId);
    			if (item == null || Ash.forId(item.getId()) == null)
    				return false;
    			if (player.getAshDelay() > Utils.currentTimeMillis())
    				return true;
    			final Ash ash = Ash.forId(item.getId());
    			player.addStopDelay(3);
    			player.setNextAnimation(new Animation(445));
    			player.setNextGraphics(ash.getGraphics());
    			WorldTasksManager.schedule(new WorldTask() {
    				@Override
    				public void run() {
    					player.getInventory().deleteItem(item.getId(), 1);
    					player.getPackets().sendGameMessage(
    							"You scatter the ashes in the wind.");
    					player.getSkills()
    							.addXp(Skills.PRAYER, ash.getExperience());
    					stop();
    				}
    
    			}, 2);
    			return false;
    		}
    	}
    }
    Player.java
    Code:
    public long getAshDelay() {
    	return ashDelay;
    }
    
    public void addAshDelay(long time) {
    	ashDelay = time + Utils.currentTimeMillis();
    }
    
    private transient long ashDelay;
    InventoryOptionsHandler.java
    Code:
    Ash ash = Ash.forId(itemId);
    if (ash != null) {
    	Ash.Scatter(player, slotId);
    	return;
    }
    It's my first snippet tbh.

    OT: Thanks to Arham 4 for improvements .
    Reply With Quote  
     

  2. #2  
    Sexy User
    User's Avatar
    Join Date
    Apr 2013
    Posts
    603
    Thanks given
    97
    Thanks received
    218
    Rep Power
    346
    Quote Originally Posted by MadDoggzz View Post
    if (ash.getId() == 20264) {
    player.setNextGraphics(new Graphics(56));
    } else if (ash.getId() == 20266) {
    player.setNextGraphics(new Graphics(47));
    } else if (ash.getId() == 20268) {
    player.setNextGraphics(new Graphics(40));
    }
    Why not include this in the enumeration instead of making a bunch of if statements for each type of ash? That said if this is just for ashes and there are only 3 types why not include this as another type of bone and add parameters to burying the bone to include graphic and animation?

    Thanks for contributing this to the community none the less, good job friend
    Reply With Quote  
     

  3. #3  
    SiteTrec Hosting

    Project's Avatar
    Join Date
    Dec 2010
    Posts
    2,673
    Thanks given
    1,033
    Thanks received
    829
    Rep Power
    1072
    This was done already [Only registered and activated users can see links. ]
    DDOS PROTECTED WEB & VPS AT AN AFFORDABLE COST
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Dec 2012
    Posts
    3,006
    Thanks given
    899
    Thanks received
    929
    Rep Power
    2548
    Code:
    public long getAshDelay() {
    		return 0;
    	}
    
    	public void addAshDelay(int i) {	
    	}
    ???
    Reply With Quote  
     

  5. Thankful user:


  6. #5  
    Registered Member
    Velocity's Avatar
    Join Date
    Jan 2009
    Age
    25
    Posts
    2,029
    Thanks given
    1,013
    Thanks received
    2,373
    Rep Power
    4112
    • as kaleem said remove the unused methods
    • store the graphic in the enum def!
    • remove either of the two logic methods
    • you're locked for 3 ticks
    • xp is added immediately on rs
    • item is removed instantly too on rs
    • message is filterable


    idk if u wanted c&c but gj nonetheless

    Code:
    // Ash Scattering
    // 9 November, 2014
    // Bart Pelle
    
    .enum "core.skill_ids" as Skill
    
    
    on item_option_1(20264) { scatter(20264, 40, 56); } // Impious ashes
    on item_option_1(20266) { scatter(20266, 125, 47); } // Accursed ashes
    on item_option_1(20268) { scatter(20268, 625, 40); } // Infernal ashes
    on item_option_1(34159) { scatter(34159, 2000, 56); } // Searing ashes
    
    proc scatter(int item, int xp, int graphic) {
    	lock();
    	animate(445);
    	graphic(graphic);
    	message("You scatter the ashes in the wind.", true);
    	add_xp(Skill::PRAYER, xp, true);
    	//message("You gain extra experience as the ancestral barbarian spirit watches over you.");
    	delete_item(item, 1);
    	wait(3);
    	unlock();
    }
    xxxxxxx
    Reply With Quote  
     

  7. #6  
    Registered Member
    Join Date
    Apr 2014
    Posts
    75
    Thanks given
    32
    Thanks received
    4
    Rep Power
    12
    Quote Originally Posted by Project View Post
    This was done already [Only registered and activated users can see links. ]
    Oh well then.

    Quote Originally Posted by User View Post
    Why not include this in the enumeration instead of making a bunch of if statements for each type of ash? That said if this is just for ashes and there are only 3 types why not include this as another type of bone and add parameters to burying the bone to include graphic and animation?

    Thanks for contributing this to the community none the less, good job friend
    Thanks for the tip, next time i'll look into that.

    Quote Originally Posted by Velocity View Post
    • as kaleem said remove the unused methods
    • store the graphic in the enum def!
    • remove either of the two logic methods
    • you're locked for 3 ticks
    • xp is added immediately on rs
    • item is removed instantly too on rs
    • message is filterable


    idk if u wanted c&c but gj nonetheless

    Code:
    // Ash Scattering
    // 9 November, 2014
    // Bart Pelle
    
    .enum "core.skill_ids" as Skill
    
    
    on item_option_1(20264) { scatter(20264, 40, 56); } // Impious ashes
    on item_option_1(20266) { scatter(20266, 125, 47); } // Accursed ashes
    on item_option_1(20268) { scatter(20268, 625, 40); } // Infernal ashes
    on item_option_1(34159) { scatter(34159, 2000, 56); } // Searing ashes
    
    proc scatter(int item, int xp, int graphic) {
    	lock();
    	animate(445);
    	graphic(graphic);
    	message("You scatter the ashes in the wind.", true);
    	add_xp(Skill::PRAYER, xp, true);
    	//message("You gain extra experience as the ancestral barbarian spirit watches over you.");
    	delete_item(item, 1);
    	wait(3);
    	unlock();
    }
    Thanks for the tips as well.

    Quote Originally Posted by Kaleem View Post
    Code:
    public long getAshDelay() {
    		return 0;
    	}
    
    	public void addAshDelay(int i) {	
    	}
    ???
    Works for me tbh.
    Reply With Quote  
     

  8. #7  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    20
    Posts
    3,377
    Thanks given
    7,120
    Thanks received
    1,879
    Discord
    View profile
    Rep Power
    3454
    Point #1: Cache your values.
    Quote Originally Posted by MadDoggzz View Post
    Code:
    		private static Map < Integer, Ash > ashes = new HashMap < Integer, Ash > ();
    
    		static {
    			for (Ash ash: Ash.values()) {
    				ashes.put(ash.getId(), ash);
    			}
    		}
    Some advice I heard from Velocity was to cache these values.
    Spoiler for how you would go about doing this:

    Code:
    		private static Map < Integer, Ash > ashes = new HashMap < Integer, Ash > ();
    		private static Ash[] values = values();
    		public static Ash[] valuesCached() {
    			return values;
    		}
    
    		static {
    			for (Ash ash: valuesCached()) {
    				ashes.put(ash.getId(), ash);
    			}
    		}
    Atleast, that's how I think is the way to go about that. Somebody do correct me.


    Point #2: Why do you have have two scatter methods?

    Consider removing the scatter method from Ash, because it shouldn't belong there.
    Spoiler for how you would go about fixing this:

    Remove the scatter method in Ash, then change the code in InventoryOptionsHandler.
    Code:
    Ash ash = Ash.forId(itemId);
    if (ash != null) {
    	AshScattering.scatter(player, slotId);
    	return;
    }


    Point #3: Utilize your enumeration more.

    Quote Originally Posted by MadDoggzz View Post
    Code:
    		if (ash.getId() == 20264) {
    			player.setNextGraphics(new Graphics(56));
    		} else if (ash.getId() == 20266) {
    			player.setNextGraphics(new Graphics(47));
    		} else if (ash.getId() == 20268) {
    			player.setNextGraphics(new Graphics(40));
    		}
    Add the GFX to the enumeration. These if-statements are kind of ruining the purpose of the enumeration..

    Spoiler for how you would go about doing this:

    Code:
    	public enum Ash {
    		IMPIOUS(20264, 4, new Graphics(56)),
    		ACCURSED(20266, 12, new Graphics(47)),
    		INFERNAL(20268, 62, new Graphics(40));
    
    		private int id;
    		private double experience;
    		private Graphics graphics;
    
    		private static Map < Integer, Ash > ashes = new HashMap < Integer, Ash > ();
    		private static Ash[] values = values();
    		public static Ash[] valuesCached() {
    			return values;
    		}
    
    		static {
    			for (Ash ash: valuesCached()) {
    				ashes.put(ash.getId(), ash);
    			}
    		}
    
    		public static Ash forId(int id) {
    			return ashes.get(id);
    		}
    
    		private Ash(int id, double experience, Graphics graphics) {
    			this.id = id;
    			this.experience = experience;
    			this.graphics = graphics;
    		}
    
    		public int getId() {
    			return id;
    		}
    
    		public double getExperience() {
    			return experience;
    		}
    
    		public Graphics getGraphics() {
    			return graphics;
    		}
    	}
    Replace:
    Code:
    		if (ash.getId() == 20264) {
    			player.setNextGraphics(new Graphics(56));
    		} else if (ash.getId() == 20266) {
    			player.setNextGraphics(new Graphics(47));
    		} else if (ash.getId() == 20268) {
    			player.setNextGraphics(new Graphics(40));
    		}
    to:
    Code:
    		player.setNextGraphics(ash.getGraphics());


    Pet peeve #1: Instead of suppressing warnings with @SuppressWarnings("unused"), remove the unused variable.
    Spoiler for how you would go about doing this:

    Remove:
    Code:
    @SuppressWarnings("unused")
    final ItemDefinitions itemDef = new ItemDefinitions(item.getId());
    Last edited by Arham; 09-07-2015 at 05:38 PM. Reason: Pet peeve #1
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work [Only registered and activated users can see links. ]!
    Reply With Quote  
     

  9. Thankful users:


  10. #8  
    Sexy User
    User's Avatar
    Join Date
    Apr 2013
    Posts
    603
    Thanks given
    97
    Thanks received
    218
    Rep Power
    346
    Quote Originally Posted by Velocity View Post
    • as kaleem said remove the unused methods
    • store the graphic in the enum def!
    • remove either of the two logic methods
    • you're locked for 3 ticks
    • xp is added immediately on rs
    • item is removed instantly too on rs
    • message is filterable


    idk if u wanted c&c but gj nonetheless

    Code:
    // Ash Scattering
    // 9 November, 2014
    // Bart Pelle
    
    .enum "core.skill_ids" as Skill
    
    
    on item_option_1(20264) { scatter(20264, 40, 56); } // Impious ashes
    on item_option_1(20266) { scatter(20266, 125, 47); } // Accursed ashes
    on item_option_1(20268) { scatter(20268, 625, 40); } // Infernal ashes
    on item_option_1(34159) { scatter(34159, 2000, 56); } // Searing ashes
    
    proc scatter(int item, int xp, int graphic) {
    	lock();
    	animate(445);
    	graphic(graphic);
    	message("You scatter the ashes in the wind.", true);
    	add_xp(Skill::PRAYER, xp, true);
    	//message("You gain extra experience as the ancestral barbarian spirit watches over you.");
    	delete_item(item, 1);
    	wait(3);
    	unlock();
    }
    is that rune-script or velocity-script what the hell?
    Reply With Quote  
     

  11. Thankful user:


  12. #9  
    Registered Member
    Join Date
    Apr 2014
    Posts
    75
    Thanks given
    32
    Thanks received
    4
    Rep Power
    12
    Quote Originally Posted by Johan Liebert View Post
    Point #1: Cache your values.


    Some advice I heard from Velocity was to cache these values.
    Spoiler for how you would go about doing this:

    Code:
    		private static Map < Integer, Ash > ashes = new HashMap < Integer, Ash > ();
    		private static Ash[] values = values();
    		public static Ash[] valuesCached() {
    			return values;
    		}
    
    		static {
    			for (Ash ash: valuesCached()) {
    				ashes.put(ash.getId(), ash);
    			}
    		}
    Atleast, that's how I think is the way to go about that. Somebody do correct me.


    Point #2: Why do you have have two scatter methods?

    Consider removing the scatter method from Ash, because it shouldn't belong there.
    Spoiler for how you would go about fixing this:

    Remove the scatter method in Ash, then change the code in InventoryOptionsHandler.
    Code:
    Ash ash = Ash.forId(itemId);
    if (ash != null) {
    	AshScattering.scatter(player, slotId);
    	return;
    }


    Point #3: Utilize your enumeration more.


    Add the GFX to the enumeration. These if-statements are kind of ruining the purpose of the enumeration..

    Spoiler for how you would go about doing this:

    Code:
    	public enum Ash {
    		IMPIOUS(20264, 4, new Graphics(56)),
    		ACCURSED(20266, 12, new Graphics(47)),
    		INFERNAL(20268, 62, new Graphics(40));
    
    		private int id;
    		private double experience;
    		private Graphics graphics;
    
    		private static Map < Integer, Ash > ashes = new HashMap < Integer, Ash > ();
    		private static Ash[] values = values();
    		public static Ash[] valuesCached() {
    			return values;
    		}
    
    		static {
    			for (Ash ash: valuesCached()) {
    				ashes.put(ash.getId(), ash);
    			}
    		}
    
    		public static Ash forId(int id) {
    			return ashes.get(id);
    		}
    
    		private Ash(int id, double experience, Graphics graphics) {
    			this.id = id;
    			this.experience = experience;
    			this.graphics = graphics;
    		}
    
    		public int getId() {
    			return id;
    		}
    
    		public double getExperience() {
    			return experience;
    		}
    
    		public Graphics getGraphics() {
    			return graphics;
    		}
    	}
    Replace:
    Code:
    		if (ash.getId() == 20264) {
    			player.setNextGraphics(new Graphics(56));
    		} else if (ash.getId() == 20266) {
    			player.setNextGraphics(new Graphics(47));
    		} else if (ash.getId() == 20268) {
    			player.setNextGraphics(new Graphics(40));
    		}
    to:
    Code:
    		player.setNextGraphics(ash.getGraphics());


    Pet peeve #1: Instead of suppressing warnings with @SuppressWarnings("unused"), remove the unused variable.
    Spoiler for how you would go about doing this:

    Remove:
    Code:
    @SuppressWarnings("unused")
    final ItemDefinitions itemDef = new ItemDefinitions(item.getId());
    Something like this then?
    Code:
    package com.rs.game.player.content;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import com.rs.game.Animation;
    import com.rs.game.Graphics;
    import com.rs.game.item.Item;
    import com.rs.game.player.Player;
    import com.rs.game.player.Skills;
    import com.rs.game.tasks.WorldTask;
    import com.rs.game.tasks.WorldTasksManager;
    import com.rs.utils.Utils;
    
    public class AshScattering {
    
    	public enum Ash {
    		IMPIOUS(20264, 4, new Graphics(56)),
    		ACCURSED(20266, 12, new Graphics(47)),
    		INFERNAL(20268, 62, new Graphics(40));
    
    		private int id;
    		private double experience;
    		private Graphics graphics;
    
    		private static Map < Integer, Ash > ashes = new HashMap < Integer, Ash > ();
    		private static Ash[] values = values();
    		public static Ash[] valuesCached() {
    			return values;
    		}
    
    		static {
    			for (Ash ash: valuesCached()) {
    				ashes.put(ash.getId(), ash);
    			}
    		}
    
    		public static Ash forId(int id) {
    			return ashes.get(id);
    		}
    
    		private Ash(int id, double experience, Graphics graphics) {
    			this.id = id;
    			this.experience = experience;
    			this.graphics = graphics;
    		}
    
    		public int getId() {
    			return id;
    		}
    
    		public double getExperience() {
    			return experience;
    		}
    
    		public Graphics getGraphics() {
    			return graphics;
    		}
    	}
    	
    	public static boolean scatter(final Player player, int slotId) {
    		final Item item = player.getInventory().getItem(slotId);
    		if (item == null || Ash.forId(item.getId()) == null)
    			return false;
    		if (player.getAshDelay() > Utils.currentTimeMillis())
    			return true;
    		final Ash ash = Ash.forId(item.getId());
    		player.addStopDelay(4);
    		player.setNextAnimation(new Animation(445));
    		player.setNextGraphics(ash.getGraphics());
    		WorldTasksManager.schedule(new WorldTask() {
    			@Override
    			public void run() {
    				player.getInventory().deleteItem(item.getId(), 1);
    				player.getPackets().sendGameMessage("You scatter the ashes in the wind.");
    				player.getSkills().addXp(Skills.PRAYER, ash.getExperience());
    				stop();
    			}
    
    		}, 2);
    		return false;
    	}
    }
    Reply With Quote  
     

  13. Thankful user:


  14. #10  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    20
    Posts
    3,377
    Thanks given
    7,120
    Thanks received
    1,879
    Discord
    View profile
    Rep Power
    3454
    Quote Originally Posted by MadDoggzz View Post
    Something like this then?
    Code:
    package com.rs.game.player.content;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import com.rs.game.Animation;
    import com.rs.game.Graphics;
    import com.rs.game.item.Item;
    import com.rs.game.player.Player;
    import com.rs.game.player.Skills;
    import com.rs.game.tasks.WorldTask;
    import com.rs.game.tasks.WorldTasksManager;
    import com.rs.utils.Utils;
    
    public class AshScattering {
    
    	public enum Ash {
    		IMPIOUS(20264, 4, new Graphics(56)),
    		ACCURSED(20266, 12, new Graphics(47)),
    		INFERNAL(20268, 62, new Graphics(40));
    
    		private int id;
    		private double experience;
    		private Graphics graphics;
    
    		private static Map < Integer, Ash > ashes = new HashMap < Integer, Ash > ();
    		private static Ash[] values = values();
    		public static Ash[] valuesCached() {
    			return values;
    		}
    
    		static {
    			for (Ash ash: valuesCached()) {
    				ashes.put(ash.getId(), ash);
    			}
    		}
    
    		public static Ash forId(int id) {
    			return ashes.get(id);
    		}
    
    		private Ash(int id, double experience, Graphics graphics) {
    			this.id = id;
    			this.experience = experience;
    			this.graphics = graphics;
    		}
    
    		public int getId() {
    			return id;
    		}
    
    		public double getExperience() {
    			return experience;
    		}
    
    		public Graphics getGraphics() {
    			return graphics;
    		}
    	}
    	
    	public static boolean scatter(final Player player, int slotId) {
    		final Item item = player.getInventory().getItem(slotId);
    		if (item == null || Ash.forId(item.getId()) == null)
    			return false;
    		if (player.getAshDelay() > Utils.currentTimeMillis())
    			return true;
    		final Ash ash = Ash.forId(item.getId());
    		player.addStopDelay(4);
    		player.setNextAnimation(new Animation(445));
    		player.setNextGraphics(ash.getGraphics());
    		WorldTasksManager.schedule(new WorldTask() {
    			@Override
    			public void run() {
    				player.getInventory().deleteItem(item.getId(), 1);
    				player.getPackets().sendGameMessage("You scatter the ashes in the wind.");
    				player.getSkills().addXp(Skills.PRAYER, ash.getExperience());
    				stop();
    			}
    
    		}, 2);
    		return false;
    	}
    }
    Precisely.
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work [Only registered and activated users can see links. ]!
    Reply With Quote  
     

  15. Thankful user:


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. [718] Ash Scattering
    By _Josh in forum Snippets
    Replies: 21
    Last Post: 10-23-2014, 11:41 AM
  2. [637/639] Dementhium - Ashes' scattering [637/639]
    By Antikristus in forum Snippets
    Replies: 3
    Last Post: 08-06-2013, 03:03 PM
  3. Replies: 10
    Last Post: 01-12-2013, 05:38 PM
  4. Ashes of the Drunk
    By Tape in forum Showcase
    Replies: 9
    Last Post: 09-18-2008, 08:28 PM
  5. Bank Booth - Ash link
    By Anton in forum Models
    Replies: 4
    Last Post: 06-03-2008, 02:34 AM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •