Thread: [TuT]Adding Give Command[TuT]

Results 1 to 9 of 9
  1. #1 [TuT]Adding Give Command[TuT] 
    Registered Member
    G R A P E D's Avatar
    Join Date
    Feb 2009
    Age
    30
    Posts
    681
    Thanks given
    26
    Thanks received
    4
    Rep Power
    334
    This Tutorial is for (::give username itemid), that way when people use it they will have the item pop up in the given username above.

    Difficulty: 1/10

    Needed Knowledge: Copy & Paste

    Files Edited: Client Class

    Step 1.

    Add
    public boolean startsWithVowel(String input) {
    try {
    if (input.startsWith("a")
    || input.startsWith("e")
    || input.startsWith("i")
    || input.startsWith("o")
    || input.startsWith("u")) {
    return true;
    }
    return false;
    } catch (Exception e) {
    sM("Error with checking for vowels.");
    }
    }
    After
    public class client extends Player implements Runnable {
    Step 2.

    Add this anywhere in your commands area.
    if (s.startsWith("give ") && playerRights == 3) {
    String[] args = command.split(" ");
    if (args.length != 3) {
    sM("Invalid command typed - \"::give itemId playerName\".");
    return;
    }
    try {
    String oName = command.subString(args[2]).replaceAll("_", " ");
    int oID = PlayerHandler.getPlayerID(otherPName);

    if (oID != -1) {
    client p = (client) server.playerHandler.players[otherPIndex];
    String name = GetItemName(Integer.parseInt(args[1])).toLowerCase();

    p.addItem(Integer.parseInt(args[1]), 1);
    p.sM("You have been given a" + (itemName.startsWith(startsWithVowel(name) ? "n" : "") + " by " + playerName + ".");
    sM("You give a" + (itemName.startsWith(startsWithVowel(name) ? "n" : "") + " to " + p.playerName + ".");
    } else {
    sM("Player is not online.");
    }
    } catch (Exception e) {
    sM("Exception was caught while excecuting command \"" + playerCommand + "\".");
    }
    return;
    }
    Save & Close then Compile & Run.

    Credits:
    100% Me

    Reply With Quote  
     

  2. #2  
    Registered Member AcHoZeN™'s Avatar
    Join Date
    Oct 2008
    Posts
    684
    Thanks given
    0
    Thanks received
    7
    Rep Power
    47
    nice job
    Reply With Quote  
     

  3. #3  
    Registered Member Hunter K0 U All's Avatar
    Join Date
    Nov 2008
    Posts
    170
    Thanks given
    0
    Thanks received
    3
    Rep Power
    15
    Nvm.
    Last edited by Hunter K0 U All; 03-09-2009 at 05:44 AM. Reason: DIDNT WORK OH WELL.
    Reply With Quote  
     

  4. #4  
    Registered Member
    G R A P E D's Avatar
    Join Date
    Feb 2009
    Age
    30
    Posts
    681
    Thanks given
    26
    Thanks received
    4
    Rep Power
    334
    Thanks Syntax.

    Reply With Quote  
     

  5. #5  
    Special Pk
    Guest
    lol take 2 mins to create this lols but anyway gd gd
    Reply With Quote  
     

  6. #6  
    Community Veteran

    Dexter Morgan's Avatar
    Join Date
    Nov 2008
    Age
    28
    Posts
    4,419
    Thanks given
    1,184
    Thanks received
    757
    Rep Power
    3098
    Stop making how to make a command tuts,
    Reply With Quote  
     

  7. #7  
    Registered Member
    G R A P E D's Avatar
    Join Date
    Feb 2009
    Age
    30
    Posts
    681
    Thanks given
    26
    Thanks received
    4
    Rep Power
    334
    This command is rarely on Servers....Thats why I put it up.

    Reply With Quote  
     

  8. #8  
    Registered Member L E G A C Y's Avatar
    Join Date
    Dec 2008
    Posts
    88
    Thanks given
    0
    Thanks received
    0
    Rep Power
    8
    Code:
    lient.java:7209: ')' expected
    .sM("You have been given a" + (itemName.startsWith(startsWithVowe
     "") + " by " + playerName + ".");
    
                                     ^
    lient.java:7210: ')' expected
    M("You give a" + (itemName.startsWith(startsWithVowel(name) ? "n"
     + p.playerName + ".");
    Reply With Quote  
     

  9. #9  
    Member

    Join Date
    Sep 2007
    Posts
    614
    Thanks given
    0
    Thanks received
    1
    Rep Power
    0
    Erm, who the hell cares if its using correct grammar? Makes the code very messy.
    Not to mention there are so many simpler ways of doing this. Look up regex pattern splitting.
    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

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