Thread: [PI] Item Count Bug

Results 1 to 5 of 5
  1. #1 [PI] Item Count Bug 
    Banned
    Join Date
    Mar 2014
    Posts
    628
    Thanks given
    109
    Thanks received
    181
    Rep Power
    0


    Currently trying to add some sort of bonfire method of training firemaking into my server using stock animations, but have run into a issue where it isn't grabbing the correct item count. After testing to see if everything would work and it didn't I begin to debug my problem and put a sendMessage statement to see the actual count of the item. For some odd reason it prints out multiples of them even though I don't have it called doing that. Anyone got any ideas?

    Code:
    package org.delrith.game.content.skill.firemaking;
    
    import org.delrith.Server;
    import org.delrith.core.event.CycleEvent;
    import org.delrith.core.event.CycleEventContainer;
    import org.delrith.core.event.CycleEventHandler;
    import org.delrith.core.util.Misc;
    import org.delrith.game.player.Client;
    import org.delrith.game.player.Player;
    
    /**
     * 
     * @author Vili
     *
     */
    
    public class Bonfire {
    
        public enum LogData {
    
            NORMAL(1511, 1, 50.0), OAK(1521, 15, 70.0), WILLOW(1519, 30, 100.0), MAPLE(
                    1517, 45, 151.0), YEW(1515, 60, 212.5), MAGIC(1513, 75, 313.8);
    
            /** Field Variables **/
            private final int logIdentifier, levelRequired;
            private final double experienceGained;
    
            /**
             * Constructs the enumerator LogData.
             * 
             * @param logIdentifier
             *            The log being lighted.
             * @param levelRequired
             *            The level required to light the log.
             * @param experienceGained
             *            The experience given for lighting the log.
             */
            private LogData(final int logIdentifier, final int levelRequired,
                    final double experienceGained) {
                this.logIdentifier = logIdentifier;
                this.levelRequired = levelRequired;
                this.experienceGained = experienceGained;
            }
    
            /**
             * Publicly constructs logIdentifier.
             * 
             * @return
             */
            public int getLog() {
                return logIdentifier;
            }
    
            /**
             * Publicly constructs levelRequired.
             * 
             * @return
             */
            public int getLevel() {
                return levelRequired;
            }
    
            /**
             * Publicly constructs experienceGained.
             * 
             * @return
             */
            public double getExperience() {
                return experienceGained;
            }
    
        }
        
        /**
         *  Handles the action for bonfires.
         * @param c
         *         Client
         * @param objectId
         *         Object identifier.
         * @param objectX
         *         Object's X coordinate.
         * @param objectY
         *         Object's Y coordinate.
         * @param itemId
         *         Item Identifier.
         */
        public static void bonfireAction(final Client c, final int objectId,
                final int objectX, final int objectY, final int itemId) {
            final String name = c.getItems().getItemName(itemId).toLowerCase();
            final int delay = Misc.random(5) + 3;
            if (Player.isSkilling == true) {
                return;
            }
            for (final LogData l : LogData.values()) {
                c.sendMessage("You have " + c.getItems().getItemAmount(l.getLog()) + " "+ name.toLowerCase() + ".");
                if (itemId == l.getLog() && objectId == 2732)
                if (c.playerLevel[11] < l.getLevel()) {
                    c.sendMessage("You need level " + l.getLevel()
                            + " firemaking to bonfire " + name + ".");
                }
                Player.setSkilling(true);
                CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
    
                    @Override
                    public void execute(CycleEventContainer container) {
                        if (!Client.isBonfire()) {
                            container.stop();
                        }
                        if (!Server.objectManager.objectExists(objectX, objectY)) {
                            container.stop();
                        }
                        if (c.getItems().getItemAmount(l.getLog()) > 0) {
                            c.startAnimation(894);
                            c.getItems().deleteItem(l.getLog(), 1);
                            c.getPA().addSkillXP((int) l.getExperience(), 11);
                            c.sendMessage("You add the " + name + " to the bonfire.");
                        }
                        if (c.getItems().getItemAmount(l.getLog()) < 1) {
                            c.sendMessage("You have run out of logs to throw on the bonfire.");
                            container.stop();
                        }
                    }
    
                    @Override
                    public void stop() {
                        Player.setSkilling(false);
                        Client.setBonfire(false);
                    }
    
                }, delay);
            }
        }
    }
    Code:
    case 2732:
    Bonfire.bonfireAction(c, objectId, objectX, objectY, itemId);
    break;
    Code:
    public int getItemAmount(final int ItemID) {
            int itemCount = 0;
            for (int i = 0; i < c.playerItems.length; i++) {
                if ((c.playerItems[i] - 1) == ItemID) {
                    itemCount += c.playerItemsN[i];
                }
            }
            return itemCount;
        }
    Reply With Quote  
     

  2. #2  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Because it's printing it out each loop for every element. Just send the message after it checks if you have the log. Derp.
    Reply With Quote  
     

  3. Thankful users:


  4. #3  
    Banned
    Join Date
    Mar 2014
    Posts
    628
    Thanks given
    109
    Thanks received
    181
    Rep Power
    0
    Quote Originally Posted by Jason View Post
    Because it's printing it out each loop for every element. Just send the message after it checks if you have the log. Derp.
    Just curious, why does it tell me I don't have any logs a couple times before it actually puts one in the fire though?

    Reply With Quote  
     

  5. #4  
    Donator

    Tringan's Avatar
    Join Date
    Feb 2011
    Age
    27
    Posts
    2,101
    Thanks given
    381
    Thanks received
    334
    Rep Power
    297
    Quote Originally Posted by Vili View Post
    Just curious, why does it tell me I don't have any logs a couple times before it actually puts one in the fire though?

    for the same previous reason, u are checking if the player has all kinds of logs individually
    Reply With Quote  
     

  6. #5  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Quote Originally Posted by Vili View Post
    Just curious, why does it tell me I don't have any logs a couple times before it actually puts one in the fire though?

    As Tringan stated, you're using an enhanced for loop that isn't even breaking properly. I've rewritten this a tiny bit, there will be some errors no doubt but they should be easy to fix.

    Code:
    public class Bonfire {
    
    
        public enum LogData {
    
    
            NORMAL(1511, 1, 50.0), OAK(1521, 15, 70.0), WILLOW(1519, 30, 100.0), MAPLE(
                    1517, 45, 151.0), YEW(1515, 60, 212.5), MAGIC(1513, 75, 313.8);
    
    
            /** Field Variables **/
            private final int logIdentifier, levelRequired;
            private final double experienceGained;
    
    
            /**
             * Constructs the enumerator LogData.
             * 
             * @param logIdentifier
             *            The log being lighted.
             * @param levelRequired
             *            The level required to light the log.
             * @param experienceGained
             *            The experience given for lighting the log.
             */
            private LogData(final int logIdentifier, final int levelRequired,
                    final double experienceGained) {
                this.logIdentifier = logIdentifier;
                this.levelRequired = levelRequired;
                this.experienceGained = experienceGained;
            }
    
    
            /**
             * Publicly constructs logIdentifier.
             * 
             * @return
             */
            public int getLog() {
                return logIdentifier;
            }
    
    
            /**
             * Publicly constructs levelRequired.
             * 
             * @return
             */
            public int getLevel() {
                return levelRequired;
            }
    
    
            /**
             * Publicly constructs experienceGained.
             * 
             * @return
             */
            public double getExperience() {
                return experienceGained;
            }
    
    
    	static Set<LogData> logs = EnumSet.allOf(LogData.class);
    
    
    	public static getLogData(int itemId) {
    		for(LogData log : logs)
    			if(log.getLogIdentifier() == itemId)
    				return log;
    		return null;
    	}
    
    
        }
        
        /**
         *  Handles the action for bonfires.
         * @param c
         *         Client
         * @param objectId
         *         Object identifier.
         * @param objectX
         *         Object's X coordinate.
         * @param objectY
         *         Object's Y coordinate.
         * @param itemId
         *         Item Identifier.
         */
        public static void bonfireAction(final Client c, final int objectId,
                final int objectX, final int objectY, final int itemId) {
            final String name = c.getItems().getItemName(itemId).toLowerCase();
            final int delay = Misc.random(5) + 3;
            if (Player.isSkilling == true) {
                return;
            }
    	LogData l = LogData.getLogData(itemId);
    	if(l == null) {
    		c.sendMessage("You can only burn logs in the fire.");
    		return;
    	}
            if (c.playerLevel[11] < l.getLevel()) {
                	c.sendMessage("You need level " + l.getLevel()
            	        + " firemaking to bonfire " + name + ".");
             }
             Player.setSkilling(true);
             CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
    
    
                    @Override
                    public void execute(CycleEventContainer container) {
                        if (!Client.isBonfire()) {
                            container.stop();
                        }
                        if (!Server.objectManager.objectExists(objectX, objectY)) {
                            container.stop();
                        }
                        if (c.getItems().getItemAmount(l.getLog()) > 0) {
                            c.startAnimation(894);
                            c.getItems().deleteItem(l.getLog(), 1);
                            c.getPA().addSkillXP((int) l.getExperience(), 11);
                            c.sendMessage("You add the " + name + " to the bonfire.");
                        } else {
                            c.sendMessage("You have run out of logs to throw on the bonfire.");
                            container.stop();
                        }
                    }
    
    
                    @Override
                    public void stop() {
                        Player.setSkilling(false);
                        Client.setBonfire(false);
                    }
    
    
                }, delay);
          }
    }
    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. [PI] Item.cfg bug
    By Exidia in forum Help
    Replies: 18
    Last Post: 12-21-2013, 01:07 AM
  2. Replies: 13
    Last Post: 07-20-2013, 10:02 PM
  3. Pi Item Bug's
    By xoodreyoox in forum Help
    Replies: 1
    Last Post: 06-13-2013, 06:32 PM
  4. [pi] item requirment bug help
    By Right man in forum Help
    Replies: 10
    Last Post: 09-04-2011, 10:01 PM
  5. [508]HD Item Option Bug [will rep]
    By Fearrichy in forum Help
    Replies: 2
    Last Post: 05-18-2009, 01:41 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •