Thread: [Amateur coder] Making first command.

Page 1 of 3 123 LastLast
Results 1 to 10 of 24
  1. #1 [Amateur coder] Making first command. 
    Registered Member
    shed's Avatar
    Join Date
    Dec 2010
    Posts
    1,835
    Thanks given
    504
    Thanks received
    576
    Rep Power
    5000
    Hello rune-server, i have recently started with my passion towards learning java and some other software developing languages.

    I'm still 16 and I want to study computer engineering in the university hopefully.

    I'm buying a Java book soon for amateurs so i can start my way with java, but for now I'm just looking at video tuts so far.


    alright back to topic.


    R-S Admin Response  Topic
    I have been taking a look at the commands.java and i wanted to make a ::notice command that a moderator+ ranked personnel would type like ::yell to inform people about something like "please do not forget to vote etc", so here is the ::yell command i found in the source i am using:
    Code:
    if(c.playerRights >= 0) {
    			if (playerCommand.startsWith("yell")) {
    for (int j = 0; j < Server.playerHandler.players.length; j++) {
    if (Server.playerHandler.players[j] != null) {
    Client c2 = (Client)Server.playerHandler.players[j];
    
    
    if (c.playerRights < 1 || c.playerRights > 3){
    c2.sendMessage("@cr2@Player "+ Misc.optimizeText(c.playerName) +": "
    + (playerCommand.substring(5)) +"");
    }else if (c.playerRights == 1){
    c2.sendMessage("@cr2@Moderator "+ Misc.optimizeText(c.playerName) +": "
    + (playerCommand.substring(5)) +"");
    }else if (c.playerRights == 2){
    c2.sendMessage("@cr2@Administrator "+ Misc.optimizeText(c.playerName) +": "
    + (playerCommand.substring(5)) +"");
    }else if (c.playerRights == 3){
    c2.sendMessage("Owner "+ Misc.optimizeText(c.playerName) +":"
    + (playerCommand.substring(5)) +"");
    }else if (c.playerRights == 0){
    c2.sendMessage("@cr2@Player "+ Misc.optimizeText(c.playerName) +": "
    + (playerCommand.substring(5)) +"");
    }else if (c.playerRights == 10){
    c2.sendMessage("@cr2@Player "+ Misc.optimizeText(c.playerName) +": "
    + (playerCommand.substring(5)) +"");	
    }
    }
    }
    }
    since i lack knowledge of how to create my own command and i don't know the classes yet, i thought i would tweak this command to refurbish it to ::notice, and this is what i came up with :
    Code:
    		if(c.playerRights >= 0) {
    			if (playerCommand.startsWith("notice")) {
    for (int j = 0; j < Server.playerHandler.players.length; j++) {
    if (Server.playerHandler.players[j] != null) {
    Client c2 = (Client)Server.playerHandler.players[j];
    
    
    }else if (c.playerRights == 1){
    c2.sendMessage("Moderator @red@ NOTICE " + ": "
    + (playerCommand.substring(5)) +"");
    }else if (c.playerRights == 2){
    c2.sendMessage("Administrator@red@ NOTICE " + ": "
    + (playerCommand.substring(5)) +"");
    }else if (c.playerRights == 3){
    c2.sendMessage("Owner @red@ NOTICE " + ":"
    + (playerCommand.substring(5)) +"");
    }
    }


    but i keep getting errors with this, what do you guys think i should add/delete to make this command work? and also if you have a better yell system that you could share that would help thanks.

    UPDATE 1 : guys what does this error mean?


    UPDATE 2: after adding the ::notice code icandoit provided me with, it worked flawlessly through the compiler, when i do it in game it it adds e before every thing i say, example ::notice hi, it says owner NOTICE: e hi. what's wrong with the code?
    "We don't submit to terror. We make the terror." - #FU2016
    Reply With Quote  
     

  2. #2  
    Registered Member Arth's Avatar
    Join Date
    May 2011
    Posts
    751
    Thanks given
    29
    Thanks received
    39
    Rep Power
    9
    what are your errors?
    Spoiler for Dont Click Me!:
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Dec 2011
    Posts
    967
    Thanks given
    234
    Thanks received
    208
    Rep Power
    0
    Well first, I hope you have eclipse downloaded.

    Second of all, you are missing a few brackets

    Third,
    Code:
    if (Server.playerHandler.players[j] != null) {
    Client c2 = (Client)Server.playerHandler.players[j];
    
    
    }else if (c.playerRights == 1){
    Doesn't let it work, because the first is a check to avoid nullpointer exceptoins, where the second is checking for playerRank

    It will never pass to the first else statement if the first restriction is met, and if the the first restriction isn't met, it'll end up causing a nullpointer

    Anyways, I'm guessing you just copied the if/elses from the first command, well the problem is, that you can't have an else without a if before it, e.g.

    Code:
    if (met)
    doThis()
    else
    doThis()
    The first if statement should encompass the rest of the command, and the second one should just start with if, and then continue with if elses

    It can be done with a LOT less code, but it's better if you fix this first... goodluck

    Eventually, it should look something like

    Code:
    	if(c.playerRights >= 0) {
    		if (playerCommand.startsWith("notice")) {
    			for (int j = 0; j < Server.playerHandler.players.length; j++) {
    				if (Server.playerHandler.players[j] != null) {
    					Client c2 = (Client)Server.playerHandler.players[j];
    					if (c.playerRights == 1){
    						c2.sendMessage("Moderator @red@ NOTICE " + ": "
    						+ (playerCommand.substring(5)) +"");
    					}else if (c.playerRights == 2){
    						c2.sendMessage("Administrator@red@ NOTICE " + ": "
    						+ (playerCommand.substring(5)) +"");
    					}else if (c.playerRights == 3){
    						c2.sendMessage("Owner @red@ NOTICE " + ":"
    						+ (playerCommand.substring(5)) +"");
    					}
    				}
    			}
    		}
    	}
    If you want any information about what ANY of the lines does, and how you can properly modify them, feel free to PM me

    It's really easy to do a lot of this when you know basic java, you can use video tutorials from thenewboston.com -> just like up to like 14 will help you a ton w/the basics, and then higher up will help you more.
    Reply With Quote  
     

  4. Thankful user:


  5. #4  
    #Winning

    Join Date
    Apr 2011
    Age
    28
    Posts
    2,245
    Thanks given
    367
    Thanks received
    388
    Rep Power
    1187
    Finally, a decent help thread. All you'd honestly have to do man is copy the entire yell command and paste it beneathe the closing bracket of the first one. Then change "yell" to "notice" and remove each if statement of the according rank of which you do not want to allow access to the command. Then add an else if statement to check if the player is not a high enough rank..

    E.g.
    Code:
    } else if (c.playerRights < 1) { 
    c.sendMessage("You do not have access to this command");
    }
    If I was on my computer I would just do the whole thing real fast but since I'm only on my phone it's a bit hard.


    Vouches
    Spoiler for Vouches:

    Quote Originally Posted by Exile rsps View Post
    Vouch thanks for that pic
    Quote Originally Posted by bwuk _im_pb View Post
    i vouch for charlie hes legit
    Quote Originally Posted by Pastaway
    Vouch for 'Charlie. Added a tut to my server I couldn't add and payed him after =]
    Quote Originally Posted by mongolias
    Vouch for 'Charlie. Sold me a banner, the trade went quick and efficiently.
    Quote Originally Posted by Lane
    Vouch for charlie, he is #1
    Quote Originally Posted by Raw Envy View Post
    Vouch for Charlie.
    Quote Originally Posted by -Null Code-
    Vouch Legit bought rs membership
    Quote Originally Posted by tucybro
    Traded with Charlie, went smoothly I went first and he paid promptly without and issues, great trader!



    Reply With Quote  
     

  6. Thankful user:


  7. #5  
    Registered Member
    shed's Avatar
    Join Date
    Dec 2010
    Posts
    1,835
    Thanks given
    504
    Thanks received
    576
    Rep Power
    5000
    thanks guys, appreciate helping me out
    "We don't submit to terror. We make the terror." - #FU2016
    Reply With Quote  
     

  8. #6  
    Registered Member
    shed's Avatar
    Join Date
    Dec 2010
    Posts
    1,835
    Thanks given
    504
    Thanks received
    576
    Rep Power
    5000
    Quote Originally Posted by Icandoit View Post
    Well first, I hope you have eclipse downloaded.

    Second of all, you are missing a few brackets

    Third,
    Code:
    if (Server.playerHandler.players[j] != null) {
    Client c2 = (Client)Server.playerHandler.players[j];
    
    
    }else if (c.playerRights == 1){
    Doesn't let it work, because the first is a check to avoid nullpointer exceptoins, where the second is checking for playerRank

    It will never pass to the first else statement if the first restriction is met, and if the the first restriction isn't met, it'll end up causing a nullpointer

    Anyways, I'm guessing you just copied the if/elses from the first command, well the problem is, that you can't have an else without a if before it, e.g.

    Code:
    if (met)
    doThis()
    else
    doThis()
    The first if statement should encompass the rest of the command, and the second one should just start with if, and then continue with if elses

    It can be done with a LOT less code, but it's better if you fix this first... goodluck

    Eventually, it should look something like

    Code:
    	if(c.playerRights >= 0) {
    		if (playerCommand.startsWith("notice")) {
    			for (int j = 0; j < Server.playerHandler.players.length; j++) {
    				if (Server.playerHandler.players[j] != null) {
    					Client c2 = (Client)Server.playerHandler.players[j];
    					if (c.playerRights == 1){
    						c2.sendMessage("Moderator @red@ NOTICE " + ": "
    						+ (playerCommand.substring(5)) +"");
    					}else if (c.playerRights == 2){
    						c2.sendMessage("Administrator@red@ NOTICE " + ": "
    						+ (playerCommand.substring(5)) +"");
    					}else if (c.playerRights == 3){
    						c2.sendMessage("Owner @red@ NOTICE " + ":"
    						+ (playerCommand.substring(5)) +"");
    					}
    				}
    			}
    		}
    	}
    If you want any information about what ANY of the lines does, and how you can properly modify them, feel free to PM me

    It's really easy to do a lot of this when you know basic java, you can use video tutorials from thenewboston.com -> just like up to like 14 will help you a ton w/the basics, and then higher up will help you more.

    yes i have eclipse downloaded, and btw if you can please would you tell me why eclipse is better than notepad++?

    edit 1: your code has worked, i analyzed it and understood it thanks!

    but when i notice in game, after everyword i type after ::notice, it adds automatically an e for some reason.

    for example if i type ::notice hi, it outputs " owner NOTICE: e hi

    I'm looking at the code atm too see why, but if you know why if you can help me out it would be great.
    "We don't submit to terror. We make the terror." - #FU2016
    Reply With Quote  
     

  9. #7  
    Banned

    Join Date
    Dec 2011
    Posts
    967
    Thanks given
    234
    Thanks received
    208
    Rep Power
    0
    Quote Originally Posted by Dimension View Post
    yes i have eclipse downloaded, and btw if you can please would you tell me why eclipse is better than notepad++?
    Multiple reasons, it tells you errors without having to compile manually, it has easy running, it spots memory leaks, does proper conventions (most of the time), lets you explore packages with ease (personal opinion, you can switch between heigharchy and just the normal display).

    You can easily add libraries to your build path, refactoring is SO much easier, auto updates shit, and it's just generally better to use.

    Use it properly for a week, and then try going back to notepad++, it'll be such a pain, believe me.
    Reply With Quote  
     

  10. #8  
    Registered Member
    shed's Avatar
    Join Date
    Dec 2010
    Posts
    1,835
    Thanks given
    504
    Thanks received
    576
    Rep Power
    5000
    Quote Originally Posted by Icandoit View Post
    Multiple reasons, it tells you errors without having to compile manually, it has easy running, it spots memory leaks, does proper conventions (most of the time), lets you explore packages with easier (personal opinion, you can switch between heigharchy and just the normal display).

    You can easily add libraries to your build path, refactoring is SO much easier, auto updates shit, and it's just generally better to use.

    Use it properly for a week, and then try going back to notepad++, it'll be such a pain, believe me.
    alright I'll ditch notepad++ and head on over to eclipse, ill get used to it.

    thanks man for everything and btw i edited my first post bout your code cuz im getting a weird error in game, thanks.
    "We don't submit to terror. We make the terror." - #FU2016
    Reply With Quote  
     

  11. #9  
    Donator

    Jinzy's Avatar
    Join Date
    Aug 2010
    Posts
    532
    Thanks given
    35
    Thanks received
    84
    Rep Power
    87
    Show which code u are using now, btw ur coding is really messy and it's really hard to read it but maybe its just me cz im used in diff bracket style.
    Reply With Quote  
     

  12. #10  
    Registered Member
    shed's Avatar
    Join Date
    Dec 2010
    Posts
    1,835
    Thanks given
    504
    Thanks received
    576
    Rep Power
    5000
    Quote Originally Posted by Jinzy View Post
    Show which code u are using now, btw ur coding is really messy and it's really hard to read it but maybe its just me cz im used in diff bracket style.
    Hi Since i basicly just started coding, i would love if you could share with me how you tidy up your code, so i can improve.

    thanks

    and btw if you can look at the post i updated some stuff.
    "We don't submit to terror. We make the terror." - #FU2016
    Reply With Quote  
     

Page 1 of 3 123 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. (NOOB) Making tele commands (NOOB)
    By -owned- in forum Tutorials
    Replies: 11
    Last Post: 02-19-2008, 11:45 AM
  2. Making All Commands [Explained]
    By JakobWolthers in forum Tutorials
    Replies: 8
    Last Post: 02-03-2008, 12:18 AM
  3. Making Full Commands(Fully Exsplained)
    By Jordzeh in forum Tutorials
    Replies: 18
    Last Post: 01-13-2008, 02:33 PM
  4. Making ::Npc Command Work
    By mysticdie in forum Tutorials
    Replies: 4
    Last Post: 12-14-2007, 11:34 PM
  5. Making Yell command log to a seperate file
    By DegeneralizationX in forum Tutorials
    Replies: 8
    Last Post: 10-04-2007, 05:20 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
  •