Thread: Blackmark command

Results 1 to 9 of 9
  1. #1 Blackmark command 
    Registered Member

    Join Date
    Sep 2007
    Posts
    585
    Thanks given
    8
    Thanks received
    7
    Rep Power
    98
    i've added an blackmark system and my command doesn't work right
    this code i use for command

    Code:
    	if (cmd.startsWith("blackmark")) 
    	{
    		try 
    		{
    			String otherPName = cmd.substring(16);
    			int otherPIndex = PlayerManager.getPlayerID(otherPName);
    Client p = (Client) Server.PlayerManager.players[otherPIndex];
    			if (otherPIndex != -1) 
    			{
    				p.Send("A BlackMark has been added to your account.");
    				c.Send("You've added a BlackMark to "+p.playerName+".");
    			} else
    				c.Send("The name doesnt exist."); 
    		} 
    		catch (Exception e) 
    		{ 
    			c.Send("Error; Enter an account to BlackMark.");
    		}
    	}
    when i do ::blackmark (Namehere) i get "Error; Enter an account to blackmark"

    Any idea's?
    Reply With Quote  
     

  2. #2  
    Icy Realm Owner
    Icy Whip's Avatar
    Join Date
    May 2007
    Posts
    1,419
    Thanks given
    30
    Thanks received
    35
    Rep Power
    213
    try this maybe

    Code:
    	if (cmd.startsWith("blackmark")) 
    	{
    String[] cmd = Command.split(" ");
    		try 
    		{
    			String otherPName = Integer.parseInt(cmd[1]);
    			int otherPIndex = PlayerManager.getPlayerID(otherPName);
    Client p = (Client) Server.PlayerManager.players[otherPIndex];
    			if (otherPIndex != -1) 
    			{
    				p.Send("A BlackMark has been added to your account.");
    				c.Send("You've added a BlackMark to "+p.playerName+".");
    			} else
    				c.Send("The name doesnt exist."); 
    		} 
    		catch (Exception e) 
    		{ 
    			c.Send("Error; Enter an account to BlackMark.");
    		}
    	}
    [Only registered and activated users can see links. ]

    Signature made by Mr. Ervis

    Any questions, MSN me; [Only registered and activated users can see links. ]
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Sep 2007
    Posts
    585
    Thanks given
    8
    Thanks received
    7
    Rep Power
    98
    Will give me 3 errors..

    Code:
    .\Command.java:199: cmd is already defined in customCommand(Client,java.lang.Str
    ing)
    String[] cmd = Command.split(" ");
             ^
    .\Command.java:199: cannot find symbol
    symbol  : method split(java.lang.String)
    location: class Command
    String[] cmd = Command.split(" ");
                          ^
    .\Command.java:202: incompatible types
    found   : int
    required: java.lang.String
                            String otherPName = Integer.parseInt(cmd[1]);
                                                                ^
    Note: .\Stream.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    3 errors
    Druk op een toets om door te gaan. . .
    Reply With Quote  
     

  4. #4  
    Icy Realm Owner
    Icy Whip's Avatar
    Join Date
    May 2007
    Posts
    1,419
    Thanks given
    30
    Thanks received
    35
    Rep Power
    213
    Quote Originally Posted by lemby pk View Post
    Will give me 3 errors..

    Code:
    .\Command.java:199: cmd is already defined in customCommand(Client,java.lang.Str
    ing)
    String[] cmd = Command.split(" ");
             ^
    .\Command.java:199: cannot find symbol
    symbol  : method split(java.lang.String)
    location: class Command
    String[] cmd = Command.split(" ");
                          ^
    .\Command.java:202: incompatible types
    found   : int
    required: java.lang.String
                            String otherPName = Integer.parseInt(cmd[1]);
                                                                ^
    Note: .\Stream.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    3 errors
    Druk op een toets om door te gaan. . .
    for the first error just remove that string cmd code, for the second one whatever your command void is called replace it with that, like for each command you have like

    Code:
    Command.startsWith("unmute")
    
    or 
    
    Cmd.startsWith("unmute")
    whatever it is replace my Command. with what yours is.
    and for the third error, replace it with whatever yours is.

    but i shouldnt have to spoon feed you exactly what it is, with your own source you should know that I won't know your exact ints, voids, strings ect. Just replace mine with yours.
    [Only registered and activated users can see links. ]

    Signature made by Mr. Ervis

    Any questions, MSN me; [Only registered and activated users can see links. ]
    Reply With Quote  
     

  5. #5  
    Registered Member
    Its paris's Avatar
    Join Date
    Apr 2009
    Posts
    1,141
    Thanks given
    56
    Thanks received
    228
    Rep Power
    689
    I'm gonna do a prediction.
    When you add e.printStackTrace() to the catch side of the try-catch, you'll see you have an arrayOutOfBoundsException.

    Code:
    int otherPIndex = PlayerManager.getPlayerID(otherPName);
    Client p = (Client) Server.PlayerManager.players[otherPIndex];
    			if (otherPIndex != -1) 
    			{
    At the if line, you anticipate the index can be -1. Now look at the line above and guess what'll happen when it really is -1.
    That's right, arrayOutOfBoundsException.

    The most simple (and sufficient) thing to do is switch 2 lines (including the { ):
    Code:
    int otherPIndex = PlayerManager.getPlayerID(otherPName);
    if (otherPIndex != -1)
    { 
    	Client p = (Client) Server.PlayerManager.players[otherPIndex];
    Reply With Quote  
     

  6. #6  
    Registered Member MadZ's Avatar
    Join Date
    Dec 2009
    Posts
    143
    Thanks given
    0
    Thanks received
    3
    Rep Power
    16
    Try this,

    Code:
    	if (cmd.startsWith("blackmark")) 
    	{
    		try 
    		{
    			String otherPName = cmd.substring(11);
    			int otherPIndex = PlayerManager.getPlayerID(otherPName);
    Client p = (Client) Server.PlayerManager.players[otherPIndex];
    			if (otherPIndex != -1) 
    			{
    				p.Send("A BlackMark has been added to your account.");
    				c.Send("You've added a BlackMark to "+p.playerName+".");
    			} else
    				c.Send("The name doesnt exist."); 
    		} 
    		catch (Exception e) 
    		{ 
    			c.Send("Error; Enter an account to BlackMark.");
    		}
    	}
    [SBD="- Renegade"] Failure to play iCraig.[/SBD]
    Reply With Quote  
     

  7. #7  
    Registered Member
    Its paris's Avatar
    Join Date
    Apr 2009
    Posts
    1,141
    Thanks given
    56
    Thanks received
    228
    Rep Power
    689
    It's the substring starting from 10. Remember it starts with 0, and it still has a space after the "blackmark" itself.
    Reply With Quote  
     

  8. #8  
    Registered Member MadZ's Avatar
    Join Date
    Dec 2009
    Posts
    143
    Thanks given
    0
    Thanks received
    3
    Rep Power
    16
    Quote Originally Posted by TheChosenOne View Post
    It's the substring starting from 10. Remember it starts with 0, and it still has a space after the "blackmark" itself.

    Yeah, I changed it in the the post above yours.
    [SBD="- Renegade"] Failure to play iCraig.[/SBD]
    Reply With Quote  
     

  9. #9  
    Registered Member

    Join Date
    Sep 2007
    Posts
    585
    Thanks given
    8
    Thanks received
    7
    Rep Power
    98
    Quote Originally Posted by TheChosenOne View Post
    I'm gonna do a prediction.
    When you add e.printStackTrace() to the catch side of the try-catch, you'll see you have an arrayOutOfBoundsException.

    Code:
    int otherPIndex = PlayerManager.getPlayerID(otherPName);
    Client p = (Client) Server.PlayerManager.players[otherPIndex];
    			if (otherPIndex != -1) 
    			{
    At the if line, you anticipate the index can be -1. Now look at the line above and guess what'll happen when it really is -1.
    That's right, arrayOutOfBoundsException.

    The most simple (and sufficient) thing to do is switch 2 lines (including the { ):
    Code:
    int otherPIndex = PlayerManager.getPlayerID(otherPName);
    if (otherPIndex != -1)
    { 
    	Client p = (Client) Server.PlayerManager.players[otherPIndex];
    I've moved those 2 lines..But i still get the same message "Error; Enter an account to blackmark."

    I've tryed using e.printStackTrace() But it i got a error..

    So i used e.getMessage() then i get this

    "Error; Enter account to blackmark.Null"



    EDIT: i've just noticed that NONE of my commands actually works..They all give error, Or Name Doesnt exist stuff..

    my base is Richscape v4.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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