Thread: CrossBow Error

Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19
  1. #11  
    I need some more coffee

    Jason's Avatar
    Join Date
    Aug 2009
    Age
    26
    Posts
    6,101
    Thanks given
    2,384
    Thanks received
    2,796
    Rep Power
    4343
    Code:
    public static void crossbowSpecial(Client c, int i) {
        Player[] players = PlayerHandler.players;
    
    
        if (i < 0 || i > players.length - 1) {
            throw new IllegalStateException("Cannot perform special on index outside of player capacity.");
        }
        Client p = (Client) players[i];
    
    
        // other code
    }
    The great thing about this is when the conditions are met, an exception is thrown that will provide insight into the cause of the problem.
    Reply With Quote  
     

  2. Thankful user:


  3. #12  
    Registered Member
    Join Date
    Nov 2014
    Posts
    238
    Thanks given
    2
    Thanks received
    0
    Rep Power
    0
    Quote Originally Posted by Jason View Post
    Code:
    public static void crossbowSpecial(Client c, int i) {
        Player[] players = PlayerHandler.players;
    
    
        if (i < 0 || i > players.length - 1) {
            throw new IllegalStateException("Cannot perform special on index outside of player capacity.");
        }
        Client p = (Client) players[i];
    
    
        // other code
    }
    The great thing about this is when the conditions are met, an exception is thrown that will provide insight into the cause of the problem.
    Code:
    [10/23/19, 3:30 PM]: java.lang.IllegalStateException: Cannot perform special on index outside of player capacity.
    [10/23/19, 3:30 PM]: 	at server.model.players.combat.range.RangeExtras.crossbowSpecial(RangeExtras.java:53)
    [10/23/19, 3:30 PM]: 	at server.model.players.CombatAssistant.crossbowSpecial(CombatAssistant.java:316)
    [10/23/19, 3:30 PM]: 	at server.model.players.combat.AttackNPC.delayedHit(AttackNPC.java:216)
    [10/23/19, 3:30 PM]: 	at server.model.players.CombatAssistant.delayedHit(CombatAssistant.java:124)
    [10/23/19, 3:30 PM]: 	at server.model.players.Client.process(Client.java:859)
    [10/23/19, 3:30 PM]: 	at server.model.players.PlayerHandler.process(PlayerHandler.java:151)
    [10/23/19, 3:30 PM]: 	at server.Server$1.execute(Server.java:239)
    [10/23/19, 3:30 PM]: 	at server.event.Task.tick(Task.java:118)
    [10/23/19, 3:30 PM]: 	at server.event.TaskScheduler.run(TaskScheduler.java:103)
    [10/23/19, 3:30 PM]: 	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    [10/23/19, 3:30 PM]: 	at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
    [10/23/19, 3:30 PM]: 	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
    [10/23/19, 3:30 PM]: 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    [10/23/19, 3:30 PM]: 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    [10/23/19, 3:30 PM]: 	at java.base/java.lang.Thread.run(Thread.java:835)
    Reply With Quote  
     

  4. #13  




    Scu11's Avatar
    Join Date
    Aug 2007
    Age
    25
    Posts
    16,053
    Thanks given
    7,047
    Thanks received
    11,828
    Rep Power
    5000
    Quote Originally Posted by Jason View Post
    Code:
    public static void crossbowSpecial(Client c, int i) {
        Player[] players = PlayerHandler.players;
    
    
        if (i < 0 || i > players.length - 1) {
            throw new IllegalStateException("Cannot perform special on index outside of player capacity.");
        }
        Client p = (Client) players[i];
    
    
        // other code
    }
    The great thing about this is when the conditions are met, an exception is thrown that will provide insight into the cause of the problem.
    That produces even less useful information in the stacktrace than before... previously it would have thrown an IndexOutOfBoundsException that detailed the actual length of the array and the index you were trying to lookup - now you've removed both of those pieces of information and replaced it with an IllegalStateException that always has the same message.

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  5. Thankful user:


  6. #14  
    I need some more coffee

    Jason's Avatar
    Join Date
    Aug 2009
    Age
    26
    Posts
    6,101
    Thanks given
    2,384
    Thanks received
    2,796
    Rep Power
    4343
    Quote Originally Posted by Scu11 View Post
    That produces even less useful information in the stacktrace than before... previously it would have thrown an IndexOutOfBoundsException that detailed the actual length of the array and the index you were trying to lookup - now you've removed both of those pieces of information and replaced it with an IllegalStateException that always has the same message.
    That is a good point, the message should have been more detailed. I initially thought the exception wasn't being thrown, preventing the user from knowing how the exception was occuring. I didn't see the stack trace initially.

    @OP What is line 53 of RangeExtras? Can you provide the surrounding method as well.
    Reply With Quote  
     

  7. #15  
    Registered Member
    Join Date
    Nov 2014
    Posts
    238
    Thanks given
    2
    Thanks received
    0
    Rep Power
    0
    Quote Originally Posted by Jason View Post
    That is a good point, the message should have been more detailed. I initially thought the exception wasn't being thrown, preventing the user from knowing how the exception was occuring. I didn't see the stack trace initially.

    @OP What is line 53 of RangeExtras? Can you provide the surrounding method as well.
    Yeah, i mean i fixed the problem by boosting up the max players but i also found something else while looking through im wondering if where it says p if those should be n's to state its referring to the npcs and not another player

    Code:
    public static void crossbowSpecial(Client c, int i) {
    		Client p = (Client)PlayerHandler.players[i]; //  error part
    		NPC n = (NPC)NPCHandler.npcs[i];
    
    		c.crossbowDamage = 1.4;
    
    		switch (c.lastArrowUsed) {
    			case 9236: // Lucky Lightning
    				createCombatGFX(c, i, 749, false);
    				c.crossbowDamage = 1.25;
    				break;
    			case 9237: // Earth's Fury
    				createCombatGFX(c, i, 755, false);
    				break;
    			case 9238: // Sea Curse
    				createCombatGFX(c, i, 750, false);
    				c.crossbowDamage = 1.10;
    				break;
    			case 9239: // Down to Earth
    				createCombatGFX(c, i, 757, false);
     				if(c.playerIndex > 0) {
    					p.playerLevel[6] -= 2;
    					p.getPA().refreshSkill(6);
    					p.sendMessage("Your magic has been lowered!");
    				}
    				break;
    			case 9240: // Clear Mind
    				createCombatGFX(c, i, 751, false);
    				if(c.playerIndex > 0) {
    					p.playerLevel[5] -= 2;
    					p.getPA().refreshSkill(5);
    					p.sendMessage("Your prayer has been lowered!");
    					c.playerLevel[5] += 2;
    					if(c.playerLevel[5] >= c.getPA().getLevelForXP(c.playerXP[5])) {
    						c.playerLevel[5] = c.getPA().getLevelForXP(c.playerXP[5]);
    					}
    					c.getPA().refreshSkill(5);
    				}
    				break;
    			case 9241: // Magical Posion
    				createCombatGFX(c, i, 752, false);
    				if(c.playerIndex > 0) {
    					p.getPA().appendPoison(6);
    				}
    				break;
    			case 9242: // Blood Forfiet
    				createCombatGFX(c, i, 754, false);
    
    				if(c.playerLevel[3] - c.playerLevel[3]/20 < 1) {
    					break;
    				}
    				c.handleHitMask(c.playerLevel[3]/20);
    				c.dealDamage(c.playerLevel[3]/20);
    				if(c.npcIndex > 0) {
    					n.handleHitMask(n.HP/10);
    					n.dealDamage(n.HP/10);
    				} else if(c.playerIndex > 0) {
    					p.handleHitMask(c.playerLevel[3]/10);
    					p.dealDamage(c.playerLevel[3]/10);
    				}
    				break;
    			case 9243: // Armour Piercing
    				createCombatGFX(c, i, 758, true);
    				c.crossbowDamage = 1.15;
    				c.ignoreDefence = true;
    				break;
    				
    				
    			case 9244: // Dragon's Breath
    				createCombatGFX(c, i, 756, false);
    				if(c.playerEquipment[c.playerShield] != 1540 || c.playerEquipment[c.playerShield] != 11283
    					|| c.playerEquipment[c.playerShield] != 11284) {
    						c.crossbowDamage = 1.48;
    				}
    				break;
    				
    				
    			case 9245:
                    createCombatGFX(c, i, 753, true);
                    c.crossbowDamage = 1.15;
                    int heal = (int) (c.boltDamage / 3);
                    if (c.playerLevel[3] + heal > c.getPA().getLevelForXP
                                    (c.playerXP[3])) {
                                            c.playerLevel[3] = c.getPA().getLevelForXP(c.playerXP[3]);
                                    } else {
                                            c.playerLevel[3] += heal;
                                            c.sendMessage("You heal 25% of your current hit.");
                                    }
                    break;
    		}
    	}
    Reply With Quote  
     

  8. #16  
    I need some more coffee

    Jason's Avatar
    Join Date
    Aug 2009
    Age
    26
    Posts
    6,101
    Thanks given
    2,384
    Thanks received
    2,796
    Rep Power
    4343
    Quote Originally Posted by scoping king View Post
    Yeah, i mean i fixed the problem by boosting up the max players but i also found something else while looking through im wondering if where it says p if those should be n's to state its referring to the npcs and not another player

    Code:
    public static void crossbowSpecial(Client c, int i) {
            Client p = (Client)PlayerHandler.players[i]; //  error part
            NPC n = (NPC)NPCHandler.npcs[i];
    
            c.crossbowDamage = 1.4;
    
            switch (c.lastArrowUsed) {
                case 9236: // Lucky Lightning
                    createCombatGFX(c, i, 749, false);
                    c.crossbowDamage = 1.25;
                    break;
                case 9237: // Earth's Fury
                    createCombatGFX(c, i, 755, false);
                    break;
                case 9238: // Sea Curse
                    createCombatGFX(c, i, 750, false);
                    c.crossbowDamage = 1.10;
                    break;
                case 9239: // Down to Earth
                    createCombatGFX(c, i, 757, false);
                     if(c.playerIndex > 0) {
                        p.playerLevel[6] -= 2;
                        p.getPA().refreshSkill(6);
                        p.sendMessage("Your magic has been lowered!");
                    }
                    break;
                case 9240: // Clear Mind
                    createCombatGFX(c, i, 751, false);
                    if(c.playerIndex > 0) {
                        p.playerLevel[5] -= 2;
                        p.getPA().refreshSkill(5);
                        p.sendMessage("Your prayer has been lowered!");
                        c.playerLevel[5] += 2;
                        if(c.playerLevel[5] >= c.getPA().getLevelForXP(c.playerXP[5])) {
                            c.playerLevel[5] = c.getPA().getLevelForXP(c.playerXP[5]);
                        }
                        c.getPA().refreshSkill(5);
                    }
                    break;
                case 9241: // Magical Posion
                    createCombatGFX(c, i, 752, false);
                    if(c.playerIndex > 0) {
                        p.getPA().appendPoison(6);
                    }
                    break;
                case 9242: // Blood Forfiet
                    createCombatGFX(c, i, 754, false);
    
                    if(c.playerLevel[3] - c.playerLevel[3]/20 < 1) {
                        break;
                    }
                    c.handleHitMask(c.playerLevel[3]/20);
                    c.dealDamage(c.playerLevel[3]/20);
                    if(c.npcIndex > 0) {
                        n.handleHitMask(n.HP/10);
                        n.dealDamage(n.HP/10);
                    } else if(c.playerIndex > 0) {
                        p.handleHitMask(c.playerLevel[3]/10);
                        p.dealDamage(c.playerLevel[3]/10);
                    }
                    break;
                case 9243: // Armour Piercing
                    createCombatGFX(c, i, 758, true);
                    c.crossbowDamage = 1.15;
                    c.ignoreDefence = true;
                    break;
                    
                    
                case 9244: // Dragon's Breath
                    createCombatGFX(c, i, 756, false);
                    if(c.playerEquipment[c.playerShield] != 1540 || c.playerEquipment[c.playerShield] != 11283
                        || c.playerEquipment[c.playerShield] != 11284) {
                            c.crossbowDamage = 1.48;
                    }
                    break;
                    
                    
                case 9245:
                    createCombatGFX(c, i, 753, true);
                    c.crossbowDamage = 1.15;
                    int heal = (int) (c.boltDamage / 3);
                    if (c.playerLevel[3] + heal > c.getPA().getLevelForXP
                                    (c.playerXP[3])) {
                                            c.playerLevel[3] = c.getPA().getLevelForXP(c.playerXP[3]);
                                    } else {
                                            c.playerLevel[3] += heal;
                                            c.sendMessage("You heal 25% of your current hit.");
                                    }
                    break;
            }
        }
    You didn't answer my question. What was line 53 of RangeExtras (probably outdated now).
    Reply With Quote  
     

  9. #17  
    Registered Member
    Join Date
    Nov 2014
    Posts
    238
    Thanks given
    2
    Thanks received
    0
    Rep Power
    0
    Quote Originally Posted by Jason View Post
    You didn't answer my question. What was line 53 of RangeExtras (probably outdated now).
    Highlighted it in red.
    Reply With Quote  
     

  10. #18  
    Member of the Imagine Cult

    Join Date
    Feb 2013
    Posts
    530
    Thanks given
    0
    Thanks received
    3
    Discord
    Karan#1337
    Rep Power
    37
    The issue is you're not doing a check for whether the target is a NPC or a Player. At the moment, the method is accomodating for both. Grabbing a Player for the index targetted, and a NPC for index targetted. That's why when you attack a NPC with an index higher than the maximum players allowed, it's both trying to get a player for that index and a NPC for that index.
    Reply With Quote  
     

  11. Thankful users:


  12. #19  
    Donator

    Join Date
    May 2018
    Age
    21
    Posts
    27
    Thanks given
    4
    Thanks received
    8
    Discord
    Austin#8138
    Rep Power
    11
    please copy + paste the code for createCombatGFX(Player c, int index, int gfx, Boolean idk)
    if the index is supposed to refer to a player, find a different method for creating combat gfx that is meant for npcs
    Reply With Quote  
     

Page 2 of 2 FirstFirst 12

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 crossbow error
    By is whoopie in forum Help
    Replies: 2
    Last Post: 08-11-2012, 11:04 AM
  2. Chaotic crossbow 4 Errors
    By Prince_ownt in forum Help
    Replies: 9
    Last Post: 12-18-2011, 11:22 PM
  3. Same error over and over?!!
    By phantomphreak in forum Tutorials
    Replies: 4
    Last Post: 09-28-2007, 01:20 AM
  4. [HELP]Render Error
    By Big J in forum General
    Replies: 3
    Last Post: 07-30-2007, 01:01 AM
  5. Error. Please reboot me :)
    By Inside Sin in forum Showcase
    Replies: 4
    Last Post: 05-13-2007, 03:39 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
  •