Thread: Issue with Switch & Cases

Results 1 to 6 of 6
  1. #1 Issue with Switch & Cases 
    Jake from State Farm

    FKN Jake's Avatar
    Join Date
    Nov 2013
    Posts
    675
    Thanks given
    45
    Thanks received
    58
    Rep Power
    153
    Alright so before I had the NPC at just 1 location and wanted to expand, the 1 location worked just fine I simply had

    Code:
    NPC NPCraids = new NPC(7286, new Position(3105, 3934));
    						World.sendMessage("@mag@A Raid has started in the Mage Arena");
    Inside the void Sequence. Which is just a 4 hour timer. However the code below does not work. It sends the text but does not send the NPC spawn.

    Code:
    public static void sequence() {
    			if(timer.elapsed(TIME)) {
    				timer.reset();
    				{
    					
    					int random = Misc.getRandom(4);
    					switch(random) {
    					case 0:
    						NPC NPCraids = new NPC(7286, new Position(3105, 3934));
    						World.sendMessage("@mag@A Raid has started in the Mage Arena");
    						break;
    					case 1:
    						NPC NPCraids1 = new NPC(7286, new Position(2973, 3938));
    						World.sendMessage("@mag@A Raid has started South of Thermo Boss Teleport.");
    						break;
    					case 2:
    						NPC NPCraids2 = new NPC(7286, new Position(3054, 10269));
    						World.sendMessage("@mag@A Raid has started in the Death Arena.");
    						break;
    					case 3:
    						NPC NPCraids3 = new NPC(7286, new Position(3195, 3815));
    						World.sendMessage("@mag@A Raid has started East of Venenatis NPC.");
    						break;
    					case 4:
    						NPC NPCraids4 = new NPC(7286, new Position(2984, 3911));
    						World.sendMessage("@mag@A Raid has started West of Wilderness Agility Teleport.");
    						break;
    					}
    					
    			}
    Attached image

    I have a command which initiates sequence.

    If you want to see the whole class -> http://pastebin.com/UWQDCv5H

    Will Rep+,

    Thanks.
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Apr 2016
    Posts
    148
    Thanks given
    46
    Thanks received
    30
    Rep Power
    19
    You've created a new NPC object but haven't actually spawned the NPC. In the typical server you would do:

    NpcHandler.spawnNpc(id, x, y .....);
    Reply With Quote  
     

  3. #3  
    Jake from State Farm

    FKN Jake's Avatar
    Join Date
    Nov 2013
    Posts
    675
    Thanks given
    45
    Thanks received
    58
    Rep Power
    153
    Quote Originally Posted by Deadman World View Post
    You've created a new NPC object but haven't actually spawned the NPC. In the typical server you would do:

    NpcHandler.spawnNpc(id, x, y .....);
    Okay I added y but I don't see what you're getting at with the .....

    Code:
    	public Position(int x, int y, int z) {
    		this.x = x;
    		this.y = y;
    		this.z = z;
    	}
    I don't have NPCHandler just NPC.

    Here is an example from Pest Control.

    Code:
    private static void spawnMainNPCs() {
    		int knightHealth = 3000 - (PLAYERS_IN_BOAT * 14);
    		int portalHealth = getDefaultPortalConstitution();
    		knight = spawnPCNPC(3782, new Position(2656,2592), knightHealth); //knight
    		portals[0] = spawnPCNPC(6142, new Position(2628,2591), portalHealth); //purple
    		portals[1] = spawnPCNPC(6143, new Position(2680,2588), portalHealth); //red
    		portals[2] = spawnPCNPC(6144, new Position(2669,2570), portalHealth); //blue
    		portals[3] = spawnPCNPC(6145, new Position(2645,2569), portalHealth); //yellow
    		npcList.add(knight);
    Changed to the following and no luck.

    Code:
    	public final class Raids {
    		/**
    		 * 1 hour timer that resets.
    		 */
    		private static final int TIME = 14400000;
    		/*
    		 * Calls the Stopwatch to keep track of time.
    		 */
    		public static Stopwatch timer = new Stopwatch().reset();
    		private static CopyOnWriteArrayList<NPC> npcList = new CopyOnWriteArrayList<NPC>();
    		/**
    		 * Spawns the NPC and resets the timer (4 hours)
    		 */
    		private static NPC[] raid = new NPC[5];
    		
    		public static void sequence() {
    			if(timer.elapsed(TIME)) {
    				timer.reset();
    				{
    					
    					int random = Misc.getRandom(4);
    					switch(random) {
    					case 0:
    						raid[0] = new NPC(7286, new Position(3105, 3934, 0));
    						World.sendMessage("@mag@A Raid has started in the Mage Arena");
    						break;
    					case 1:
    						raid[1] = new NPC(7286, new Position(2973, 3938, 0));
    						World.sendMessage("@mag@A Raid has started South of Thermo Boss Teleport.");
    						break;
    					case 2:
    						raid[2] = new NPC(7286, new Position(3054, 10269, 0));
    						World.sendMessage("@mag@A Raid has started in the Death Arena.");
    						break;
    					case 3:
    						raid[3] = new NPC(7286, new Position(3195, 3815, 0));
    						World.sendMessage("@mag@A Raid has started East of Venenatis NPC.");
    						break;
    					case 4:
    						raid[4] = new NPC(7286, new Position(2984, 3911, 0));
    						World.sendMessage("@mag@A Raid has started West of Wilderness Agility Teleport.");
    						break;
    					}
    					
    					for(NPC n : raid) {
    						npcList.add(n);
    					return;
    			}
    		}
    	}			
    }
    	}
    Reply With Quote  
     

  4. #4  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    The second one you created is worse than the first.

    Code:
    public static void sequence() {
    			if(timer.elapsed(TIME)) {
    				timer.reset();
    					int random = Misc.getRandom(4);
    					NPC raid = null;
    					switch(random) {
    					case 0:
    						raid = new NPC(7286, new Position(3105, 3934));
    						World.sendMessage("@mag@A Raid has started in the Mage Arena");
    						break;
    					case 1:
    						raid = new NPC(7286, new Position(2973, 3938));
    						World.sendMessage("@mag@A Raid has started South of Thermo Boss Teleport.");
    						break;
    					case 2:
    						raid = new NPC(7286, new Position(3054, 10269));
    						World.sendMessage("@mag@A Raid has started in the Death Arena.");
    						break;
    					case 3:
    						raid = new NPC(7286, new Position(3195, 3815));
    						World.sendMessage("@mag@A Raid has started East of Venenatis NPC.");
    						break;
    					case 4:
    						raid = new NPC(7286, new Position(2984, 3911));
    						World.sendMessage("@mag@A Raid has started West of Wilderness Agility Teleport.");
    						break;
    					}
    					//You need to add a line here which will spawn the npc, in the matrix sources it'd look like..
    				if (raid != null)
    				World.spawnNPC(raid);
    			}
    }
    Read the code. You're missing the line which spawns the NPC itself. I find it odd though that the code you had before functioned as it was missing the spawning just as well, however this one with exact same code doesn't function. Odd.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Apr 2016
    Posts
    148
    Thanks given
    46
    Thanks received
    30
    Rep Power
    19
    post NPC() and spawnPCNPC() methods
    Reply With Quote  
     

  6. #6  
    Jake from State Farm

    FKN Jake's Avatar
    Join Date
    Nov 2013
    Posts
    675
    Thanks given
    45
    Thanks received
    58
    Rep Power
    153
    Quote Originally Posted by Kris View Post
    The second one you created is worse than the first.

    Code:
    public static void sequence() {
    			if(timer.elapsed(TIME)) {
    				timer.reset();
    					int random = Misc.getRandom(4);
    					NPC raid = null;
    					switch(random) {
    					case 0:
    						raid = new NPC(7286, new Position(3105, 3934));
    						World.sendMessage("@mag@A Raid has started in the Mage Arena");
    						break;
    					case 1:
    						raid = new NPC(7286, new Position(2973, 3938));
    						World.sendMessage("@mag@A Raid has started South of Thermo Boss Teleport.");
    						break;
    					case 2:
    						raid = new NPC(7286, new Position(3054, 10269));
    						World.sendMessage("@mag@A Raid has started in the Death Arena.");
    						break;
    					case 3:
    						raid = new NPC(7286, new Position(3195, 3815));
    						World.sendMessage("@mag@A Raid has started East of Venenatis NPC.");
    						break;
    					case 4:
    						raid = new NPC(7286, new Position(2984, 3911));
    						World.sendMessage("@mag@A Raid has started West of Wilderness Agility Teleport.");
    						break;
    					}
    					//You need to add a line here which will spawn the npc, in the matrix sources it'd look like..
    				if (raid != null)
    				World.spawnNPC(raid);
    			}
    }
    Read the code. You're missing the line which spawns the NPC itself. I find it odd though that the code you had before functioned as it was missing the spawning just as well, however this one with exact same code doesn't function. Odd.
    I was tired it was 6am lol. I forgot to add World.register(NPCraids); under each spawn line. Thank you.
    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. Link cases with the baby cases
    By buck in forum Help
    Replies: 8
    Last Post: 08-20-2009, 08:22 AM
  2. Replies: 0
    Last Post: 06-23-2009, 02:19 PM
  3. Having issues with stalls.
    By Demetri in forum Help
    Replies: 3
    Last Post: 02-28-2009, 06:14 AM
  4. Issue with models on webclient
    By bazinger in forum Help
    Replies: 0
    Last Post: 12-05-2008, 11:25 AM
  5. Replacing lots of if statements with switch's.
    By Stanyer in forum Tutorials
    Replies: 6
    Last Post: 02-07-2008, 03:08 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
  •