Thread: Packet 72 - NullPointerException?

Results 1 to 6 of 6
  1. #1 Packet 72 - NullPointerException? 
    Registered Member
    Deadly Uzi's Avatar
    Join Date
    Jul 2008
    Posts
    994
    Thanks given
    177
    Thanks received
    87
    Rep Power
    362
    Hello!

    I have a problem that is delaying me MAJORLY and makes me want to stop using RS2D because I have absolutely NO IDEA how to fix it.

    The problem is that when I click to attack an NPC(Packet 72), the system goes through a method which like calls the attackNPC method in a different class, sets the attackers blah blah blah .

    The problem is that it gives me a NullPointerException!

    I have a class called CombatCaller, which deals with the packets, and I have a class called CombatController which actually manages what happens in combat.

    Here, the classes aren't long so I'll just copy paste both of them in here -

    Here is the CombatCaller class:

    Code:
    package net.varek.rs2d.packethandler;
    
    import org.apache.mina.common.IoSession;
    
    import net.varek.rs2d.model.NPC;
    import net.varek.rs2d.model.Player;
    import net.varek.rs2d.net.ActionSender;
    import net.varek.rs2d.net.Packet;
    import net.varek.rs2d.scriptengine.Parser;
    import net.varek.rs2d.controller.CombatController;
    import net.varek.rs2d.manager.NPCManager;
    import net.varek.rs2d.manager.ScriptManager;
    
    public class CombatCaller implements PacketHandler {
    
    	private static CombatController Combat;
    
    	public void handlePacket(Packet p, IoSession session) {
    		Player player = (Player) session.getAttachment();
    		ActionSender sender = player.getActionSender();
    
    		if (p.getId() == ATTACK_PLAYER) {
    			handleAttackPlayer(p, player, sender);
    		}
    		if (p.getId() == MAGIC_ON_PLAYER) {
    			handleMagicOnPlayer(p, player, sender);
    		}
    		if (p.getId() == ATTACK_NPC) {
    			handleAttackNPC(p, player, sender);
    		}
    		if (p.getId() == MAGIC_ON_NPC) {
    			handleMagicOnNPC(p, player, sender);
    		}
    	}
    
    	static void handleAttackPlayer(Packet p, Player player, ActionSender sender) {
    		int victim = p.readShortA();
    		
    		Combat.attackPlayer(victim, player);
    	}
    
    	static void handleMagicOnPlayer(Packet p, Player player, ActionSender sender) {
    		sender.sendMessage("You tried to mage a player!");
    	}
    
    	static void handleAttackNPC(Packet p, Player player, ActionSender sender) {
    		int victim = p.readShortA();
    	
    		if (NPCManager.isValid(victim)) {
    			NPC n = NPCManager.getNPC(victim);
    			Parser parser = ScriptManager.getScriptManager().getParser(
    					ScriptManager.GENERAL);
    			int script = parser.call("attacknpc", "" + n.getId(), player);
    			if (Parser.isTrue(script)) {
    				if (Parser.isND(script)) {
    					// no default action
    					return;
    				}
    			}
    
    			System.out.println(player.username + " started attacking an NPC - "
    					+ n);
    			player.setEntityFace(victim);
    			Combat.attackNPC(victim, player);
    		}
    	}
    
    	static void handleMagicOnNPC(Packet p, Player player, ActionSender sender) {
    		sender.sendMessage("You tried to mage a NPC!");
    	}
    
    	public static final int ATTACK_PLAYER = 73;
    	public static final int MAGIC_ON_PLAYER = 249;
    	public static final int ATTACK_NPC = 72;
    	public static final int MAGIC_ON_NPC = 131;
    
    }
    And the CombatController, which actually manages the combat(Well not yet )

    Code:
    package net.varek.rs2d.controller;
    
    import net.varek.rs2d.manager.NPCManager;
    import net.varek.rs2d.model.Player;
    import net.varek.rs2d.model.NPC;
    import net.varek.rs2d.model.PlayerAnimation;
    import net.varek.rs2d.net.ActionSender;
    import net.varek.rs2d.content.skills.ISkill;
    import net.varek.rs2d.content.skills.SkillConstants;
    import net.varek.rs2d.controller.EquipmentController;
    import net.varek.rs2d.manager.ItemManager;
    
    /**
     * @author Martin Date - 4/24/09 Controls attacking and other combat-related
     *         things. Called from the class file CombatController in package:
     *         net.varek.rs2d.packethandler.
     */
    
    public class CombatController {
    
    	private Player player;
    	private ActionSender sender;
    
    	public void attackPlayer(int victim, Player player) { // Handles PVP.
    		sender.sendMessage("You attacked a player with an ID of: " + victim);
    		player.setEntityFace(victim);
    	}
    
    	public void attackNPC(int npc, Player player) { // Handles PVN.
    
    		NPC n = NPCManager.getNPC(npc);
    
    		if (n != null) {
    
    			player.setAnimation(new PlayerAnimation(getAttackAnimation(), 0));
    			
    			int hitAmount = net.varek.rs2d.util.RandomNumber.rand(getMaxHit());
    			n.decreaseHP(hitAmount);
    
    			if (n.isMoveable())
    				n.setMoveable(false);
    		}
    	}
    This also happens with players.

    I appreciate ANY HELP, seriously.

    I will be the bitch of the person who solves this problem for me(Not really)

    Thanks in advance, A LOT!
    -Deadly Uzi
    Attempting to develop a multi-revision library. See it on GitHub.
    Reply With Quote  
     

  2. #2  
    #Flippergang

    Alberto's Avatar
    Join Date
    May 2008
    Posts
    756
    Thanks given
    46
    Thanks received
    40
    Rep Power
    121
    Could you post the error you get?
    Hopes and Dreams
    Need something programmed and willing to pay?
    Pm me.
    Reply With Quote  
     

  3. #3  
    Registered Member Paketa's Avatar
    Join Date
    Oct 2007
    Posts
    2,681
    Thanks given
    17
    Thanks received
    82
    Rep Power
    680
    Show me the complete error in your cmd box and I might be able to help.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Deadly Uzi's Avatar
    Join Date
    Jul 2008
    Posts
    994
    Thanks given
    177
    Thanks received
    87
    Rep Power
    362
    I can't really post the code because I have to turn on the IDE and all.

    But the FIRST line it points out is the line which calls the CombatController class,

    Combat.attackNPC(victim, player);
    Attempting to develop a multi-revision library. See it on GitHub.
    Reply With Quote  
     

  5. #5  
    Member Packet 72 - NullPointerException? Market Banned


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    35
    Posts
    12,574
    Thanks given
    199
    Thanks received
    7,106
    Rep Power
    5000
    I'm gonna take a wild guess and guess that your stream method for getting the playerId is wrong therefore it's returning a null/non existing Player class..but until you post the actual error lines that's all it is, a guess .

    Attached imageAttached image
    Reply With Quote  
     

  6. #6  
    Registered Member
    Deadly Uzi's Avatar
    Join Date
    Jul 2008
    Posts
    994
    Thanks given
    177
    Thanks received
    87
    Rep Power
    362
    I know, I used the same method(It's packet actually, the variable p is Packet) for players. But the problem is the NPC... If I fix the NPC, then I can fix the NullPointer that gives when I attack a player, that is if I find the right Packet method for the playerId.

    So the real problem is the NPC.
    Attempting to develop a multi-revision library. See it on GitHub.
    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

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