Thread: how to make this command work with spaces in a players name

Results 1 to 5 of 5
  1. #1 how to make this command work with spaces in a players name 
    Chow down on these noodles
    OodlesOfNoodles's Avatar
    Join Date
    May 2011
    Posts
    1,821
    Thanks given
    235
    Thanks received
    91
    Rep Power
    55
    how would i get this command ::xnpcother to work on players with spaces in their names?
    Code:
    if (playerCommand.startsWith("xnpcother")) {
    				try {	
    					String[] args = playerCommand.split(" ");
    					String otherplayer = args[1];
    					int newNPC = Integer.parseInt(args[2]);
    					for(int i = 0; i < Config.MAX_PLAYERS; i++) {
    						if(Server.playerHandler.players[i] != null) {
    							if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(otherplayer)) {
    							Client c2 = (Client)Server.playerHandler.players[i];
    								c2.npcId2 = newNPC;
                          	 			                                                c2.isNpc = true;
                            				                                                c2.updateRequired = true;
                            				                                                c2.setAppearanceUpdateRequired(true);
    								c2.sendMessage("You have been turned into an NPC by: " + c.playerName);
    							break;
    						} 
    					}
    				}
    			} catch(Exception e) {
    				c.sendMessage("Player Must Be Offline.");
     		 }			
    	}
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    Registered Member Stewie1million's Avatar
    Join Date
    Jun 2011
    Posts
    588
    Thanks given
    2
    Thanks received
    56
    Rep Power
    14
    Change:
    Code:
    String[] args = playerCommand.split(" ");
    To:
    Code:
    String[] args = playerCommand.split(" ", 2);
    Reply With Quote  
     

  3. #3  
    ಠ_ಠ

    Joshua's Avatar
    Join Date
    May 2010
    Posts
    1,907
    Thanks given
    397
    Thanks received
    708
    Rep Power
    803
    A cheap hax would be to replace the seperation between command sections with something other than spaces.

    Example:

    ::xnpcother_Player Name_NpcId

    An even easier way would be to just load the player name from the end of the command. IE, after the second space so the code would be:

    ::xnpcother NpcId Player Name




    [Only registered and activated users can see links. ]

    Spoiler for Eye Bleach & Recent Releases:



    [Only registered and activated users can see links. ]

    [Only registered and activated users can see links. ]

    [Only registered and activated users can see links. ]

    [Only registered and activated users can see links. ]

    [Only registered and activated users can see links. ]


    Reply With Quote  
     

  4. #4  
    Chow down on these noodles
    OodlesOfNoodles's Avatar
    Join Date
    May 2011
    Posts
    1,821
    Thanks given
    235
    Thanks received
    91
    Rep Power
    55
    yea tried that didnt work v_v
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  5. #5  
    Kacey
    I Am Kacey's Avatar
    Join Date
    May 2011
    Posts
    738
    Thanks given
    243
    Thanks received
    56
    Rep Power
    19
    String[] args = playerCommand.split(" ");
    if (args.length == 3) {

    Your method here.
    }

    Try this?

    or this

    if (playerCommand.startsWith("xnpcother")) {
    String name = playerCommand.substring(9);
    for(int i = 0; i < Config.MAX_PLAYERS; i++) {
    if(Server.playerHandler.players[i] != null) {
    if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(otherplayer)) {
    Client c2 = (Client)Server.playerHandler.players[i];
    c2.npcId2 = newNPC;
    c2.isNpc = true;
    c2.updateRequired = true;
    c2.setAppearanceUpdateRequired(true);
    c2.sendMessage("You have been turned into an NPC by: " + c.playerName);
    break;
    }
    }
    }
    } catch(Exception e) {
    c.sendMessage("Player Must Be Offline.");
    }
    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. how to make players not have spaces in thier name
    By OodlesOfNoodles in forum Help
    Replies: 2
    Last Post: 11-13-2011, 09:51 PM
  2. how to make this command work right
    By OodlesOfNoodles in forum Help
    Replies: 4
    Last Post: 11-07-2011, 03:27 AM
  3. Replies: 21
    Last Post: 02-13-2011, 02:49 PM
  4. Replies: 2
    Last Post: 03-18-2010, 08:23 PM
  5. Replies: 1
    Last Post: 08-21-2009, 03:02 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
  •