Thread: ZombieKilled Npc handler Crashes Server

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 ZombieKilled Npc handler Crashes Server 
    EpicPks Is Back!

    Join Date
    Jun 2012
    Posts
    480
    Thanks given
    12
    Thanks received
    16
    Rep Power
    29


    This is the code

    if (npcs[i].isDead == true) {
    if (npcs[i].actionTimer == 0 && npcs[i].applyDead == false && npcs[i].needRespawn == false) {
    npcs[i].updateRequired = true;
    npcs[i].facePlayer(0);
    npcs[i].killedBy = getNpcKillerId(i);
    npcs[i].animNumber = getDeadEmote(i); // dead emote
    npcs[i].animUpdateRequired = true;
    npcs[i].freezeTimer = 0;
    npcs[i].applyDead = true;
    killedBarrow(i);
    if (isZombieCaveNpc(i))
    killedZombies(i);
    if (isFightCaveNpc(i))
    killedTzhaar(i);
    if(npcs[i].summon == true)
    npcs[i].summon = false;
    npcs[i].actionTimer = 4; // delete time
    resetPlayersInCombat(i);
    /*if (npcs[i].npcType == 1158){
    handleKalpite(i);
    }*/
    Code:
    		private void killedZombies(int i) {
    		final Client c2 = (Client)Server.playerHandler.players[npcs[i].spawnedBy];
    		c2.zombiesKilled++;
    		System.out.println("To kill: " + c2.zombiesToKill + " killed: " + c2.zombiesKilled);
    		if (c2.zombiesKilled == c2.zombiesToKill) {
    			//c2.sendMessage("STARTING EVENT");
    			c2.waveId++;
    			CycleEventHandler.getSingleton().addEvent(c2, new CycleEvent() {
    		@Override
    		public void execute(CycleEventContainer c) {
    					if (c2 != null) {
    						Server.zombieCaves.spawnNextWave(c2);
    					}	
    					c.stop();
    				}
    Help Please.
    Reply With Quote  
     

  2. #2  
    Father Of Lies


    Join Date
    May 2012
    Age
    26
    Posts
    1,216
    Thanks given
    267
    Thanks received
    289
    Rep Power
    242
    out of the code provided, which is line 2315?
    Reply With Quote  
     

  3. #3  
    EpicPks Is Back!

    Join Date
    Jun 2012
    Posts
    480
    Thanks given
    12
    Thanks received
    16
    Rep Power
    29
    Quote Originally Posted by Chelsea Grin View Post
    out of the code provided, which is line 2315?
    2315 --> c2.zombiesKilled++;
    Reply With Quote  
     

  4. #4  
    Father Of Lies


    Join Date
    May 2012
    Age
    26
    Posts
    1,216
    Thanks given
    267
    Thanks received
    289
    Rep Power
    242
    Quote Originally Posted by djzone24 View Post
    2315 --> c2.zombiesKilled++;
    if the integer is null, adding to it will give a null pointer. set the default value to 0
    Reply With Quote  
     

  5. #5  
    EpicPks Is Back!

    Join Date
    Jun 2012
    Posts
    480
    Thanks given
    12
    Thanks received
    16
    Rep Power
    29
    Quote Originally Posted by Chelsea Grin View Post
    if the integer is null, adding to it will give a null pointer. set the default value to 0
    I'm not sure how to initialise the integer to 0 in this setting. would it simply be int c2.Zombieskilled = 0; ?
    Reply With Quote  
     

  6. #6  
    Registered Member
    Hoodlum's Avatar
    Join Date
    Jul 2010
    Age
    29
    Posts
    1,561
    Thanks given
    84
    Thanks received
    248
    Rep Power
    1251
    Quote Originally Posted by djzone24 View Post
    I'm not sure how to initialise the integer to 0 in this setting. would it simply be int c2.Zombieskilled = 0; ?
    Just make the variable zombiesKilled = 0;
    Quote Originally Posted by zzzfishstick View Post
    Soul split? How the hell did you get their source? And isn't it based off InsidiaX?
    Reply With Quote  
     

  7. #7  
    EpicPks Is Back!

    Join Date
    Jun 2012
    Posts
    480
    Thanks given
    12
    Thanks received
    16
    Rep Power
    29
    Quote Originally Posted by Hoodlum View Post
    Just make the variable zombiesKilled = 0;

    Thanks I'll assume it's fixed.
    Reply With Quote  
     

  8. #8  
    Banned
    Join Date
    Apr 2012
    Posts
    479
    Thanks given
    36
    Thanks received
    72
    Rep Power
    0
    Code:
    		private void killedZombies(int i) {
    		final Client c2 = (Client)Server.playerHandler.players[npcs[i].spawnedBy];
    if (c2 == null) return;
    		c2.zombiesKilled++;
    		System.out.println("To kill: " + c2.zombiesToKill + " killed: " + c2.zombiesKilled);
    		if (c2.zombiesKilled == c2.zombiesToKill) {
    			//c2.sendMessage("STARTING EVENT");
    			c2.waveId++;
    			CycleEventHandler.getSingleton().addEvent(c2, new CycleEvent() {
    		@Override
    		public void execute(CycleEventContainer c) {
    					if (c2 != null) {
    						Server.zombieCaves.spawnNextWave(c2);
    					}	
    					c.stop();
    				}
    Reply With Quote  
     

  9. #9  
    Registered Member
    TheChosenOne's Avatar
    Join Date
    Jan 2013
    Posts
    967
    Thanks given
    47
    Thanks received
    161
    Rep Power
    366
    zombiesKilled is a primitive datatype, which can never be null (if you don't consider an array to be primitive).
    Therefore, c2 is the only object able to be the null.
    SGPK's answer is the answer closest to the truth. He/she recognised the c2 variable as the source of the NullPointerException.

    But rather than throwing in his 'if(c2 == null) return;", I'd look more into why it is null.
    If "c2" is null then "Server.playerHandler.players[npcs[i].spawnedBy];" is null.
    Neither "Server", "Server.playerHandler" or "Server.playerHandler.players" is null.
    There is however, a null objects inside the array at index "npcs[i].spawnedBy".
    If the rest of your code is correct, I can only assume spawnedBy isn't the correct index.
    Reply With Quote  
     

  10. Thankful user:


  11. #10  
    Banned

    Join Date
    Jul 2011
    Posts
    691
    Thanks given
    163
    Thanks received
    161
    Rep Power
    0
    This is why we utilize try and catch. Will prevent server crashes, and player disconnections

    Like this:
    Code:
    	private void killedZombies(int i) {
    		final Client c2 = (Client)Server.playerHandler.players[npcs[i].spawnedBy];
    		try{
    			c2.zombiesKilled++;
    			System.out.println("To kill: " + c2.zombiesToKill + " killed: " + c2.zombiesKilled);
    			if (c2.zombiesKilled == c2.zombiesToKill) {
    				//c2.sendMessage("STARTING EVENT");
    				c2.waveId++;
    				CycleEventHandler.getSingleton().addEvent(c2, new CycleEvent() {
    			@Override
    			public void execute(CycleEventContainer c) {
    						if (c2 != null) {
    							Server.zombieCaves.spawnNextWave(c2);
    						}	
    						c.stop();
    					}
    				}
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    Reply With Quote  
     

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. NPC clipping crashes server
    By swednpk in forum Help
    Replies: 2
    Last Post: 01-19-2013, 07:34 PM
  2. [PI]Server Crashes
    By Nutella in forum Help
    Replies: 13
    Last Post: 04-08-2012, 08:56 PM
  3. z508 server crashes
    By pure barrage in forum Help
    Replies: 1
    Last Post: 11-03-2009, 08:05 AM
  4. [525] Server Crashes Help rep++
    By White. in forum Help
    Replies: 7
    Last Post: 04-14-2009, 02:26 PM
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
  •